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
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ Description
-----------
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.

Multiple sensors support
------------------------
Server supports multiple remote and one local sensor. Sensors configuration: id, name and accuracy are stored in database.
Remote sensor readings are added with http GET call, e.g. http://localhost:8000/addtemp?sensorid=1&temp=12

Files
-----
* load_gpio.sh - bash commands to load kernel modules
* 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_plot.htm - example client front-end showing live temperatures from local sensor (no remote sensors support yet)
* 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
* build_database.sh - shell script to create database schema (also one local and two remote sensors are added)
* build_example_database.sh - schell script to create example database with real world data from the Pi recorded in UK Jan-Feb 2013

Dependencies
------------
Expand Down
14 changes: 12 additions & 2 deletions build_database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
# build_database.sh - create empty temperature database schema for to log temperature in.
#
# Tom Holderness 22/01/2012
sqlite3 piTemps.db 'DROP TABLE temperature_records;'
sqlite3 piTemps.db 'CREATE TABLE temperature_records(unix_time bigint primary key, celsius real);'


echo "Creating sensor_records table"
sqlite3 piTemps.db 'DROP TABLE sensor_records;'
sqlite3 piTemps.db 'CREATE TABLE sensor_records(sensor_id integer primary key, name varchar, celsius_accuracy real);'
echo "Adding config for one local sensor and two remote sensors"
sqlite3 piTemps.db 'INSERT INTO sensor_records(sensor_id, name, celsius_accuracy) VALUES (0, "Local sensor 0 - DS18B20", 0.5);'
sqlite3 piTemps.db 'INSERT INTO sensor_records(sensor_id, name, celsius_accuracy) VALUES (1, "Remote sensor 1", 0.1);'
sqlite3 piTemps.db 'INSERT INTO sensor_records(sensor_id, name, celsius_accuracy) VALUES (2, "Remote sensor 2", 1.5);'

echo "Creating temperature_records table"
sqlite3 piTemps.db 'DROP TABLE temperature_records;'
sqlite3 piTemps.db 'CREATE TABLE temperature_records(id integer primary key autoincrement, sensor_id int, unix_time bigint, celsius real, foreign key(sensor_id) references sensor_records(sensor_id));'
12 changes: 12 additions & 0 deletions build_example_database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
#
# build_example_database.sh - create example temperature database.

DB_FILE=piTemps.db

if [[ -e $DB_FILE ]]; then
echo "Error: $DB_FILE already exists"
exit -1
fi

sqlite3 $DB_FILE < example_database.sql
7,960 changes: 7,960 additions & 0 deletions example_database.sql

Large diffs are not rendered by default.

Binary file removed sample_database.db
Binary file not shown.
Loading