Running python in node-red, passing back a msg

We'll this is good news, at least I'm making progress, everyday going over w3schools.com/js/js_objects.asp and nodered messages doc. As I understand the DS18B20 sensor it writes 2 lines out to a file(w1_slave) and I wanted to make sure when I pickup that temp in the file that it's not a temp from 20 minutes ago as something might have gone bad with the sensor and writes to the w1_slave file. I then display this temp on a dashboard.
The plan is to monitor at least 3 places on the boat while underway. I want to watch engine room temperature and the packings on both shafts. Yes, I could buy some marine industrial stuff for this, but I need a project like this in my retirement as I've been doing home automation since the 90's with x10 stuff.

OK, understood. I don't use that node as I said earlier. I haven't got time to look at it at the moment. Have you submitted an issue? You might get a quick response. Do you see the timestamp using the technique you used originally, or does it get it from a timestamp on the file itself, or something like that?

I have not submitted an issue yet but will sometime today. I've never seen the timestamp even in my original code but was looking for a way to get it from the file, and that would be ok. This node caught me because it was to have it, I'll play with this sometime this evening.

What do you see if you run
ls -l the/file/name
does the timestamp on the file change as it samples the sensor?

That's valid for ALGOL as well, I do remember, at the university back in the 70's, I guy was in too much hurry, lost the box in the stairs, cards flying all over down from 3rd floor, he had to spend some time to pick them up and sort them in correct order again...

2 Likes

Quick tip: you can make the script a lot easier on the eyes by introducing a variable before the if statements:

payload = msg.payload.decode("UTF-8")
if (payload == "..."):

I'm still 25-30 years away from retiring but this sparked a long forgotten memory. I remember sometime in the end of 90s having a couple of X10 smart sockets and a X10 computer interface module attached to my Linux server (over COM-port). I also had a webcam hooked to my Windows computer running an (illegally obtained) copy of Real Networks Helix Server to encode and serve an RTSP stream. I knew a guy working at a local ISP who had set up a static IP address and a hostname to our fixed price ISDN connection I always had connected.

I could then watch the stream from my Nokia E90 phone over GPRS while connecting over SSH to toggle a light using a shell script. I guess I could say I was a bit ahead of time with IoT (and also very fortunate to have a tech enthusiast father sponsoring the equipment) :smile:.

It's strange funny how little things have changed in 20 years for me. Lately I've been playing around with RTSP cameras and just a few weeks ago installed a bunch of RF RGB-CCT garden lights to our cottage. Now I'm just toggling them through Blynk app and Node-RED. And it still seems to impress most friends, family and even (developer) colleagues and feels somewhat magical to myself also!

Add a sprinkler control, so as they are in shock and awe what you can do with all this technology, you can hose them down, and cool them off, so they don't over heat! (LOL)

Already done. :stuck_out_tongue_winking_eye:

hmmm, doesn't seem to, however it has the timestamp of when the I did the ls -l .... and that never changes, but the data within the file does as I can grab one of the sensors and do a cat w1_slave and watch the temp go up and down.

I don't understand what you mean by that. Does it change if you run ls again?

[Edit] By which I meant does the timestamp on the file shown by ls -l change after fetching new data and running ls again?

Also what happens if one of the devices is unavailable when you ask for data? If that is missing then you can presumably be sure that any data given by the node must be up to data, otherwise it would not be there again, in which case you don't need a timestamp. The docs for w1_therm says that every read causes the sensor to be read.

[More Edits] I have looked at the source code for the node and as far as I can see there is nothing in the code to set msg.timestamp. No reference to any timestamp at all in fact, so it looks as if the readme is just plain wrong.

No, the timestamp does not change. run ls get 12:28 wait 5 minutes run ls get 12:28
image

However I've found (google) several instances of where people say that if line 1 does not have a YES then you need to retry. No means device failure.
image

image

And what happens if you unplug one of the devices, or ask for a non-existent one?

Unplug and the directory goes away, and you get not such file or directory

w1-therm doc: "Support is provided through the sysfs w1_slave file. Each open and
read sequence will initiate a temperature conversion then provide two
lines of ASCII output. The first line contains the nine hex bytes
read along with a calculated crc value and YES or NO if it matched."

So it looks like the "YES" is nothing more than a check that the "data read" worked. That will probably be good enough for a validation.

I meant what does the ds18b20 node send?

I'm guessing it sends a "delete" of some kind ?. The directory and all associated data is gone once I pull the sensor + wire

So if there is data there that suggests that it has fetched it ok, so you don't need a timestamp. The fact that it is there means it must be ok and has just been read from the sensor.

yea, that's what I'm thinking. Now just ran a bunch of tests.Everything is there, un-plug sensor, everything(directory and files are there) exactly 1:30 seconds later the directory and all files are deleted. and during that time I've done nothing but ls commands. Something(w1-therm?) is running every 1:30 seconds and deleting the directory and files.