Quick note if you're a) reading multiple ds18b20's with a raspberry pi and b) struggling with flow stalls

I'd been using the node-red-contrib-ds18b20-sensor node to read 4 ds18b20's directly from gpio4 on my raspberry pi. Unfortunately this seemed to cause the flow to stall for 2-3 seconds while the pi was bit banging the 1-wire comms to the sensors. I've got a fiddly PID loop that needs regular updates and this was really throwing that out of whack.

It's possible there are other ways around this issue, maybe owfs, maybe the other ds18b20 node, maybe a dedicated 1-wire bridge...but I sidestepped it entirely by moving the sensors to a nodemcu esp8266 running tasmota. The temps now come in over MQTT using the mqtt server node and everything is running smooth as butter. I can run the entire flow every second if I want with no stalls or weirdness. It's awesome.

FWIW installing tasmota on a newish nodemcu is basically 1) download latest tasmota-sensors image, 2) download tasmotizer, 3) flash. If you start reading on how to flash esp8266 you're going to see all sorts of stuff about serial to usb hardware and all that jazz..if you go with a nodemcu it's built in.

I'm basically positive doing this with an arduino would yield the same benefit. I've read a few places that the wifi + esp8266 can lead to weirdness when reading ds18b20's. etc.etc. My point is that this really cleared a major problem up for me with almost no effort.

Hope that helps.

1 Like

I have similar experiences using 6 ds18b20 sensors. I have solved it in a similar way, by writing a Node.js script that runs as a service, outside of Node-RED, but on the same machine(Pi). That service reports the temperatures to the mqtt server and Node-RED experiences no delays and does not stall anymore.

1 Like

I had a quick look at the source code of the contrib node: https://github.com/bpmurray/node-red-contrib-ds18b20-sensor/blob/master/ds18b20-node/ds18b20-node.js

They use synchronous file access to the sensors. This prevents the NodeJS event loop to process other tasks until the operation has finished. Depending on the sensor's resolution, the DS18B20 readings can take over a second per sensor. So the blocking behavior you described is to be expected.

I see you have already found your way to using an ESP8266 and MQTT, that would have been my preferred suggestion as well. :+1:
In fact, that is my setup at home and works like a charm. I have deployed around 8 ESPs here with several sensors (BME280, DS18B20) and door/window switches. :grin:

@nrbrt - that's a great idea! I'm running nodered in docker on the pi and thought of just running a second instance, but figured I'd just give this esp thing a go since i had one collecting dust anyway.

This is going to be me now that I see how easy it is. You can buy 50 of them for $3 each haha.

Before you jump in (and depending on what you are measuring the temperature of) - have a look at some of the Xiaomi Bluetooth sensors out there

  1. Dirt Cheap
  2. Battery operated
  3. Pass the WAF as they actually look 1/2 way decent
  4. Speak through Bluetooth to an ESP32 which can then pass on the results through MQTT to NR
  5. a Single ESP32 can service a number of sensors (think 1 per floor - depending on walls etc)

I am just in the process of moving a number of my older ESP8266 and DS18B20 units across to this environment

Link here

Craig

