1

So this is going to sound strange, but I don't see the date stamp of w1_slave files change as the contents (and temperature changes). I think it's set as the boot time and doesn't change. Ever

pi@bedroom1:/sys/bus/w1/devices/28-0115735605ff $ ll
...
-rw-r--r-- 1 root root 4.0K Nov 13 21:54 w1_slave

The time above shows 21:54 but the actual time was 22:07

pi@bedroom1:/sys/bus/w1/devices/28-0115735605ff $ date
Mon 13 Nov 22:07:22 GMT 2017

Again, to show I'm not cracking up:

pi@bedroom1:/sys/bus/w1/devices/28-0115735605ff $ ll
...
-rw-r--r-- 1 root root 4.0K Nov 13 21:54 w1_slave

Then when I cat it with some time in between (and temperature change):

pi@bedroom1:/sys/bus/w1/devices/28-0115735605ff $ cat w1_slave 
82 01 4b 01 7f ff 0c 10 59 : crc=59 YES
82 01 4b 01 7f ff 0c 10 59 t=24125

pi@bedroom1:/sys/bus/w1/devices/28-0115735605ff $ cat w1_slave 
a1 01 4b 01 7f ff 0c 10 34 : crc=34 YES
a1 01 4b 01 7f ff 0c 10 34 t=26062

pi@bedroom1:/sys/bus/w1/devices/28-0115735605ff $ ll
...
-rw-r--r-- 1 root root 4.0K Nov 13 21:54 w1_slave

The date hasn't changed!

Tailing with -f doesn't update 'on the fly' either when I would have expected it too.

pi@bedroom1:/sys/bus/w1/devices/28-0115735605ff $ tail -f w1_slave 
99 01 4b 01 7f ff 0c 10 e2 : crc=e2 YES
99 01 4b 01 7f ff 0c 10 e2 t=25562

So what am I missing? Isn't this a "regular file"? I've tried to setup a inotify based watcher on this file and am getting no results.

enter image description here

The small print: I'm comfortable with the Pi and the sensor, and I have several machines running with working sensors. This surprised me when I switched from a "polling" watcher, reading the file every few seconds to a inotify based one.

  • /sys is a virtual file system that can be accessed to set or obtain information about the kernel's view of the system. The 21:54 is likely the timestamp your pi started detecting the ds18b20 after the w1 module got loaded. You can try to do a watch w1_slave if you want to see the file change. – steviethecat Nov 15 '17 at 10:37
1

This is documented in the linux w1_therm driver information file and a bit of a give-away is the time it takes to read the w1_slave file.

Each open and read sequence will initiate a temperature conversion then provide two lines of ASCII output.

So when you open the file for reading it initiates a temperature conversion on the DS18B20 device and you get to wait 750ms for it to complete. There is no support for having the device continuously read and this file updated. You would need to do that using some non-blocking I/O in your application instead.

w1_therm.c line 460 has the delay definition.

So to answer the question: no, it is not a regular file.

  • Thanks for the answer and references. It looks like the minimum polling frequency of any application would have to be >750ms then. I wonder how fast the device can do the calculation. – Toby Nov 16 '17 at 12:41
  • The conversion times are documented in the device datasheet and depend on the resolution. It seems the current Linux driver for this supports changing the resolution but continues to use the worst-case delay time of 750ms and for some reason does't change the timeout value according to the resolution selected. – patthoyts Nov 16 '17 at 16:14
  • Awesome, so according to datasheets.maximintegrated.com/en/ds/DS18B20.pdf from 94 to 750ms, thanks – Toby Nov 17 '17 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.