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 / Bwired.module @ 251

History | View | Annotate | Download (3.7 kB)

1
' Gambas module file
2
3
' Description:
4
' Bwired.module
5
' Support for Bwired related functions.
6
7
' Development Status:
8
' Just build, so possible bugs around.
9
10
' Links:
11
' http://www.bwired.nl/domoticaworld.asp
12
13
' DomotiGa - an open source home automation program.
14
' Copyright(C) 2009 Ron Klinkien
15
16
' Read file called COPYING for license details.
17
18
PUBLIC hPost AS NEW HttpClient AS "hPost"
19
PUBLIC tBwired AS NEW Timer
20
21
PUBLIC SUB Run()
22
23
  ' start poll timer for Bwired
24
  tBwired = NEW Timer AS "tBwired"
25
  tBwired.Delay = Main.iBwiredMapPushTime * 1000 * 60 ' multiply for minutes
26
  tBwired.Start
27
28
END
29
30
PUBLIC SUB tBwired_Timer()
31
32
  UploadBwiredData()
33
34
END
35
36
PRIVATE SUB CreateBwiredData() AS String
37
38
  DIM xXml AS XmlWriter
39
  DIM sXml, sValue, sLabel AS String
40
  DIM rResult AS Result
41
  DIM iId AS Integer
42
43
  xXml = NEW XmlWriter
44
  xXml.Open("", TRUE, "UTF-8")
45
  xXml.StartElement("BWired")
46
    xXml.StartElement("Init")
47
      xXml.Element("DateTime", Now())
48
      xXml.Element("UserName", Main.sBwiredMapUser)
49
      xXml.Element("Password", Main.sBwiredMapPassword)
50
      xXml.Element("ScreenName", Main.sBwiredMapScreenName)
51
      xXml.Element("Gpslat", Main.sBwiredMapGpsLat)
52
      xXml.Element("Gpslong", Main.sBwiredMapGpsLong)
53
      xXml.Element("City", Main.sBwiredMapCity)
54
      xXml.Element("Website", Main.sBwiredMapWebsite)
55
      xXml.Element("WebCamPicUrl", Main.sBwiredMapWebsitePicUrl)
56
      xXml.Element("Title", Main.sBwiredMapTitle)
57
    xXml.EndElement()
58
    rResult = Main.hDB.Exec("SELECT * FROM devices_bwired")
59
60
    IF NOT rResult THEN
61
      Main.WriteLog(("Error: table 'devices_bwired' not found!"))
62
      RETURN
63
    END IF
64
65
    IF rResult.Count THEN
66
      FOR EACH rResult
67
        xXml.StartElement("Entry")
68
        xXml.Element("Name", rResult!description)
69
        xXml.Element("ID", iId)
70
        xXml.Element("Units", rResult!devicelabel)
71
        SELECT rResult!value
72
          CASE "Value"
73
            sValue = Devices.GetCurrentValueForDevice(rResult!deviceid)
74
          CASE "Value2"
75
            sValue = Devices.GetCurrentValue2ForDevice(rResult!deviceid)
76
          CASE "Value3"
77
            sValue = Devices.GetCurrentValue3ForDevice(rResult!deviceid)
78
          CASE "Value4"
79
            sValue = Devices.GetCurrentValue3ForDevice(rResult!deviceid)
80
        END SELECT
81
        xXml.Element("Value", sValue)
82
        xXml.EndElement()
83
        INC iId
84
      NEXT
85
    END IF
86
87
  xXml.EndElement()
88
  RETURN xXml.EndDocument()
89
90
END
91
92
PUBLIC SUB UploadBwiredData()
93
94
  DIM sContent AS String
95
96
  IF hPost.Status > 0 THEN
97
    Main.WriteLog(("I'm already uploading XML data to Bwired, skipping."))
98
    RETURN
99
  END IF
100
101
  sContent = CreateBwiredData()
102
103
  hPost.URL = "http://www.bwired.nl/Bwiredservice/receive.asp"
104
  hPost.TimeOut = 10
105
  hPost.Async = TRUE
106
  hPost.Post("text/xml", sContent)
107
108
  IF Main.bBwiredMapDebug THEN Main.WriteDebugLog("[Bwired] " & sContent)
109
110
END
111
112
PUBLIC SUB hPost_Error()
113
114
  Main.WriteDebugLog(("[Bwired] XML data post error."))
115
116
END
117
118
PUBLIC SUB hPost_Finished()
119
120
  DIM iCount AS Integer
121
122
  SELECT hPost.Code
123
    CASE 0
124
      IF InStr(hPost.Headers[0], "HTTP/1.1 200") THEN
125
        Main.WriteLog(("Uploaded XML data to Bwired."))
126
      ELSE
127
        Main.WriteLog(("Unknown error occured while uploading XML data to Bwired!"))
128
      END IF
129
    CASE 401
130
      Main.WriteLog(("Error authenticating while uploading XML data to Bwired!"))
131
    CASE 404
132
      Main.WriteLog(("Error page not found while uploading XML data to Bwired!"))
133
    CASE ELSE
134
      Main.WriteLog(("Unknown error occured while uploading XML data to Bwired!"))
135
  END SELECT
136
137
  IF Main.bBwiredMapDebug THEN
138
    FOR iCount = 0 TO hPost.Headers.Count - 1
139
      Main.WriteDebugLog("[Bwired] " & Left(hPost.Headers[iCount], Len(hPost.Headers[iCount]) - 1))
140
    NEXT
141
  END IF
142
143
END