Yes, I found that script a few weeks ago, and it works great. Thanks!
(https://github.com/nrbrt/ds18b20-service)
Now MQTT provides a reading of 5 sensors every 5 seconds.

However, a couple of days ago 3 out of 5 sensors disappeared from the MQTT stream. Rebooting the Pi did not work. I had to unplug the sensor wires from the Pi, put them back again, and they reappeared.

1 Like

I'll bump this, because it helped me solve a seemingly difficult problem with random errors.
Node-red started to throw the error "EINTR: interrupted system call, read". At first I didn't find the cause, because it started some time after I had included the ds18b20 node. Apparently it was caused by the way the ds18b20-node was handling requests.

@nrbrt Great small scipt!

The service has been running flawlessly ever since I implemented it.

1 Like

I ran into this prob back in 2019.

Here is a link to the solution I came up with.
https://discourse.nodered.org/t/fastest-onewire-ds18b20-update-rate-on-raspberry-pi/16520/10?u=meeki007

Here is a copy of that post:

I too have a ton of DS18B20's and was floored by how long it took to get data back down the line using contrib-ds18b20-sensor
So I started diggin how is polling the sensors on a 1 wire can geting so congested

If you look at the contrib-ds18b20-sensor code ds18b20 github . You will notice that its polling information from all the sensors then checking an array for the matching ID you entered into the node.

So if you have 10 sensors its polling 10 times! 10 sensors Its not using the match rom commands found in the 1-wire documentation. DS18B20.pdf

My solution was to poll once and sort the data myself. I've had 14 sensors talking fine!

Here is my flow I'm using for one 100 yard lane of the company freezer ( oh there are more lanes :blush: )

[{"id":"6a6c83b8.bb185c","type":"inject","z":"e1935875.a74068","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":120,"y":80,"wires":[["13ef1dd3.a2cf62"]]},{"id":"604ddc78.fab204","type":"comment","z":"e1935875.a74068","name":"TESTING: Output all temp sensors connected into an array. To figure out sensor ID's","info":"","x":310,"y":40,"wires":[]},{"id":"13ef1dd3.a2cf62","type":"rpi-ds18b20","z":"e1935875.a74068","topic":"","array":false,"name":"","x":310,"y":80,"wires":[["1f01bf2a.2f3b71"]]},{"id":"1f01bf2a.2f3b71","type":"debug","z":"e1935875.a74068","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":510,"y":80,"wires":[]},{"id":"d2bb6889.0e9c88","type":"comment","z":"e1935875.a74068","name":"Body: Tempature Probes","info":"diagram of map link here ","x":130,"y":140,"wires":[]},{"id":"78b46331.d9ff7c","type":"comment","z":"e1935875.a74068","name":"Freezer_400_East_U","info":"","x":240,"y":240,"wires":[]},{"id":"796619bd.d06898","type":"comment","z":"e1935875.a74068","name":"edit when changing sensor","info":"","x":750,"y":180,"wires":[]},{"id":"b656262f.9f4ee8","type":"comment","z":"e1935875.a74068","name":"TmpSen-Checks ----->","info":"","x":1200,"y":260,"wires":[]},{"id":"1a32f115.43a18f","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_East_U","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":240,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"a9f385f1.3e9de8","type":"debug","z":"e1935875.a74068","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1170,"y":600,"wires":[]},{"id":"69e008c7.5e0bd8","type":"link out","z":"e1935875.a74068","name":"TmpSen-RX OUT","links":["7b1ba438.5b19ec","7410bd02.e9f9b4"],"x":1075,"y":260,"wires":[]},{"id":"4a0ae719.de3f58","type":"inject","z":"e1935875.a74068","name":"30sec","topic":"","payload":"","payloadType":"date","repeat":"30","crontab":"","once":true,"onceDelay":"","x":120,"y":180,"wires":[["a780bcc.d212b4"]]},{"id":"1abb841e.5a146c","type":"switch","z":"e1935875.a74068","name":"If = FFB001A31704","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FFB001A31704","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":240,"wires":[["1a32f115.43a18f"],["b619ce5b.8681a"]]},{"id":"a780bcc.d212b4","type":"rpi-ds18b20","z":"e1935875.a74068","topic":"","array":false,"name":"","x":310,"y":180,"wires":[["1abb841e.5a146c"]]},{"id":"4a878a7f.f420b4","type":"comment","z":"e1935875.a74068","name":"Freezer_400_East_L","info":"","x":240,"y":280,"wires":[]},{"id":"b619ce5b.8681a","type":"switch","z":"e1935875.a74068","name":"If = FFAA33401802","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FFAA33401802","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":280,"wires":[["d0e0c004.6fd2a"],["3e0ebc54.8d7ee4"]]},{"id":"d0e0c004.6fd2a","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_East_L","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":280,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"98d18d4e.df1cd","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Center_U","info":"","x":240,"y":320,"wires":[]},{"id":"3e0ebc54.8d7ee4","type":"switch","z":"e1935875.a74068","name":"If = FFAA0F411801","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FFAA0F411801","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":320,"wires":[["12701796.dd9258"],["8dc831b7.4b3a5"]]},{"id":"12701796.dd9258","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Center_U","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":320,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"54ce9ea5.13a41","type":"comment","z":"e1935875.a74068","name":"Freezer_400_West_U","info":"","x":240,"y":360,"wires":[]},{"id":"8dc831b7.4b3a5","type":"switch","z":"e1935875.a74068","name":"If = FF8710411801","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF8710411801","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":360,"wires":[["9c0c8a20.b71128"],["c9cc70a.b54399"]]},{"id":"9c0c8a20.b71128","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_West_U","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":360,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"f8eb4ab0.77f5e8","type":"comment","z":"e1935875.a74068","name":"Freezer_400_West_L","info":"","x":240,"y":400,"wires":[]},{"id":"c9cc70a.b54399","type":"switch","z":"e1935875.a74068","name":"If = FF790B411801","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF790B411801","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":400,"wires":[["9c20d488.d080b8"],["a738605e.324f3"]]},{"id":"9c20d488.d080b8","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_West_L","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":400,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"a9b72790.2912e8","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_West_Coil","info":"","x":200,"y":440,"wires":[]},{"id":"a738605e.324f3","type":"switch","z":"e1935875.a74068","name":"If = FF2233401802","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF2233401802","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":440,"wires":[["8ccbe599.592bb8"],["1f08a207.0316be"]]},{"id":"8ccbe599.592bb8","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_West_Coil","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":440,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"fdabded6.4baed","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_West_Intake","info":"","x":190,"y":480,"wires":[]},{"id":"7024c4f.2a0f93c","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_West_Exhaust","info":"","x":180,"y":520,"wires":[]},{"id":"f2757e0e.8448e","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_East_Coil","info":"","x":200,"y":560,"wires":[]},{"id":"adf5687a.72fbe8","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_East_Intake","info":"","x":190,"y":600,"wires":[]},{"id":"1f08a207.0316be","type":"switch","z":"e1935875.a74068","name":"If = FF370F411801","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF370F411801","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":480,"wires":[["7dd0da09.27a764"],["83e81070.5a8b6"]]},{"id":"7dd0da09.27a764","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_West_Intake","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":480,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"83e81070.5a8b6","type":"switch","z":"e1935875.a74068","name":"If = FF2BB7331801","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF2BB7331801","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":520,"wires":[["28e8b5f8.d64a0a"],["1cba9c60.871ca4"]]},{"id":"28e8b5f8.d64a0a","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_West_Exhaust","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":520,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"1cba9c60.871ca4","type":"switch","z":"e1935875.a74068","name":"If = FF1304C11705","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF1304C11705","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":560,"wires":[["6a9640cc.45f73"],["31d65f4.6ccd1a"]]},{"id":"6a9640cc.45f73","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_East_Coil","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":560,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"31d65f4.6ccd1a","type":"switch","z":"e1935875.a74068","name":"If = AAB7CA131302","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"AAB7CA131302","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":600,"wires":[["87c3c26e.0d41f"],["3c110f1.3dd4cf"]]},{"id":"87c3c26e.0d41f","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_East_Intake","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":600,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"72ba34ec.a7fe5c","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_East_Exhaust","info":"","x":190,"y":640,"wires":[]},{"id":"3c110f1.3dd4cf","type":"switch","z":"e1935875.a74068","name":"If = FF13A3B31701","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF13A3B31701","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":640,"wires":[["95291a0f.00d098"],[]]},{"id":"95291a0f.00d098","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_East_Exhaust","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":640,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]}]

