DS18B20 on R-Pi with Cayenne

I installed Cayenne on R-Pi3+ and it was magic. I found that I could login to my Cayenne web account and there was my R-Pi dashboard with various display widgets, including an existing DS18B20 (digital temperature sensor).


My question now is how to read the DS18B20 with MQTT. I suppose I should also ask about MQTT with the other widgets that you see there, such as network speed. How are these values sent to the Cayenne dashboard? I’m beginning to suspect they are not published by MQTT.

I had previously installed the temp sensor to r-pi using modprobe w1-therm. This creates a permanent device at /sys/bus/w1/devices/28-000007a89399. The device apparently can be polled to write the current temperature into a file.

I also have a DHT22 temp and humidity sensor. This device was not installed as a system device. I have used the Adafruit_Python_DHT software and cayenne.client to publish MQTT messages for it. I then created a Cayenne dashboard for it.
r-pi-cayenne-dht
I have also written a Python client to subscribe to DHT22 messages from my Cayenne-MQTT publisher. So, I’ve made a lot of progress in understanding this stuff.

But my question remains: how does the DS18B20 data get to Cayenne dashboard? Is MQTT involved? Do I need to write more code for MQTT publish of the DS18B20 if I want to subscribe from other clients?

I hope I’ve been clear enough. Thanks for your help.

@kitecamguy great to hear that you like the Cayenne platform. When you installed cayenne on your pi, it created all the pre widget like (CPU, RAM, Storage< temp, speed, reboot, and shutdown). It then pulled data from the 1-wire DS18B20 and it might have shown as a temporary green widget.The pi agent then publish data using MQTT and can be found in GitHub - myDevicesIoT/Cayenne-Agent: Cayenne Agent

I would love to see how this work.

Are you referring this, so that you can get DSB18B20 data on the DTH sensor dashboard?

Darn it, I’m not very markdown savvy - I expected to be able to reply with quoted inclusions of your reply. Oh well.
The DHT22 code is something I found here: DHT11/DHT22 with Raspberry Pi

You mentioned that initially my DS18B20 would appear as a temporary green widget. I seem to recall that was true, and then I did something to make it permanent.

Getting the DS18B20 on my DHT sensor dashboard would be nice, but mainly I’m trying to figure out how the data of the R-Pi system (incl. DS18B20) gets onto the dashboard. Is it strictly MQTT or something else? I think that the link to Cayenne-Agent that you’ve provided tells me that it is MQTT. If MQTT, then I need to figure out the ClientID, Username, Password and topic strings so that I can subscribe from other clients.

@jburhenn can provide better detail on how pi agent works.
If you want to add DS18B20 to DTH dashboard then you have to only add the code for DS18B20 into the DHT11/DHT22 with Raspberry Pi you are using and then use a separate channel to display DS18B20 data.

1 Like

Give a shout if you have any problems with @shramik_salgaonkar suggestion. I should still have that Pi hooked up somewhere…

1 Like

Yes, the agent uses MQTT to communicate with the server. To see your MQTT credentials you can look in the AppSettings.ini file at /etc/myDevices/AppSettings.ini.

For communications the agent sends JSON messages on the v1/{username}/things/{client_id}/data/json topic. If you’d like to look at the code that creates the topics and sends messages that is available at Cayenne-Agent/cayennemqtt.py at master · myDevicesIoT/Cayenne-Agent · GitHub. You can subscribe to any topics under your user account. In other words any topics starting with v1/username/....

To get the DS18B20 data you’d need to parse the JSON data to get the sensor channel that matches the channel in the DS18B20 widget settings.

1 Like