Publishing temperature reading from a DS18B20 1-Wire digital temperature sensor using a Raspberry Pi and node.js
This is a follow up to my previous post detailing how to get temperature readings using a Pi and the DS18B20 digital temperature sensor. For this part I am going to expose the temperature readings via a JSON feed using node.js to serve the response.
On a request for /temperature.json the application reads the contents of w1_slave as utf-8, which is the data of the 1-Wire digital thermometer connected to pin #4. A regex is then used to extract the temperature reading before forming an application/json response for the temperature in both celcius and fahrenheit.
A working example, providing my Pi hasn’t been fried, can be found at http://pi.jam.im:8124/temperature.json.