Author Topic: Using mcThings and Losant to visualize data!  (Read 108 times)

mc-T2

  • Administrator
  • Full Member
  • *****
  • Posts: 181
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Using mcThings and Losant to visualize data!
« on: January 16, 2017, 03:17:16 pm »
Hello everyone!
We just posted a new video that showcases how to display information from your mcThings platform into the Losant IoT application! Using Losant, you can create some fantastic dashboards to visualize the data from your mcModules (such as number gauges and dials, multiple types of graphs, etc) and also the ability to setup workflows to be alerted on critical information. You can use your mcModules as well as SIGFOX devices (Use the mcDemo205 and Losant to plot locations onto a map on your dashboard!)
Losant is perfect for individuals, businesses and IoT integrator's who want to capture data for viewing, analysis, etc. Check them out here: www.losant.com

There is a great walk-through on how to setup your modules and your Losant account and bring data into the application. We recommend checking out this walk-through to help you out.

mcModule & Losant walkthrough:  https://www.losant.com/blog/getting-started-with-mc-things-and-losant

SIGFOX (mcDemo205) and Losant walkthrough: https://www.losant.com/blog/collect-monitor-visualize-sigfox-data

In the video, we also walk-through setting up modules and pushing the information into a Losant Dashboard! Below the video, please see examples of the codes we used for some of the widgets that you see on the live dashboard.

Here is a link to the live dashboard!! https://goo.gl/xLRzPB


https://youtu.be/PVyjyIwcuUc



Code for temperature and battery voltage:

Code: [Select]
Class LosantTempBattery
    Shared Event Boot()
        Lplan.SetBeaconTime(120)
    End Event
   
    // Device ID of Peripheral in Losant
    Const LosantDeviceId As String = "YourLosantDeviceIDHERE"
    // MQTT topic in Losant
    Const LosantTopic As String = "losant/" + LosantDeviceId + "/state"
   
    Shared Event CheckTemp() RaiseEvent Every 59 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 5 Minutes
        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


Code for Door Open/Closed status and door count

Code: [Select]
Class LosantXTRA
   
   
    // Device ID of Peripheral in Losant
    Const LosantDeivceId As String = "YourLosantDeviceIDHERE"
    // MQTT topic in Losant
    Const LosantTopic As String = "losant/" + LosantDeivceId + "/state"
   
    Shared _doorState As String
    Shared _doorcount As Integer
   
    Shared Event Boot()
        _doorState = "Open"
        _doorcount = 0
    End Event
   
    Shared Event ReedSwitchChanged()
        'debounce interrupt
        Thread.Sleep(100000)
        Thread.ClearHardwareEvent()
        LedRed = True
        If ReedSwitch = True Then
            _doorState = "Open"   
            _doorcount = _doorcount + 1
        Else
            _doorState = "Closed"
        End If
        sendMQTTData()
        LedRed = False
    End Event
   
    Shared Event CheckSensors() RaiseEvent Every 60 Seconds
        sendMQTTData()
    End Event
   
    Private Sub sendMQTTData()
        Dim tempTMP102string As String = TempSensor.GetTemp().ToString()
        Dim battShort As Short = Device.BatteryVoltage()
        Dim battFloat As Float = battShort / 1000
        Dim battString As String = battFloat.ToString()
       
       
        // Create data JSON object
        Dim dataJson As Json = New Json
        dataJson.Add("battery", battString)
        dataJson.Add("temperature", tempTMP102string)
        dataJson.Add("doorState", _doorState)
        dataJson.Add("doorCount", _doorcount)
       
       
        // Create Losant preferred JSON object
        Dim losantPayload As Json = New Json
        losantPayload.Add("data", dataJson)
       
        // Publish to Losant MQTT
        Lplan.Publish(LosantTopic, losantPayload.ToListOfByte)
       
    End Sub
   
End Class

Code for Moisture Sensor into Losant -Note - This code is not optimized (Events could be grouped together into one payload as is done in the code above for the door/open closed state and count)

Code: [Select]
Define PinMode Pin0 As AnalogInput Alias MoistureLevel
Define PinMode Pin6 As DigitalOutput Alias enableMoistureLevel

Class LosantMoisture
   
   
    Shared Event Boot()
        Lplan.SetBeaconTime(175)
    End Event
   
    // Device ID of Peripheral in Losant
    Const LosantDeivceId As String = "58730cd41b29cb0100c8b870"
    // MQTT topic in Losant
    Const LosantTopic As String = "losant/" + LosantDeivceId + "/state"
   
    Shared Event measureMoisture() RaiseEvent Every 60 Seconds
       
        enableMoistureLevel = True 'turn on voltage divider
        Thread.Sleep(40000) 'sleep 40ms for voltage to stabilize
        Dim voltage As Short = MoistureLevel
        Dim payload As ListOfByte = New ListOfByte
        Dim payString As String = ""
        If voltage > 1500 Then
            payString = "Dry - I NEED WATER!!"
        ElseIf voltage <= 1499 And voltage >= 800 Then
            payString = "Getting Low"             
        ElseIf voltage <= 799 And voltage >= 1 Then
            payString = "Watered!"               
           
        Else
        End If
        enableMoistureLevel = False 'turn off voltage divider
       
        // Create temp JSON object - { "MoistureLevel" : "Moisture Message" }
        Dim moistureJson As Json = New Json
        moistureJson.Add("Moisture", payString)
       
        // Create Losant preferred JSON object - { "data" : {"MoistureLevel" : "Moisture Message"}}
        Dim losantPayload As Json = New Json
        losantPayload.Add("data", moistureJson)
       
        // Publish to Losant MQTT
        Lplan.Publish(LosantTopic, losantPayload.ToListOfByte)
    End Event
    Shared Event CheckTemp() RaiseEvent Every 60 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 5 Minutes
        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

Here is a link to the live dashboard!! https://goo.gl/xLRzPB
Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB

Social Buttons