Instructions Arduino temphum
Temperature and Humidity Sensor Network with Arduino and Ubuntu
Hardware
- PC capable of running Ubuntu 10.10, USB port, ethernet port
- Arduino Duemilanove
(Many
sources, for example Amazon)
- Ethernet shield
- Sensor board: Modern Device SHT21
- 10 pin flat ribbon cable
- Pin header right angle
Project
Enclosure:
Note:
I am not being paid by any of the hardware stores to advertise their
products, I am just saying that that’s where I bought the hardware.
Software Environment
Ubuntu
10.10
Firefox
(version >= 3.6.16)
flot
0.6 (newer version probably works)
Connecting the Arduino with the PC over Ethernet
On
PC:
right-click
on network-manager and select “Edit connections”
or
System-menu,
System->Preferences->Network Connections
Click
on the Wired Tab, click on Add
Note
that the last of the four numbers can be any number between 0 and
255, but the first three have to be the same as the first three
numbers on the Arduino. In my example, I chose 192.168.1.177 as the
address for the Arduino, so the first three numbers for the PC need
to be 192.168.1.
This
connection does not interfere with the Wifi connection, so you can be
connected to the Internet while the Arduino is plugged into the only
ethernet port on a laptop.
Connect
the Arduino to the PC with an Ethernet cable. Modern PC’s do not even
need a cross-over cable, a standard straight-through cable works.
And
you should see the message that indicates that the Arduino and the PC
are now connected.
Testing the connection with a Telnet session
telnet
192.168.1.177
Trying
192.168.1.177...
Connected
to 192.168.1.177.
Escape
character is '^]'.
Request
a temperature value by typing ‘t’ and then the ENTER key:
t
1
Temperature: 72.13
t
2
Temperature: 72.15
t
3
Temperature: 72.17
Request
a humidity value by typing ‘h’ and then the ENTER key:
h
12
Humidity: 63.76
h
13
Humidity: 63.60
h
14
Humidity: 63.57
Source Code
Considered Improvements
Combine the script files into one file
In
order to retrieve a measurement value, a telnet session must be open
to communicate with the Arduino. It would be very inefficient to open
and close a new telnet session for every single value; it is more
efficient to open a telnet session, to retrieve measurement values in
a loop, and to leave the telnet session open until the program
closes. The down side is that it not possible to call a function that
is inside of a loop. This is why I initially wrote two script files:
one with the telnet loop, and one for the JSON format conversion.
Obviously,
it would be nice to call a function that retrieves a measurement
value from the Arduino and have just one script file. One possible
way to deal with the telnet session issue is, instead of opening and
closing a session for every single value, to inquire whether a
session is open, and if not, open one. This should have the added
advantage that if a session was unintentionally closed, it would be
re-opened.
MySQL Database
There
are several advantages to storing the measurement data in a database.
First, when a LAMP software stack is installed (Linux - Apache -
MySQL - PHP), the web page script can issue a JSON request and the
database will generate the data with built-in calls, there is no
longer the need to manually assemble the JSON file. Second, having
the data in a database leads to a somewhat standardized way to access
the data, as opposed to a data file with an arbirtrary format. Third,
it would be fun to learn LAMP, to design a relational database, and
to play with other visualization software that uses databases.
Distributed Architecture
At
this time, the design relies on a server that polls the data from the
Arduino and stores them on the server storage. The web page client
then retrieves the data from the server and plots them.
Alternatively, a client may be able to connect to the Arduino
directly and retrieve the data from the Arduino. In this scenario,
the web page HTML code and Flot Javascript library files could still
be stored on a PC, and the measurement data could be stored on the
ethernet shield’s SD card. There are Ajax libraries for the Arduino
that could hopefully send data in JSON format. A scenario that goes
even further is where the web page itself is generated on the
Arduino, so a client’s HTML request points directly to the Arduino’s
IP address. But how do you store the Flot library on an Arduino?
Source Code Management
Since
this is beginning to look like an ongoing evolving project, with
multiple development branches, so I’ll probably start using a source
code management tool (think version control)
I
have used CVS and Subversion in the past, but git seems to be the new
evolving standard. Linus Torvalds thinks git is not only better than
CVS and subversion, but CVS and subversion are .. well, see for
yourself what he has to say :-)
No comments:
Post a Comment