mc-Things
mc-Platform => MQTT => Topic started by: sketchet on December 28, 2016, 06:12:45 pm
-
Has anyone had any luck getting an mc-Gateway connected to Cayenne? I have been able to publish to CloudMQTT but have not been able to connect the mc-Gateway to Cayenne.
-
Hello,
MyDevices is still working to allow connection through MQTT. Hopefully this is available soon. As soon as this is good to go we will announce it on the forum
Thanks!
-
My Devices has MQTT support now. I'm trying to send temperature, but I can't figure out correct lplan.publish stuff.
// 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
-
Can you show your gateway set?
-
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:
// 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)
-
@Labmaster - Great work! Thanks for keeping us posted!