A C implementation of the w1_therm temperature sensor reader for WildlifeSystems.
This program reads temperature data from 1-Wire temperature sensors connected to
the system via the Linux kernel w1_therm driver interface. It outputs readings in JSON
format compatible with the WildlifeSystems sensor-control framework.
Supported sensors:
- DS18S20 (family code 0x10)
- DS1822 (family code 0x22)
- DS18B20 (family code 0x28)
- DS1825 (family code 0x3B)
- DS28EA00 (family code 0x42)
makesudo make installThis installs the binary to /usr/bin/sensor-w1therm and the man page to
/usr/share/man/man1/sensor-w1therm.1.
sudo make uninstallsudo sensor-w1therm enableThis adds the w1-gpio overlay to /boot/firmware/config.txt. A reboot is required.
sensor-w1thermOutput example:
[{"sensor":"ds18b20","measures":"temperature","unit":"Celsius","sensor_id":"28-0123456789ab","value":23.500}]# Read only internal sensors
sensor-w1therm internal
# Read only external sensors
sensor-w1therm external
# Read all sensors explicitly
sensor-w1therm allsensor-w1therm setupThis is run automatically on boot by the systemd service.
sensor-w1therm listsensor-w1therm identifyReturns exit code 60.
sensor-w1therm versionsensor-w1therm mock-
Enable 1-Wire interface:
sudo sensor-w1therm enable -
Reboot the Raspberry Pi
The program uses the Linux kernel w1_therm driver sysfs interface:
/sys/bus/w1/devices/*/w1_slave- Traditional interface with CRC check/sys/bus/w1/devices/*/temperature- Direct temperature reading in millidegrees/sys/bus/w1/devices/w1_bus_master1/therm_bulk_read- Bulk conversion trigger
For more information, see the kernel documentation.
The program detects and reports the following error conditions:
- Startup value (85.0°C): Indicates the sensor has not completed a conversion yet
- Insufficient power (127.937°C): Indicates the kernel driver detected a power or bus error (not that the sensor is completely unpowered)
From within the sensor-w1therm directory:
debuild -us -uc -b- Linux kernel with
w1_thermdriver - POSIX threads library (pthread)
- GCC compiler
GPL-2.0-or-later
Comparison with older Bash version
Ed Baker ed@ebaker.me.uk
Part of the WildlifeSystems project. For more information, visit: