Skip to content

Instantly share code, notes, and snippets.

@glynnbird
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glynnbird/bb0f117baea8aca05639 to your computer and use it in GitHub Desktop.
Save glynnbird/bb0f117baea8aca05639 to your computer and use it in GitHub Desktop.
#!/bin/bash
# find the sensor_id by looking for a suitable device
sensorid=`find /sys/bus/w1/devices/* -type l | grep -o '[0-9]*-.*$' | head -n 1`
# extract temperature from file
filename="/sys/bus/w1/devices/$sensorid/w1_slave"
T=`tail -n 1 "$filename" | grep -o "[0-9]*$"`
# change units to celsius
t=${T:0:2}.${T:2:3}
# get the date & time
unix=`date "+%s"`
d=`date "+%Y-%m-%d %H:%M:%S %Z"`
# turn into JSON
json="{ \"ts\": $unix, \"date\": \"$d\", \"temperature\": $t, \"sensor_id\": \"$sensorid\" }"
# send to CouchDB
curl -X POST -H "Content-Type: application/json" -d "$json" "http://localhost:5984/logger/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment