This is a project for a web-based sensor monitor using Arduino and/or the Nanoshields.
It collects data from sensors and sends it to a server in the local network using an Ethernet Nanoshield (or a regular Arduino Ethernet Shield with the W5100 chip).
This data is stored in a database on the server and is shown, in real time, on a set of gauges when you access a web page. The web server runs in Python, using the Django framework.
These are installation instructions for a simple setup of a web server in your local machine. To create a robust installation, please check the "WARNING" section below.
- Install Python 2.7
- On Windows, download and install this
- On Mac OSX, follow these instructions
- On Linux, follow these instructions
- Install
pip
- On Windows:
- Download and install
setuptools
for Python 2.7 from here - Download and install
pip
from here - Add
C:\Python27
andC:\Python27\Scripts
to your PATH environment variable:- Click Start, start typing "Edit the system environment variables" and open it
- Click "Environment Variables..."
- In "System Variables", select "PATH" and click "Edit..."
- At the end of "Variable value:", add
;C:\Python27\Scripts
and click OK three times
- Download and install
- On Linux or on Mac OSX, you can find the instructions Python installation links above
- On Windows:
- Install Django 1.6
- On Windows:
- Open an administrator command prompt by right-clicking in "Command Prompt" and selecting "Run as Administrator"
- Run
pip install Django
- On Linux of Mac OSX:
- Open the terminal and run
sudo pip install Django
- Open the terminal and run
- On Windows:
- Download the ZIP with all the source code or clone this GIT repository
- Open a command prompt and go to the directory where this README file is, and where manage.py resides
- Run
python manage.py syncdb
- When asked to create a superuser, answer "yes"
- Select a username, e-mail and password of your choice
- Find the IP address of your computer in the local network running
ipconfig
in Windows orifconfig
in Mac or Linux- For the instructions below, we will assume your IP is
192.168.0.10
, so please replace it as needed
- For the instructions below, we will assume your IP is
- Run
python manage.py runserver 192.168.0.10:8000
- On Windows, if a dialog shows up asking for permissions, select "Allow access"
- If needed, allow access to port 8000 in your firewall by adding a rule (or disable the firewall for a quick test, but it's not recommended)
- Open you browser at http://192.168.0.10:8000/admin, and log in using the username and password you created above
- Add the sensors you need, one for each gauge:
- Click in Sensor Types and then Add Sensor Type
- Choose a name: this will show up on top of each gauge
- Choose a code: this will be used in the Arduino code to send data to this gauge
- To make things simple, use only lower case letters, numbers and underscores, e.g.
temp1
orext_temp
- To make things simple, use only lower case letters, numbers and underscores, e.g.
- Choose the maximum and minimum values that are adequate for your sensor
- Choose the sensor units (e.g. "volts", "degrees", etc.): this will be shown right below the gauge value
- Click "Save" and repeat for each sensor you want to add
- Modify the
BasicSensorMonitor
example in thearduino
folder to match the sensors you have:- All you have to do is to populate correctly the string that is sent to the server
- The main line of code that needs to be changed is:
sprintf(params, "voltage1=%d.%02d&voltage2=%d.%02d", DECIMAL(v1, 2), DECIMAL(v2, 2));
- Replace
voltage1
,voltage2
, etc. with the sensor codes you created above - Replace the variables
v1
andv2
with the variables that contain the sensor data in your Arduino code - Adjust the number of decimal places as you need it
- Add more sensors if you need
- Don't forget to increase the
params[]
string size to accommodate your data!
- Upload the Arduino code
- Open you browser at http://192.168.0.10:8000/admin and enjoy!
This is a sample application and is not suitable for a production environment. It offers no authentication or other security mechanisms. If you wish to run it in a secure production environment, here are some recommendations:
- Run it on a physically isolated network if you just need a local application
- Use a proper production deployment for Django instead of the development web server outlined here (there are lots of tutorial for that on the web)
- If you are running it remotely over the web, do so through a secure VPN
- Take care of database size, and create some job to delete old sensor data
- Create proper firewall rules in your server
- This code is provided free of charge, so run it at your own risk!
Copyright (c) 2013 Circuitar
This software is released under an MIT license. See the attached LICENSE file for details.