In the following thread the question of adding another LED was posed:
How to ad an extra led In the python esp32 course chapter Node_RED ?
Has anyone added another temperature sensor (DS18B20)? And how was it added?
Thanks again for posting a dedicated thread! Just to clarify:
- Do you want to add a different sensor to that ESP (like a DHT) and publish to an MQTT topic?
- Or do you want to connect multiple DS18B20 sensors to your ESP board to post temperature readings?
I want to connect multiple DS18B20 sensors to my ESP board to post temperature readings?
Ok. Unfortunately I don’t have any tutorials on that exact subject. I’ll describe what you would to do to publish more than one reading to Node-RED (I’ll use the MQTT with Node-RED example from the “MicroPython Programming with ESP32 and ESP8266” eBook).
In the boot.py file, you need to declare your second temperature topic: https://github.com/RuiSantosdotme/ESP-MicroPython/blob/master/code/MQTT/Node_RED_Client/boot.py
For example, you’ll publish the second temperature in the MQTT topic temp2 :
topic_pub2 = b'temp2'
In the main.py file: https://github.com/RuiSantosdotme/ESP-MicroPython/blob/master/code/MQTT/Node_RED_Client/main.py
I would need to modify line 50 to:
read_ds_sensor()
Delete line 51:
client.publish(topic_pub, msg)
Then, in the read_ds_sensor() function, you need to modify it to look something like this:
def read_ds_sensor(): roms = ds_sensor.scan() print('Found DS devices: ', roms) print('Temperatures: ') ds_sensor.convert_temp() time.sleep(1) i = 0 for rom in roms: temp = ds_sensor.read_temp(rom) if isinstance(temp, float): # uncomment for Fahrenheit #temp = temp * (9/5) + 32.0 msg = (b'{0:3.1f}'.format(temp)) print(temp, end=' ') print('Valid temperature') if i==0 : client.publish(topic_pub, msg) elif i==1 : client.publish(topic_pub2, msg) i = i + 1
Something like that should work. There are better ways to do it, but unfortunately I don’t have time to write a custom script or to test it. Make sure while copying and pasting you do the right indentation.
For the wiring, you can use this tutorial as a reference: https://randomnerdtutorials.com/esp32-with-multiple-ds18b20-temperature-sensors/
I hope that helps!
Everything seems to be working as you suggested above. I now have four DS18B20 temperatures sensors indicating on node-red gauges and charts. However, when I connected all four temperatures to one chart, they would not indicate on the chart and I also could not seem to figure out how to connect different colors to different temperature lines on the chart. I then left it running over night and the next day I had four lines (temperatures) on one of the charts that was connected to all four temperatures. Do you have any explanation why the four readings took so long to show up. I must have tried a dozen times to record multiple temperatures without success and then this happened. Also I still haven’t figured out how to assign different colors to different lines on the chart. Any ideas?
Now, the next step would be to view these temperatures from anywhere on the internet as presented in the Node-Red Dashboard. I was so impressed with Unit 7 – Accessing the ESP32 Web Server from Anywhere, in your “Learn ESP32 with Arduino IDE and I wonder if I can view my temperatures from anywhere? I guess this should be another thread?
Another again thank you so much for these challenging projects. You really do a good job in your presentations.
Hello again, I’m glad it’s working now and you were able to modify the code to make it compatible with the four sensors!
However, I don’t have an explanation for what happened to you… The readings should appear in your Node-RED charts immediately after they were published.
- After a few hours, is it work now reliably?
- Are the readings appearing instantly?
You can use Ngrok running in the Raspberry Pi to make the Node-RED dashboard accessible from anywhere 🙂
Rui,
I’m having trouble with the ESP32 getting hung up and not transmitting through Ngrok. My dashboard will work for awhile and then stop. Temperature gauges and charts still indicate but get hung up and the charts stop advancing. Gauges also freeze in place. When I depress the “enable” button things start working again.
Do you have any ideas as to why processing stops and how to keep the ESP32 functioning?
I’m not sure, what do you see in the Shell/Terminal/Serial Monitor of your ESP32?
It’s probably having some error that crashes the board… but based on that information I’m not sure what’s happening.
Rui,
Started New Thread:ESP32 gets hung up and stops processing temperatures on charts and gauges
I guess my problem is that my ESP32 gets hung up and stops processing. Charts stop recording and gauges stop. I monitored the serial monitor and got the following:
Found DS devices: [bytearray(b”(‘\xa9\xb3/\x14\x01\xb6″), bytearray(b'(\x89\xa0%0\x14\x01\xf7′), bytearray(b'(\xde[\xae/\x14\x01\xd2′), bytearray(b'(bc*0\x14\x01\xd0’)]
Temperatures:
74.075 Valid temperature
73.5125 Valid temperature
73.5125 Valid temperature
73.85 Valid temperature
Found DS devices: [bytearray(b”(‘\xa9\xb3/\x14\x01\xb6″), bytearray(b'(\x89\xa0%0\x14\x01\xf7′), bytearray(b'(\xde[\xae/\x14\x01\xd2′), bytearray(b'(bc*0\x14\x01\xd0’)]
Temperatures:
74.075 Valid temperature
Traceback (most recent call last):
File “main.py”, line 137, in <module>
File “main.py”, line 125, in <module>
File “main.py”, line 21, in read_ds_sensor
File “ds18x20.py”, line 39, in read_temp
File “ds18x20.py”, line 29, in read_scratch
Exception: CRC error
MicroPython v1.9.4-762-gfa50047bb on 2018-12-28; ESP32 module with ESP32
Type “help()” for more information.
>>
I’ve reproduced this several times with the same message. I’m using the above code and your recommended additions for four temperature inputs. Any suggestions why this is happening and how to fix it?
Ok! I’ll mark this thread a “Closed” and continue the conversation here: https://rntlab.com/question/esp32-gets-hung-up-and-stops-processing-temperatures-on-charts-and-gauges/