Ds18b20 wrong value if temperature is below 0 degrees

i use the ds18b20 sensor with raspberry. Since update to node-red 1.2.9. the values of temperatures below 0 degrees are showing wrong. There is p.e.4093.9. What can i do?


Welcome to the forum @Speedy.

Please feed the output of the sensor node into a Debug node and screenshot what you see in the debug pane. You can paste an image here directly. Also tell us which node you are using, there are several DS18b20 nodes. It is probably node-red-contrib-something. If you are not sure look in Manage Palette to find out,

Also stop node red then start it again in a terminal using node-red-start and copy/paste here what you get. Copy/paste for this please not a screenshot. When pasting logs or flows here use the </> button at the top of the forum entry window and paste it in. The startup log will tell us a lot about your system.

Node: node-red-contrib-sensor-ds18b20

It's work before the update fine. All other sensors > 0 degrees are ok.

If you warm it up is it ok again?

Don't forget the log.

Is this you or somebody else? Fails to read negative temperatures!! (Any more!!) · Issue #6 · charlielito/node-red-contrib-sensor-ds18b20 · GitHub

What version of Raspibian are you using?

Doing a search I found a thread that had a similar issue and doing a apt full-upgade fixed it. Worth a try

Yes. Positive temperature is show correct.

Hi, i've the up to date version. Full-upgrade show that no updates available. The problem is since the note-red update.

Yes! That's my problem, too.

OK, show us the startup log then please.

11 Feb 13:11:10 - [info]
Willkommen bei Node-RED!
11 Feb 13:11:10 - [info] Node-RED Version: v1.2.9
11 Feb 13:11:10 - [info] Node.js  Version: v12.20.1
11 Feb 13:11:10 - [info] Linux 5.10.11-v7+ arm LE
11 Feb 13:11:11 - [info] Paletten-Nodes werden geladen
11 Feb 13:11:13 - [info] Einstellungsdatei: /root/.node-red/settings.js
11 Feb 13:11:13 - [info] Kontextspeicher: 'default' [ module=memory]
11 Feb 13:11:13 - [info] Benutzerverzeichnis: /root/.node-red
11 Feb 13:11:13 - [warn] Projekte inaktiviert: editorTheme.projects.enabled=false
11 Feb 13:11:13 - [info] Flow-Datei: /root/.node-red/flows_raspberrypi.json
11 Feb 13:11:13 - [warn]
Die Datei mit den Datenflowberechtigungsnachweisen wird mit einem vom System generierten SchlĂĽssel verschlĂĽsselt.
Wenn der vom System generierte SchlĂĽssel aus irgendeinem Grund verloren geht, werden Ihre Berechtigungsnachweise
Die Datei kann nicht wiederhergestellt werden. Sie müssen sie löschen und erneut eingeben.
Ihre Berechtigungsnachweise.
Sie sollten Ihren eigenen SchlĂĽssel mit Hilfe der Option 'credentialSecret' in
Ihre Einstellungsdatei. Node-RED wird dann Ihre Berechtigungsnachweise erneut verschlĂĽsseln.
Datei mit dem ausgewählten Schlüssel beim nächsten Deployen einer Änderung verwenden.
11 Feb 13:11:13 - [info] Flows starten
11 Feb 13:11:13 - [info] Flows gestartet
11 Feb 13:11:13 - [info] Server wird jetzt auf ausgefĂĽhrt.

It appears you didn't use the recommended script to install node red, so somehow you are running as root. Which is a bad idea.

I've use this script. Is the root-install the problem?

Edit: I've (re)install node-red after normal apt upgrade, because the nagative problem.

I don't know whether that is the problem. How are you running as root? Did you run teh script using sudo or logged on as root or something like that?

This tutorial shows you how you can look at the system pseudo files for the sensor to check that the system side of it is working. Raspberry Pi Tutorial Series: 1-Wire DS18B20 Sensor - Waveshare Wiki

I was logged on as root :frowning:
The sensor is ok. If the temperature positive then the correct value is shown.

I've 13 ds18b20 sensors, but the only with negative temperature don't work.

Have you tried any of the other ds18b20 nodes?

I've tried one other node. There i must add a Topic and can not choose a SensorID. I don't no how this work. The values shouldt stored in the influxdb.

Did you check the /sys files as I suggested?

You should not even have the root user enabled. There is never any need for that.

I can't help you directly but I ran into a similar problem with a sketch running on a ESP8266 and found the following which fixed my code. Apparently Arduinos do the math differently and don't have the issue. I rather suspect that the following lies at the heart of your issue.

" 'byte' is unsigned. When you put MSB and LSB together on UNO or NANO, it seems that (MSB << 8)|LSB results in the correct signed number. But on the ESP8266 it looks like it results in an unsigned number. This will turn all negative numbers into large positive ones. For example, 0xFFF8 is -0.5 degrees, but as a positive number it is 65528 and dividing by 16 gives you 4095.5.
Throwing (int16_t) on the front forces the compiler to treat the result as a signed 16-bit integer which then gives the correct result."