Originally posted by vince954
View Post
Code:
Imports System.Collections.Generic Sub Main(ByVal Parms As Object) Dim USERNAME as string= "meteobridge" Dim PASSWORD as string= "meteobridge" Dim URL As String = "192.168.1.48/cgi-bin/livedataxml.cgi" URL = USERNAME & ":" & PASSWORD & "@" & URL Dim Query As String = hs.GETURL(URL,"",False,80) Dim xmlData As New XmlDocument() Dim xmlnodelist As XmlNodeList Dim xmlnode As XmlNode Dim MeteoData As New Dictionary(Of String, Items) xmlData.LoadXml(Query) ' Update the Ref #s for the devices you have. The name isn't used and can stay the same xmlnode = xmlData.SelectSingleNode("logger/TH") MeteoData.Add("OutsideTemperature", New Items With {.Ref=1976, .Value=CtoF(xmlnode.Attributes.GetNamedItem("temp").Value)}) MeteoData.Add("OutsideHumidity", New Items With {.Ref=100, .Value=xmlnode.Attributes.GetNamedItem("hum").Value}) MeteoData.Add("OutsideDewpoint", New Items With {.Ref=104, .Value=CtoF(xmlnode.Attributes.GetNamedItem("dew").Value)}) xmlnode = xmlData.SelectSingleNode("logger/THB") MeteoData.Add("InsideTemperature", New Items With {.Ref=1975, .Value=CtoF(xmlnode.Attributes.GetNamedItem("temp").Value)}) MeteoData.Add("InsideHumidity", New Items With {.Ref=839, .Value=xmlnode.Attributes.GetNamedItem("hum").Value}) MeteoData.Add("InsideDewpoint", New Items With {.Ref=104, .Value=CtoF(xmlnode.Attributes.GetNamedItem("dew").Value)}) MeteoData.Add("BarPress", New Items With {.Ref=105, .Value=MBtoHG(xmlnode.Attributes.GetNamedItem("press").Value )}) MeteoData.Add("SeaPress", New Items With {.Ref=0, .Value=MBtoHG(xmlnode.Attributes.GetNamedItem("seapress").Va lue)}) xmlnode = xmlData.SelectSingleNode("logger/WIND") MeteoData.Add("WindSpeed", New Items With {.Ref = 102, .Value = MStoMPH(xmlnode.Attributes.GetNamedItem("wind").Value)}) MeteoData.Add("WindGust", New Items With {.Ref = 106, .Value = MStoMPH(xmlnode.Attributes.GetNamedItem("gust").Value)}) MeteoData.Add("WindChill", New Items With {.Ref = 2253, .Value = CtoF(xmlnode.Attributes.GetNamedItem("chill").Value)}) MeteoData.Add("WindDir", New Items With {.Ref = 137, .Value = xmlnode.Attributes.GetNamedItem("dir").Value}) xmlnode = xmlData.SelectSingleNode("logger/RAIN") MeteoData.Add("RainRate", New Items With {.Ref=0, .Value=MMtoIN(xmlnode.Attributes.GetNamedItem("rate").Value) }) MeteoData.Add("RainTotal", New Items With {.Ref = 798, .Value = MMtoIN(xmlnode.Attributes.GetNamedItem("total").Value)}) MeteoData.Add("RainDelta", New Items With {.Ref = 107, .Value = MMtoIN(xmlnode.Attributes.GetNamedItem("delta").Value)}) ' Update HS3 virtual devices updateHS3(MeteoData) End Sub Sub updateHS3(ByVal data As Object) Dim val As Double For Each item As KeyValuePair(Of String, Items) In data if item.Value.Ref > 0 val = Convert.ToDouble(item.Value.Value) 'hs.WriteLog("MeteoPoll","Key=" & item.Key & ", Ref=" & item.Value.Ref & ", Value=" & val) hs.SetDeviceValueByRef(item.Value.Ref,val, true) End If Next End Sub ' Function CtoF (ByVal C As Decimal) As Decimal Return Format(((9*C)/5 ) + 32,"0.00") End Function Function MBtoHG(ByVal MB As Decimal) As Decimal Return Format(MB*0.02953,"0.00") End Function Function MMtoIN(ByVal MM As Decimal) As Decimal Return Format(MM/25.4,"0.00") End Function Function MStoMPH(ByVal MS As Decimal) As Decimal Return Format(MS/0.44704,"0.00") End Function Public Class Items Public Property Ref As Integer Public Property Value As Double Public Sub New() End Sub End Class
Comment