Can't publish temperature from McThings


#1

I’m trying to do a simple temperature sensor from McThings using MQTT. The publish function in McThings seems simple enough by sending a topic and a payload.

I am pretty sure that I have the topic correct. I can see “Last data packet sent…” information in the Cayenne Dashboard that is updating every time I try to send data. There is also a flash in the Dashboard that says “Offline” every time I try to publish.

I think the problem is in the payload. From the Cayenne documentation, it looks like I should be sending a string. Seems simple enough “temp,c=21”. It seems like McThings only wants to send a “ListOfBytes”, not a string.

How can I get Cayenne to accept a “ListOfBytes” as the payload?

McThings is listed as a partner on the MyDevices.com website. Can you talk to them directly to figure out how we can publish from McThings?

Thanks


#2

Yeah we like the guys at McThings. Before I talk with them, let’s see if @jburhenn has any ideas about how to see data coming from the McThings payload.

~B


#3

I’d suggest trying to convert the String to ListOfByte. This link seems to suggest you can do that using payload.Add(string).
http://mcthings.createaforum.com/mqtt/working-with-listofbyte/

I assume that just converts the string into a list containing ASCII characters which in theory would be correctly processed as a string payload by the Cayenne server. So I’d suggest giving that a try. If it doesn’t seem to work you could try connecting to a public broker like broker.hivemq.com to see exactly what is being received and if it matches the “temp,c=21” payload you send.


#4

I saw the function that accepts a string, and I tried it and it didn’t work either.

Thanks for the broker.hivemq.com suggestion. I have that working with McThings with a ListOfBytes object. When I subscribe, I see the text that I expect. I am using MQTT.fx v1.5.0 to subscribe, and Payload decoded by “Plain Text Decoder”. I am publishing my temp hourly on broker.hivemq.com. You can subscribe to the topic to see for yourself - kevin/MyDevicesCom/test

A this point I think that I have a configuration problem on Cayenne, or Cayenne is not working. I removed McThings from the equation. I basically set up MQTT.fx v1.5.0 the same as the sample in the Cayenne documentation, and it has the same problem. It seems to successfully publish the message, the dashboard blinks offline, and no data is stored. I also can’t subscribe to that topic in MQTT.fx (java error with a stack that is beyond my knowledge).

Can anyone else run a quick test with MQTT.fx to see if they can publish, just like the example in Cayenne API docs?
https://mydevices.com/cayenne/docs/bring-your-own-thing-api/
Search for “type,unit=value”, that will take you to the section with the example that I am trying to do.


#5

Do you maybe have another device trying to use the same MQTT credentials? E.g. an Arduino or MQTT.fx or a Python test app? If two devices try to use the same credentials they can cause each other to keep disconnecting/reconnecting. You might try generating another MQTT device to test with.


#6

Seems to work ok for me. The topic should be :
"v1/" + username + "/things/" + clientid + "/data/" + channel

And the payload:
temp,c=21

(username and client id removed - replace with info from dashboard)
image
image

I did get the disconnect flash when I use the wrong username/clientID in the topic so it’s worth checking that.


#7

Wohoo… progress!!! Somehow I had 2 device ID’s and the first one I was using was not working. The second device ID works, so I deleted the first ID.

I have seen a couple of data points come in from McThings, so the whole “listOfByte” vs. Strings is taken care of. The McThings implementation is just fine.

Code snippet in case someone else tries with McThings…
Const mdTopic As String = “v1/” + mdUserId + “/things/” + mdClientId + “/data/” + mdChannel
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)

I’m still having troubles with MQTT.fx though. I can’t get it to stay connected to the broker. Double checked all my settings, I’ll look at that another day.

2017-11-30 20:12:45,474 INFO — MqttFX ClientModel : MqttClient with ID 22d59050-d3f1-11e7-86d0-83752e057225 assigned.
2017-11-30 20:12:45,993 INFO — MqttFX ClientModel : Broker connection lost: Resetting client.
2017-11-30 20:12:45,995 INFO — ScriptsController : Clear console.
2017-11-30 20:12:45,996 INFO — ScriptsController : Clear console.
2017-11-30 20:13:21,197 INFO — BrokerConnectorController : onConnect
2017-11-30 20:13:21,199 INFO — ScriptsController : Clear console.
2017-11-30 20:13:21,199 INFO — MqttFX ClientModel : MqttClient with ID 22d59050-d3f1-11e7-86d0-83752e057225 assigned.
2017-11-30 20:13:21,623 INFO — MqttFX ClientModel : Broker connection lost: Resetting client.
2017-11-30 20:13:21,624 INFO — ScriptsController : Clear console.
2017-11-30 20:13:21,625 INFO — ScriptsController : Clear console.


#8

If you are using the same MQTT credentials with MQTT.fx that you are using with your connected mcThings device you may see connection issues. You should only connect one device per client ID. If you want to test with MQTT.fx you can generate another Bring Your Own Things device and use those credentials, or make sure the mcThings device is not connected before using its credentials.