Skip to content

Toy rust program for retrieving temperature data from a DS18B20 sensor

Notifications You must be signed in to change notification settings

awendland/rpi-ds18b20-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RPI DS18B20 Temp Sensor

This is a toy program written in Rust for retrieving temperature data from a DS18B20 sensor attached via the one-wire interface to a Raspberry Pi.

Setup

This was developed on macOS and cross-compiled for a Raspberry Pi 3. To ease in cross-compiling, cross and rustup were used.

First, rustup was used to retrieve the appropriate target components rustup target add armv7-unknown-linux-musleabihf.

Then, cross was used to transparently create a Docker environment for the cross-compilation toolchain via cross build --target armv7-unknown-linux-musleabihf. Output from cross is placed in target/ as if cargo was used directly.

Usage

The program is quite simple (it mostly just reads from the w1 virtual file system). By default it outputs the temperature from the sensor in farenheit, or if either -r/--raw is passed it outputs it in millicelsius.

Expanded Usage

I setup a cron job on my Raspberry Pi to submit the latest temperature data to a Google Sheet via one of the proxy Google Sheet API services. For example, the cron entry looks something like:

*/15 18,19,20 * * * curl -X POST 'https://api.steinhq.com/v1/storages/TOKEN/SHEET' --data "[{ \"Time\": \"$(date -u +"\%Y-\%m-\%dT\%H:\%M:\%SZ")\", \"Temperature\": $(~/rpi-ds18b20-rust --raw) }]"

About

Toy rust program for retrieving temperature data from a DS18B20 sensor

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages