Page 5 of 22

Bwired Googlemaps upload data webservice

Posted: Wed Mar 18, 2009 1:22 am
by Alexander
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by sooty</i>
<br />It looks like I found the answer, and yes it will.

I have used 19 kWh of power in less than 23 minutes [:(]

Paul..
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

LOL!! "Today Water 539 ltr". Damn is your waterpipe broken and is your house flooded ?

Bwired Googlemaps upload data webservice

Posted: Wed Mar 18, 2009 10:35 am
by Sooty
Lorenzo,

If you copy the code (In purple colour) below to a file and re-name it ???.vb, then this should work for the lamp status. NOTE: the code is not tested, but should work OK.

You will need to add your other information where indicated. if you still have problems, then let me know the device codes and device types you want to add, and I will create the whole script for you.

Note the GetStatus function. This will return a text value based on the status of the device.

To add lamp 2 for example, you can add another Const lamp2 = "A3" and in the entry section call the GetStatus like this: GetStatus(lamp2)

Hope that makes sense.

Paul..

<font color="purple">

Code: Select all

Imports System.IO
Imports System.Net
Imports System.Text

Sub Main(ByVal parms As Object)
    Const url = "http://www.bwired.nl/Bwiredservice/receive.asp"
    Const screenname = "YourScreenName" '<---REPLACE THIS WITH YOUR INFO
    Const name = "YourName" '<---REPLACE THIS WITH YOUR INFO
    Const passwd = "YourPassword" '<---REPLACE THIS WITH YOUR INFO
    Const city = "YourCity" '<---REPLACE THIS WITH YOUR INFO
    Const gpslat = "YourLat" '<---REPLACE THIS WITH YOUR INFO
    Const gpslong = "YourLon" '<---REPLACE THIS WITH YOUR INFO
    Const title = "YourTitle" '<---REPLACE THIS WITH YOUR INFO
    Const temp = "??" '<---REPLACE ?? WITH YOUR HOMESEER TEMPERATURE DEVICE CODE
    Const humid = "??" '<---REPLACE ?? WITH YOUR HOMESEER HUMIDITY DEVICE CODE
    Const baro = "??" '<---REPLACE ?? WITH YOUR HOMESEER BAROMETER DEVICE CODE
    Const lamp1 = "A2" '<---REPLACE  ?? WITH YOUR HOMESEER LAMP 1 DEVICE CODE
    Dim myXML
    Dim xmlhttp

    myXML = hs.CreateStringClass
    myXML.Add("<?xml version=""1.0"" encoding=""UTF-8"" ?>")
    myXML.Add("<BWired>")
    myXML.Add("<Init>")
    myXML.Add("<DateTime>" & Now() & "</DateTime>")
    myXML.Add("<UserName>" & name & "</UserName>")
    myXML.Add("<Password>" & passwd & "</Password>")
    myXML.Add("<ScreenName>" & screenname & "</ScreenName>")
    myXML.Add("<Gpslat>" & gpslat & "</Gpslat>")
    myXML.Add("<Gpslong>" & gpslong & "</Gpslong>")
    myXML.Add("<City>" & city & "</City>")
    myXML.Add("<Website />")
    myXML.Add("<WebCamPicUrl />")
    myXML.Add("<Title>" & title & "</Title>")
    myXML.Add("</Init>")

    myXML.Add("<Entry>")
    myXML.Add("<Name>Outside Temperature</Name>")
    myXML.Add("<ID>1</ID>")
    myXML.Add("<Units>C</Units>")
    myXML.Add("<Value>" & CStr(hs.DeviceValue(temp) / 10).Replace(",", ".") & "</Value>")
    myXML.Add("</Entry>")

    myXML.Add("<Entry>")
    myXML.Add("<Name>Outside Humidity</Name>")
    myXML.Add("<ID>2</ID>")
    myXML.Add("<Units>%</Units>")
    myXML.Add("<Value>" & hs.DeviceValue(humid) & "</Value>")
    myXML.Add("</Entry>")

    myXML.Add("<Entry>")
    myXML.Add("<Name>Barometer</Name>")
    myXML.Add("<ID>3</ID>")
    myXML.Add("<Units>hPa</Units>")
    myXML.Add("<Value>" & CInt(hs.DeviceValue(baro) / 100) & "</Value>")
    myXML.Add("</Entry>")

    myXML.Add("<Entry>")
    myXML.Add("<Name>Lamp 1</Name>")
    myXML.Add("<ID>4</ID>")
    myXML.Add("<Units></Units>")
    myXML.Add("<Value>" & GetStatus(lamp1) & "</Value>")
    myXML.Add("</Entry>")


    myXML.Add("</BWired>")

    xmlhttp = WebRequest.Create(url)
    xmlhttp.Method = "POST"
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(myXML.Value)
    xmlhttp.ContentType = "text/xml"
    xmlhttp.ContentLength = byteArray.Length
    Dim dataStream As Stream = xmlhttp.GetRequestStream()
    dataStream.Write(byteArray, 0, byteArray.Length)
    dataStream.Close()
    Dim response As WebResponse = xmlhttp.GetResponse()
    response.Close()

    myXML.Reset()

End Sub

Public Function GetStatus(ByVal devCode As String) As String
    Dim strInpStatus As String
    Dim strOutStatus As String

    strInpStatus = hs.DeviceStatus(devCode)

    Select Case strInpStatus
        Case "2"
            strOutStatus = "ON"
        Case "3"
            strOutStatus = "OFF"
        Case "4"
            strOutStatus = "DIM"
        Case Else
            strOutStatus = "UNKNOWN"
    End Select

    Return strOutStatus.ToString

End Function
</font id="purple">

Bwired Googlemaps upload data webservice

Posted: Wed Mar 18, 2009 10:49 am
by Sooty
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by mgizmo</i>
<br /><blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by sooty</i>
<br />It looks like I found the answer, and yes it will.

I have used 19 kWh of power in less than 23 minutes [:(]

Paul..
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

LOL!! "Today Water 539 ltr". Damn is your waterpipe broken and is your house flooded ?
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

I will let Pieter get all the grey hairs working out how he will sort out the time difference problems [:D]

Not so much of a problem with the small time difference between UK & NL local time, but it could be a problem with larger differences from other countries.

Paul..

Bwired Googlemaps upload data webservice

Posted: Wed Mar 18, 2009 11:39 am
by Alexander
Also, He needs to look into the decimal point i guess?

Bwired Googlemaps upload data webservice

Posted: Wed Mar 18, 2009 12:53 pm
by Rene
Only decimal points are supported at this time. For this reason I convert any commas to dots in my Homeseer script.

Rene.

Bwired Googlemaps upload data webservice

Posted: Wed Mar 18, 2009 1:04 pm
by drmacchi
@Sooty , thank you! I will try later. I'll let you know.

Bwired Googlemaps upload data webservice

Posted: Wed Mar 18, 2009 7:35 pm
by drmacchi
@Sooty , i did that and i don't have any errors in log file. Let's hope. Now i'm waiting that my xml data are accepted and published on asp page. Pieter are you there? :) :) Best regards boys.

Bwired Googlemaps upload data webservice

Posted: Wed Mar 18, 2009 11:47 pm
by Bwired
Nothing coming in, when are you sending?
I should see some XML's coming in, but nothing!

Bwired Googlemaps upload data webservice

Posted: Thu Mar 19, 2009 4:05 pm
by drmacchi
Pieter i did a schedule , every 60 min. here's log of HS.

19/03/2009 12.22.05 Info Event Trigger "xml2bwired"
19/03/2009 12.22.05 Info Running script in background: xml2bwired.vb
19/03/2009 13.22.05 Info Event Trigger "xml2bwired"
19/03/2009 13.22.05 Info Running script in background: xml2bwired.vb
and so on...

this is my script
Imports System.IO
Imports System.Net
Imports System.Text

Sub Main(parms As Object)
const url = "http://www.bwired.nl/Bwiredservice/receive.asp"
const screenname="<Domotica_IT>"
const name="<xxxxx>"
const passwd="<xxxxxx>"
const city="<Dumenza>"
const gpslat="46.018781"
const gpslong="<8.787689>"
const title="<The Wolf's land>"
Const temp = "??"
Const humid = "??"
Const baro = "??"
Const lamp1 = "A2"
Dim myXML
Dim xmlhttp

myXML = hs.CreateStringClass
myXML.Add("<?xml version=""1.0"" encoding=""UTF-8"" ?>")
myXML.Add("<BWired>")
myXML.Add("<Init>")
myXML.Add("<DateTime>" & Now() & "</DateTime>")
myXML.Add("<UserName>" & name & "</UserName>")
myXML.Add("<Password>" & passwd & "</Password>")
myXML.Add("<ScreenName>" & screenname & "</ScreenName>")
myXML.Add("<Gpslat>" & gpslat & "</Gpslat>")
myXML.Add("<Gpslong>" & gpslong & "</Gpslong>")
myXML.Add("<City>" & city & "</City>")
myXML.Add("<Website />")
myXML.Add("<WebCamPicUrl />")
myXML.Add("<Title>" & title & "</Title>")
myXML.Add("</Init>")

myXML.Add("<Entry>")
myXML.Add("<Name>Outside Temperature</Name>")
myXML.Add("<ID>1</ID>")
myXML.Add("<Units>C</Units>")
myXML.Add("<Value>" & CStr(hs.DeviceValue(temp) / 10).Replace(",", ".") & "</Value>")
myXML.Add("</Entry>")

myXML.Add("<Entry>")
myXML.Add("<Name>Outside Humidity</Name>")
myXML.Add("<ID>2</ID>")
myXML.Add("<Units>%</Units>")
myXML.Add("<Value>" & hs.DeviceValue(humid) & "</Value>")
myXML.Add("</Entry>")

myXML.Add("<Entry>")
myXML.Add("<Name>Barometer</Name>")
myXML.Add("<ID>3</ID>")
myXML.Add("<Units>hPa</Units>")
myXML.Add("<Value>" & CInt(hs.DeviceValue(baro) / 100) & "</Value>")
myXML.Add("</Entry>")

myXML.Add("<Entry>")
myXML.Add("<Name>Gate's lamp</Name>")
myXML.Add("<ID>4</ID>")
myXML.Add("<Units></Units>")
myXML.Add("<Value>" & GetStatus(lamp1) & "</Value>")
myXML.Add("</Entry>")


myXML.Add("</BWired>")

xmlhttp = WebRequest.Create(url)
xmlhttp.Method = "POST"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(myXML.Value)
xmlhttp.ContentType = "text/xml"
xmlhttp.ContentLength = byteArray.Length
Dim dataStream As Stream = xmlhttp.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = xmlhttp.GetResponse()
response.Close()

myXML.Reset()

End Sub

Public Function GetStatus(ByVal devCode As String) As String
Dim strInpStatus As String
Dim strOutStatus As String

strInpStatus = hs.DeviceStatus(devCode)

Select Case strInpStatus
Case "2"
strOutStatus = "ON"
Case "3"
strOutStatus = "OFF"
Case "4"
strOutStatus = "DIM"
Case Else
strOutStatus = "UNKNOWN"
End Select

Return strOutStatus.ToString

End Function

Bwired Googlemaps upload data webservice

Posted: Thu Mar 19, 2009 4:51 pm
by Digit
Lorenzo,
I would be surprised if this will run. Take the time to review the script once more!
An example: CInt(hs.DeviceValue(baro) / 100); what you're actually doing is CInt(hs.DeviceValue("??") / 100).
So, you have a device "??". I don't think so :-)
Somewhere the script will throw an exception and stop executing there, so it's not reaching the end where the XML is actually sent.

Bwired Googlemaps upload data webservice

Posted: Thu Mar 19, 2009 4:52 pm
by Rene
@drmacchi: Add the following line to your script, just between the response.Close() and myXML.Reset() lines, to check whether the XML is created correctly:

hs.SendEmail(<your email address>,<your email address>,"test",myXML.Value)

Replace <your email address> with your email adres between "".

Rene.

Bwired Googlemaps upload data webservice

Posted: Thu Mar 19, 2009 7:09 pm
by drmacchi
I did insert code for mail test. This is the mail that i receive:

<?xml version="1.0" encoding="UTF-8" ?><BWired><Init><DateTime>19/03/2009 18.08.22</DateTime><UserName><drmacchi></UserName><Password><43694369></Password><ScreenName><Domotica_IT></ScreenName><Gpslat>46.018781</Gpslat><Gpslong><8.787689></Gpslong><City><Dumenza></City><Website /><WebCamPicUrl /><Title><The Wolf's land></Title></Init><Entry><Name>Outside Temperature</Name><ID>1</ID><Units>C</Units><Value>0</Value></Entry><Entry><Name>Outside Humidity</Name><ID>2</ID><Units>%</Units><Value>0</Value></Entry><Entry><Name>Barometer</Name><ID>3</ID><Units>hPa</Units><Value>0</Value></Entry><Entry><Name>Gate's lamp</Name><ID>4</ID><Units></Units><Value>OFF</Value></Entry></BWired>

Bwired Googlemaps upload data webservice

Posted: Thu Mar 19, 2009 7:11 pm
by drmacchi
Ops, user and password will be changed immediatly!

Bwired Googlemaps upload data webservice

Posted: Thu Mar 19, 2009 7:50 pm
by Digit
Remove the "<" and ">" from your values.
So for instance <drmacchi> should be drmacchi,
<Domotica_IT> should be Domotica_IT, etc.

Bwired Googlemaps upload data webservice

Posted: Thu Mar 19, 2009 8:23 pm
by Fantic
you mean like this?
<ScreenName>Domotica_IT</ScreenName>

Regards, Maarten.
Never let a computer know you're in a hurry.