Last active
September 15, 2016 17:38
-
-
Save LosantGists/510091594cb9e988513c1ec8f3b77605 to your computer and use it in GitHub Desktop.
GETTING STARTED WITH MC-THINGS AND LOSANT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Class TempLogger | |
| // Device ID of Peripheral in Losant | |
| Const LosantDeivceId As String = "57d85157f3894e01006c6afa" | |
| // MQTT topic in Losant | |
| Const LosantTopic As String = "losant/" + LosantDeivceId + "/state" | |
| Shared Event CheckTemp() RaiseEvent Every 30 Seconds | |
| Dim temp As Float = TempSensor.GetTemp() // Get Temp from sensor | |
| Dim tempstring As String = temp.ToString() | |
| // Create temp JSON object - { "temperature" : "23.06" } | |
| Dim tempJson As Json = New Json | |
| tempJson.Add("temperature", tempstring) | |
| // Create Losant preferred JSON object - { "data" : {"temperature" : "23.06"}} | |
| Dim losantPayload As Json = New Json | |
| losantPayload.Add("data", tempJson) | |
| // Publish to Losant MQTT | |
| Lplan.Publish(LosantTopic, losantPayload.ToListOfByte) | |
| End Event | |
| Shared Event CheckVoltage() RaiseEvent Every 30 Seconds | |
| Dim BattVolt As Integer = Device.BatteryVoltage// Get battery voltage | |
| // Create temp JSON object - { "batteryVoltage" : "2816" } | |
| Dim batteryJson As Json = New Json | |
| batteryJson.Add("batteryVoltage", BattVolt) | |
| // Create Losant preferred JSON object - { "data" : {"batteryVoltage" : "2816"}} | |
| Dim losantPayload As Json = New Json | |
| losantPayload.Add("data", batteryJson) | |
| // Publish to Losant MQTT | |
| Lplan.Publish(LosantTopic, losantPayload.ToListOfByte) | |
| End Event | |
| End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment