Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
*.swp
*.db
*.log
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
PiThermServer
=============

Simple NodeJS server for the DS18B20 digital temperature sensor on the Raspberry Pi.
Simple NodeJS server and SQLite3 logger for the DS18B20 digital temperature sensor on the Raspberry Pi.

Description
-----------
A few lines of code to show my implementation of a NodeJS server for the DS18B20 GPIO temperature sensor on the Raspberry Pi. The sensor is accessed using the w1-gpio and w1-therm kernel modules in the Raspbian distro. The server parses data from the sensor and returns the temperature and a Unix time-stamp in JSON format. A simple front-end is included and served usig node-static, which performs ajax calls to the server and plots temperature in real time using the highcharts JavaScript library.
A NodeJS server for the DS18B20 GPIO temperature sensor on the Raspberry Pi. The sensor is accessed using the w1-gpio and w1-therm kernel modules in the Raspbian distro. The server parses data from the sensor and returns the temperature and a Unix time-stamp in JSON format, this is then written to an SQLite database on the Pi. A simple front-end is included and served using node-static, which performs ajax calls to the server/database and plots temperature in real time or from a time-series, using the highcharts JavaScript library.

Files
-----
* load_gpio.sh - bash commands to load kernel modules
* server.js - NodeJS server, returns temperature as JSON and serves other static files
* temperature_plot.htm - example client front-end
* server.js - NodeJS server, returns temperature as JSON, logs to database and serves other static files
* temperature_plot.htm - example client front-end showing live temperatures
* temperature_log.htm - example client front-end showing time-series from database records
* build_database.sh - shell script to create database schema
* sample_database.db - example database with real world data from the Pi recorded in UK Jan-Feb 2013

Usage
-----
* With sensor attached load kernel modules: sudo load_gpio.sh
* Start server: node server.js
Dependencies
------------
* NodeJS
* SQLite3
* node-sqlite3
* node-static

Install/Setup
-------------
1. Run `npm install` in this directory
2. Run `load_gpio.sh` script as root to load kernel modules for the sensor
3. Run the `build_database.sh` script to create "piTemps.db". Note this wil drop any existing database of the same name in the directory
4. Open "server.js" and edit line 35 to read the serial number of your sensor in /sys/bus.
5. In a terminal run "node server.js" to start the server.
6. Open a web browser on the Pi and go to http://localhost:8000/temperature_plot.htm to see a plot of current temperature. Go to http://localhost:8000/temperature_log.htm to see a plot of logged temperature.

References
----------
http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/temperature/

Screenshots/Images
------------------
<p><a href="http://tomholderness.files.wordpress.com/2013/02/ss_temperatured_db_log.png"><img src="http://tomholderness.files.wordpress.com/2013/02/ss_temperatured_db_log.png" alt="Temperature time-series plot" width="400"></a></p>
<p><a href="http://tomholderness.files.wordpress.com/2013/01/plot1.png"><img src="http://tomholderness.files.wordpress.com/2013/01/plot1.png" alt="Temperature plot" width="400"></a></p>
Screenshot of temperature plot
<p><a href="http://tomholderness.files.wordpress.com/2013/01/pi_temp_sensor_scaled.jpg"><img src="http://tomholderness.files.wordpress.com/2013/01/pi_temp_sensor_scaled.jpg" width="400"></a></p>
Expand Down
34 changes: 30 additions & 4 deletions load_gpio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,42 @@
# load_gpio.sh - Load Raspberry Pi GPIO/therm modules to kernel
#
# Note - this script must be run as root:
# sudo load_gpio_therm_modules.sh
# sudo load_gpio.sh
#
# Tom Holderness 03/01/2013
#
# Ref: http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/temperature

set -e # exit on errors (lazy error checking)

modprobe w1-gpio # load gpio module
modprobe w1-therm # load temperature module
MODULES_FILE="/etc/modules"

exit 0
function processYes {
# new line just to be safe
echo "" >> $MODULES_FILE

if [ $(grep -c "w1-gpio" $MODULES_FILE) == "0" ]; then
echo "w1-gpio" >> $MODULES_FILE
fi

if [ $(grep -c "w1-therm" $MODULES_FILE) == "0" ]; then
echo "w1-therm" >> $MODULES_FILE
fi

echo "All done. "
}

# modprobe w1-gpio # load gpio module
# modprobe w1-therm # load temperature module

echo "Modules loaded for current session."
echo -n "Do you want to add the modules to /etc/modules? [yn]: "

while read answer; do
case "$answer" in
y) processYes; exit 0;;
n) echo "Nothing more to do. "; exit 0;;
*) echo -n "Option invalid. Try again [yn]: ";;
esac
done

33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "PiThermServer",
"version": "0.0.1",
"description": "Simple NodeJS server and SQLite3 logger for the DS18B20 digital temperature sensor on the Raspberry Pi.",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "git://github.com/talltom/PiThermServer.git"
},
"keywords": [
"Raspberry",
"Pi",
"Temperature",
"Server",
"DS18B20",
"GPIO",
"Sensor"
],
"author": "Tom Holderness",
"license": "BSD-2-Clause",
"bugs": {
"url": "https://github.com/talltom/PiThermServer/issues"
},
"homepage": "https://github.com/talltom/PiThermServer",
"dependencies": {
"sqlite3": "~2.1.19",
"node-static": "~0.7.3"
}
}