Just a note for anyone reading this that I have used owserver for several years with node-red-contrib-owfs and it works perfectly on a selection of Pis from Zeros up. It does not suffer from the issues described above.

Looked at the link you provided but am not clear on how you get data from owserver into node red. Perhaps a thumbnail? Never mind. Missed the obvious

One advantage is that once owserver is running on the machine with the devices connected then you can use the node on any machine on the network and point at owserver on the first machine to get the data.

owserver is in the Raspbian and Ubuntu repositories.
sudo apt install owserver ow-shell
ow-shell provides command line tools such as owdir and owread which can be useful for debug. Just install and use (or you might need to enable and start it, not sure).

$ owdir
/lounge_temp
/28.FF0C36511604
/28.FF52B0561603
/bedroom_temp
/bus.0
/uncached
/settings
/system
/statistics
/structure
/simultaneous
/alarm

You can specify aliases which map device ids to useful names (such as lounge_temp above). That name can be used in the owfs node. If you have to change a sensor you just have to change the alias in the owserver conf file and everything else keeps working :slight_smile:

Hello. I am using node-red on a RBPI4 for controlling the fermentation process in my brewery. I have 4 temperature sensors DS18b20 which are now physically wired in a parallel configuration (sensors are connected one after the other in a line) with CAT5 wires to the GPIO4 of the PI. Furthest sensor is 10 meters away from PI. I use a 4.7 kOhm resistor between GPIO4 pin and +5V (used to power the sensors). In node-red I read each sensor every 10 seconds with the sensor-ds18b20 node. I have four separated flows for each fermenter (on each I read a different sensor). The problem I have is that randomly one of the sensor is like "offline" for some time which can last hours and then came back to life (see attached picture)

