Author Topic: Cayenne My Devices  (Read 1396 times)

Labmaster

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Cayenne My Devices
« on: November 27, 2017, 11:41:42 pm »
My Devices has MQTT support now.  I'm trying to send temperature, but I can't figure out correct lplan.publish stuff.

Code: [Select]
// MQTT topic in MyDevices.com - v1/username/things/clientID/data/channel
    Const mdTopic As String = "v1/" + mdUserId + "/things/" + mdClientId + "/data/" + mdChannel
    Shared Event CheckTemp() RaiseEvent Every 10 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)
        tempJson.Add("temp,c=", "99")
        // Create Wia preferred JSON object - { "data" : {"temperature" : "23.06"}}
        Dim wiaPayload As Json = New Json
        //wiaPayload.Add("data", tempJson)
        wiaPayload.Add("temp,c=99")
        Dim mdData As String = "temp,c=99"
        // Publish to wia MQTT
        Lplan.Publish(mdTopic, mdData.ToListOfByte)
        Lplan.
       
        // Blink Red LED after publish to MyDevices.com
        LedRed = True
        Thread.Sleep(100000)
        LedRed = False
    End Event