Last active
August 29, 2015 14:06
-
-
Save glynnbird/bb0f117baea8aca05639 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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