Displaying LM75 Data to the web
Displaying LM75 Data to the web
As a follow on to the LM75 raspbian data logger project this project enables the raspberry pi to display the temperature and trend directly to the web using COSM.
A live link to the Raspberry pi displaying current temperature can be seen here
In order to set this up first we need to register for COSM on their website, then in console click on the + Device feed button it should open a window like this:
Click on the something else icon you should get a screen like this
Select No, I will push data to COSM then click on next and enter your device title in this example I called it Temperature. click on next in Tag’s to create your Feed Id note this down we will need it later
Now in the console window click on the + Datastream icon and enter a data stream ID take note of it you will need it later.
Next click on the keys icon and make an entry in label and click on all access privileges
And you should get a unique key like above.
Now your ready to go back to the raspberry pi you’ll need 3 files,
Firstly modify the LM75.sh to below:
#!/bin/bash
i2cget -y 0 0x48 0x00 w |
awk '{printf("%.1f\n", (a=( \
(("0x"substr($1,5,2)substr($1,3,1))*0.0625)+0.1) \
)>128?a-256:a)}'
And run chmod as below
root@raspberrypi:/home/pi# chmod +x lm75.sh
Next we need to set up a format to COSM call this file blank.json but make sure to replace Temperature with your ID
{
"version":"1.0.0" ,
"datastreams":[
{"id":"Temperature","current_value":"T1"}
]
}
The third and final file we need is called update.sh in this file replace 79483 with your feed ID and ZkuxZqMWfB-HeaiIijZIOlA-EKmSAKxMcHFod3RtVWNUQT0g with your unique key.
#! /bin/bash
while true;
do
temp=$(./lm75.sh)
cat blank.json | sed 's/T1/'$temp'/g' > \
send.json
curl --request PUT \
--data-binary @send.json \
--header "X-ApiKey: ZkuxZqMWfB-HeaiIijZIOlA-EKmSAKxMcHFod3RtVWNUQT0g" \
http://api.cosm.com/v2/feeds/79483
sleep 60
done
Next run the two command below if all is working well your raspberry pi is now sending data to COSM go back there and see if it is receiving the data
root@raspberrypi:/home/pi# chmod +x update.sh
root@raspberrypi:/home/pi# ./update.sh
Displaying to the web the status of the LM75 temperature sensor using Raspbian