The files contained in this repository can be downloaded to your computer using a svn client.
On Linux you simply type the command displayed below.

This URL has Read-Only access.

Statistics
| Revision:

root / trunk / DomotiGaServer / AIBO.module @ 239

History | View | Annotate | Download (2.5 kB)

1
' Gambas module file
2
3
' Description:
4
' AIBO.module
5
' Support for Sony AIBO ERS-7 monitor if he/she is awake or not, and give him commands via e-mail.
6
7
' Development Status:
8
' Detecting AIBO and setting device status accordingly works, giving it commands via e-mail needs to be tested.
9
10
' Links:
11
' http://www.aiai.ed.ac.uk/project/aibo/aibo-mail.html
12
' http://littlegreengecko.org/aibomailref_mind3.htm
13
14
' DomotiGa - an open source home automation program.
15
' Copyright(C) 2008 Ron Klinkien
16
17
' Read file called COPYING for license details.
18
19
PUBLIC tAIBO AS NEW Timer
20
21
PUBLIC SUB CheckAIBO()
22
23
  DIM rResult AS Result
24
25
  rResult = Main.hDB.Exec("SELECT * FROM devices WHERE enabled is TRUE")
26
27
  IF rResult.Available THEN
28
    IF rResult.Count >= 1 THEN
29
      FOR EACH rResult
30
        IF InStr(Devices.FindTypeForDevice(rResult!id), "AIBO")
31
          IF Main.bAIBODebug THEN Main.WriteDebugLog("[AIBO] checking AIBO named '" & rResult!name & "' with address http://" & rResult!address)
32
          Ping(rResult!id, rResult!address)
33
        END IF
34
      NEXT
35
    ELSE
36
      Main.WriteLog("AIBO: no AIBO(s) found in device table!")
37
    END IF
38
  END IF
39
40
END
41
42
PUBLIC SUB Run()
43
44
  ' start poll timer for AIBO
45
  tAIBO = NEW Timer AS "tAIBO"
46
  tAIBO.Delay = Main.iAIBOPollTime * 1000 ' multiply for seconds
47
  tAIBO.Start
48
49
END
50
51
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52
' try to get url to see if AIBO is awake or not
53
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54
PRIVATE FUNCTION Ping(iId AS Integer, sAddress AS String) AS Boolean
55
56
  DIM hAIBO AS NEW HttpClient
57
  DIM sStatus, sURL AS String
58
59
  sURL = "http://" & sAddress
60
61
  hAIBO = NEW HttpClient AS "AIBOPing"
62
  hAIBO.URL = sURL
63
  hAIBO.Async = FALSE
64
  hAIBO.TimeOut = 1
65
  hAIBO.Get
66
67
  IF hAIBO.Status < 0 THEN
68
    sStatus = "Sleeping"
69
    ' not reachable, he's asleep
70
  ELSE
71
    sStatus = "Awake"
72
    ' success, he/she is awake
73
  END IF
74
75
  ' find and update device
76
  IF Main.bAIBODebug THEN Main.WriteDebugLog("[AIBO] dog with id " & iId & " is " & sStatus)
77
  Devices.ValueUpdate(iId, sStatus, "", "", "")
78
79
CATCH ' some errors
80
  Main.WriteLog("AIBO Error: " & ERROR.Text & "")
81
  RETURN FALSE
82
83
END
84
85
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86
' generate e-mail with requested command to sent to AIBO
87
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88
PUBLIC FUNCTION Command(sUser AS String, sCommand AS String) AS Boolean
89
90
  ' todo, need to implement user->email routine
91
  ' Mail.SendMail("AIBO MAIL", sAddress, sCommand)
92
93
END
94
95
PRIVATE SUB tAIBO_Timer()
96
97
  CheckAIBO()
98
99
END