Part 3 - Bluemix and the Internet of (50000 small) Things: Configuring the Pi software

Edit: To make this much easier, I've added a cheat at the bottom of this posting. I've also corrected a few areas which were incomplete or unclear.


Before tweaking any software, we have to install some basic functionality to allow us access the various pieces of our project, i.e. the sensors and the camera. We will also need some way to send the captured sensor data to Bluemix.

Preparing the Raspberry Pi

The following may seem like a lot of work, but it's really a few straightforward items that you can follow and tick off as you go along. I plan on creating a set of scripts to make it much easier, but they're not ready yet.

The first thing we need to do is make sure everything is up to date by updating the Raspberry operating system:

sudo apt-get update && sudo apt-get upgrade

This shows the list of sources that are checked for updates first:

and then it shows the list of packages for which it has found new versions:


Answer "Y" to install these - here it has to download almost 50MB of files, but if you haven't updated your system in a while, it could be hundreds of megabytes. It's probably a good idea to update no matter how much has to be downloaded since it's likely the latest versions will contain fixes and will provide a more stable platform.

Next we need to make sure that the camera has the software we need. To ensure that the operating system support for the camera is installed, run

sudo raspi-config

This starts the configuration process, which looks like the screenshot below:



Go down to the Enable Camera line as shown here, press enter, tab down to Finish and press enter.

We also want to force the correct loading of various parts of the system. To do this, we have to tell the operating system that we want support for the Dallas One-wire Protocol, which is how the temperature sensors communicate with the Pi. The system also has to recognize the humidity sensors and support video streaming, so change /etc/modules so that it contains:

snd-bcm2835
w1-gpio
w1-therm
bcm2835_v4l2 
i2c-bcm2708
i2c-dev

and add the following lines to the end of /boot/config.txt

# Turn off the camera LED
disable_camera_led=1

# Set 1-wire GPIO pin number
dtoverlay=w1-gpio,gpiopin=4
device_tree=

At this point, the camera and the sensors are actually competing for the GPIO pins, so you need to prevent some parts from being loaded. To do this, add the following to /etc/modprobe.d/raspi-blacklist.conf - if the file doesn't exist, create it:

blacklist snd-soc-pcm512x
blacklist snd-soc-wm8804

Now restart the Pi using:

sudo reboot

When the Pi has restarted, we can add the other software needed to support the sensors and devices:
We also need the DHT22 and DS18B20 nodes for node-RED. Since we have to access the ports as root, we'll install these for root:

sudo mkdir -p /root/.node-red
cd /root/.node-red
sudo npm install --unsafe-perm node-red-contrib-dht-sensor
sudo npm install --unsafe-perm node-red-contrib-ds18b20-sensor
cd ..
sudo chown -R root:root .node-red


Bee Factoid: When you have installed the camera, you can see the bees active at all times of the day and night because bees never sleep, at least not as we consider sleep, although research has shown that they do take very short rests which become more regular as they get older. Since the camera is close to the bees, you can sometimes get a very good close-up of a bee where you can see its eyes clearly. All five of them! Worker bees have three small eyes on the top of the head and two large compound eyes on the sides. A drone's compound eyes are much larger since he has to be able to find and follow a queen in flight.

Verify the installation

Let's now verify that the hardware and software are all working together. To check that the camera is working OK, take a picture and check that the photo file is created correctly:

raspistill -o testpic.png

To check that the WiringPi  library is correctly reading the pins, run:

sudo gpio readall

This should display something like:



The 1-wire protocol is built into the kernel, and this creates these folders where it creates a file called w1_slave in which the status of the sensor is stored. To make sure that your temperature sensors are recognized, type:

ls /sys/bus/w1/devices

and that should display a list of directories similar to:


Note that by convention the ID is actually the inverse of the name without the leading 28-, so that the first device here has the ID of 03A3FA050000

MAC address

Before continuing, we also want to capture one specific piece of information, the MAC address of the network interface. It's easy to find it - type ifconfig, and the MAC address is the piece highlighted in red below:


Simply remove the colons to give a 12 digit hexadecimal address. In this example that would result in an address of FFDCBA987654.

The easy way to install!

I've gathered most of the installation steps into a script, and have enumerated the steps required below - it's a simple checklist:
  • Change /boot/config.txt to contain
# Turn off the camera LED
disable_camera_led=1
# Set 1-wire GPIO pin number
dtoverlay=w1-gpio,gpiopin=4
device_tree=
  • Change /etc/modules to contain the following - the order they appear in the list is important:
snd-bcm2835
w1-gpio
w1-therm
bcm2835_v4l2
i2c-bcm2708
i2c-dev
  • Change /etc/modprobe.d/raspi-blacklist.conf to contain the following - if the file doesn't exist, create it:
blacklist snd-soc-pcm512x
blacklist snd-soc-wm8804
  • Simply run
wget https://github.com/bpmurray/beespi/archive/master.zip
unzip -y master.zip
cd  beespi-master
./setup.sh
sudo reboot

Of course, you still have to verify the installation as described above, but doing it this way is much easier.

 

Next time ...

In the next installment, we'll see how to capture the sensor data and send it to Bluemix.

Comments

  1. Hi Brendan, interesting work!

    My bees had capped swarm cells last weekend, I was lucky to catch that during the regular inspection so did artificial swarm. I wonder if you bees are in the preparation of swarm also? I read there is increase of brood frames temperature when the bees prepare to swarm. Wondering if we can see this in your temperature chart?

    If this works, that would reduce the inspection to the hive, so less interruption to the bees.

    Zheng (Jen)

    ReplyDelete

Post a Comment