This project has
taken a few weeks to come together, not least because of the range of parts I
needed to order.
Plantfriends is a
neat project that allows you to monitor the soil moisture of plants, along with
temperature and humidity. The
information is collected by a raspberry pi base station, which uses a database
to store the data and initates emails when there is a problem. The latest status and summary of each plant
can also be viewed via an Android app on a smartphone.
Sounds
complicated? Well....yes, it was.
The project involved:
- physically building
the circuits for three sensor nodes and the base station (although the latter
is much more simple!)
- programming the
Moteino boards
- setting up the
operating system on the Raspi
- setting up php
server on the Raspi
- creating a
database
- running a python
script on the Raspi to read the incoming data, and populate the database
- setting up an
android app on the phone
- creating some cases for the sensor nodes. In Lego, obviously.
I built one sensor
first to get to grips with how things were supposed to work. As it turned out, the major obstacles were
the various codes, not with the hardware!
The sensor node:
The red board if the moteino; the thing on the left is the soil moisture sensor. The humidity and temp sensor is mounted on the underside of the board. And battery pack as well (4x AA batteries). Oh, yes, the sensor nodes also monitor their own power supply, and can warn once the batteries need changing!
The base unit:
This is just a temporary case for now. Moteino receiver on the right (hanging out the case!). Also added is the switch circuit I added (I'll cover another time in more detail).
The sensor nodes inside the Lego cases, and with the moisture sensor probes in the soil:
Problems and Solutions
Here be techie stuff.
Generally, Dickson's guide was dead easy to follow. Every step of the physical build was photographed and annotated, and pretty much idiot proof.
Programming the Moteino boards took some troubleshooting, as I was using a later model board with a different radio transmitter (the RFM69). This meant some new libraries were needed and a few changes to the basic code as the command lines for using the radio are different. Still, nothing a little Google-Fu couldn't resolve.
Setting up the Raspi raspian OS was easy enough.
Error with ttyAMA0
permission denied
ls -l /dev/ttyAMA0
will show the owner (root) and group.
sudo adduser pi tty
Log back in to take
effect.
Serial device
disconnected
raise
SerialException('device reporst rediness to read but returned no data (device
disconnected?)') serial.serialutil.SerialException: device reports readiness to
read but returned no data (device disconnected?)
Run
ps -ef | grep
tty
If the output looks anything like
root
2522 1 0 06:08 ? 00:00:00 /sbin/getty -L ttyAMA0 115200
vt100
Then you need to disable getty from trying to send data to that port. In
order to use the Raspberry Pi’s serial port, we need to disable getty (the
program that displays login screen) by find this line in file /etc/inittab
T0:23:respawn:/sbin/getty
-L ttyAMA0 115200 vt100
And comment it out by adding # in front of
it
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100)
To prevents the Raspberry
Pi from sending out data to the serial ports when it boots, go to file
/boot/cmdline.txt and find the line and remove it
console=ttyAMA0,115200
kgdboc=ttyAMA0,115200
Reboot the Raspberry Pi
Gmail security for
login
Python script unable
to log into email account.
Database not being
populated despite everything seemingly okay
Avoid using hypens
in the node name.
Add the node info
using the admin.php script!
Check the python
script is running
ps aux
Look for process
with plantfriends.py
Setting the USB
debug on Android phone
I think this took the longest to work out, and I didn't take notes the whole time, but the fun was working out what code was needed!