.
This is off course not nice because temperature signals are the feedback to the control loop opening and closing the cooling solenoid valves.

I tried the solution suggested by meeki007 with the contrib-ds18b20-sensor node but it did not work, had the error message: EINTR: interrupted system call, read.

The owserver is also not ideal because it relies on the wifi. Fermentation control has to run also if wifi is down.

My question is the following: is there any other reliable way to get the ds18b20 temperature sensor values and physically (with wires, not with wifi or Bluetooth) send them to the to the PI in which I am running the control loop with node-red?
Thanks in advance for any suggestions. I am struggling with this issue since a month now and I am unfortunately close to switch to a standalone but more reliable STC1000 solution.

What would account as reliable enough, possibly a separate Arduino board with an Ethernet shield and MQTT connection?

I've found sensor interfacing a lot more reliable on microcontroller platforms and tend to use ESP8266's for this kind of purpose. They communicate over WiFi though so I brought our a classic Arduino with ethernet. Often times the Arduino board - Raspberry Pi interface is done using serial but I've also read about enough issues with it already on this forum to not make me trusr the medium...

As far as I remember, the IO pins of the Pi are 3.3V level. You should power your sensors with 3.3V, including the GPIO pull-up. Otherwise you might damage your Pi.

Some good advice over here https://raspberrypi.stackexchange.com/questions/41234/max-length-of-wire-w-3-3v-or-other-issue

Thanks. This is quite helpful. I forgot to mention that with the exact same hardware configuration but with RBPI3B+ model instead of RBPI4 I had no issues in the last half a year

Thanks. An arduino board or similar + Ethernet shield and mqtt connection to the PI sounds a good alternative!

Another possibility is to use a USB to 1-wire adaptor. Then you get a full spec 1-wire interface rather than the poor imitation you get with direct Pi connection. That is ok for short wires and a few devices but will fail if you push it too far.

Or, alternatively, some ESP8266/ESP32 boards placed at strategic points (to keep the wires short) and push the data via MQTT.
I have one in each room, each with BME280 and DS18B20 sensors, and IO's for door/window switches.

1 Like