Imports System.Convert Imports System.IO Imports System.Net Public Sub Main(ByVal Parms As Object) 'Derived from https://forums.homeseer.com/showthread.php?t=180358&styleid=1 'developed with tenware Tenscripting 'creating the IOT device and create/renewing the SAS token not implemented. Use Azure IoT device explorer to create. 'Configure these variables to your environment Dim iothubname As String = "your-iot-hub-name" Dim deviceID As String = "your-device-id" Dim apiversion As String = "2016-02-03" Dim sastoken As String = "SharedAccessSignature sr=hubname.azure-devices.net%2Fdevices%2Fdevicename&sig=xxxxxxx&se=1234" Dim debug As Boolean = True 'Set to true for some loggging '------------- 'Pass the category as the first parameter as category=xxx|device name1|device name2|etc etc 'example: category=temperature|living room|outside|inside|garage 'pass the homeseer device names in the parameters separted by a pipe | 'The category is free text name that is that allows you to group your data together using queries in Azure.. Dim ParmArray() As String Dim category() As String ParmArray = Parms.ToString.Split(ToChar("|")) 'Split passed parameters by looking for pipe symbol category = ParmArray(0).Split(New Char() {"="c}) 'extract out the text after the keyword category= for the first parameter sent in Dim strURL As String = String.Format("https://{0}.azure-devices.net/devices/{1}/messages/events/?api-version={2}", iothubname, deviceID, apiversion) Dim myWebReq As HttpWebRequest Dim myWebResp As HttpWebResponse Dim encoding As New System.Text.UTF8Encoding Dim sr As StreamReader Dim thedate As String = DateTime.Now.ToString("s") 'Generate an ISO 8601 (American) Date stamp. For Each item As String In ParmArray.Skip(1) 'Skip the first item in the passed parameters list as that was the catergory. Dim devicename As String = item Dim deviceref As Integer = hs.GetDeviceRefByName(item) Dim value As String = CType(hs.DeviceValue(deviceref), String) Dim json As String = "{""datestamp"":""" + thedate + """,""category"":""" + category(1) + """,""devicename"":""" + devicename + """,""value"":""" + value + """}" Try Dim data As Byte() = encoding.GetBytes(json) myWebReq = DirectCast(WebRequest.Create(strURL), HttpWebRequest) myWebReq.ContentType = "application/json; charset=utf-8" myWebReq.ContentLength = data.Length myWebReq.Headers.Add("Authorization", sastoken) myWebReq.Method = "POST" Dim myStream As Stream = myWebReq.GetRequestStream() If debug Then hs.WriteLog("Sending: ", json) If data.Length > 0 Then myStream.Write(data, 0, data.Length) myStream.Close() End If myWebResp = DirectCast(myWebReq.GetResponse(), HttpWebResponse) sr = New StreamReader(myWebResp.GetResponseStream()) Dim responseText As String = sr.ReadToEnd() If debug Then hs.WriteLog("Response: ", responseText) Catch ex As Exception : hs.WriteLog("Error: ", ex.Message.ToString) End Try Next End Sub