Author Topic: Cayenne My Devices  (Read 398 times)

Labmaster

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Cayenne My Devices
« on: December 01, 2017, 11:06:10 am »
I actually got it working last night.  It turns out that I had 2 devices defined in MyDevices.com, and I was using the correct client ID in the gateway, and the wrong clientID in the code.

This is the most recent version of my working code:
Code: [Select]
    // MQTT topic in MyDevices.com - v1/username/things/clientID/data/channel
    Const mdTopic As String = "v1/" + mdUserId + "/things/" + mdClientId + "/data/" + mdChannel
    //Const mdTopic As String = "kevin/MyDevicesCom/test"
    Shared Event CheckTemp() RaiseEvent Every 3600 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 mdPayload As ListOfByte = New ListOfByte
        Dim mdData As String = "temp,c=" + tempString
        //mdData = "temp,c=99"
        mdPayload.Add(mdData)
        // Publish to wia MQTT
        Lplan.Publish(mdTopic, mdPayload)
Winner Winner x 1 View List