In a previous post (http://l-k.me/J) I described an idea I had to make use of a Raspberry Pi as a local sensor tool on a bee hive, a project I’ve dubbed ‘BeePi’.

Below is a small requirement chart for the projects needs and potential:

Requirement Must Have Would Like To Have Nice To Have
Internal Hive Temp Sensor Yes
External Hive Temp Sensor Yes
XYZ Accelerometer Yes
High Capacity Battery Yes
Solar Charging Battery Charger Yes
WiFi Transmitter Yes
WiFi Hub Yes
3G Connectivity Yes
Hive Disassembly Sensor Yes
RFID Antenna Yes
Weather Station Yes

While all of these could be rolled into a singular project, but it makes sense to break up development into phases based on real world requirements and (of course) money.

A lot of what is required for this project exists in singular projects already published by the Raspberry Pi community, a large following of users are making use of the Maplin USB Weather Station (http://l-k.me/I), GPIO Temperature Sensor(s) (http://l-k.me/K) and RFiD Reader (http://l-k.me/L). The use of a 3G and / or WiFi dongle makes sending data exceptionally easy as the OS will handle any of the connecting to the internet / network leaving any software to make / receive API calls and store the data where appropriate.

The use of the BeePi as a WiFi Hub is also worth considering if you have more than one hive in a location it makes sense to have a singular hub / data collecting server that all of the other BeePi’s connect to. There are many tutorials on the internet that show you how to turn your Raspberry Pi into a WiFi hub and make use of a singular 3G dongle to connect them all to the internet (Or even host the database locally).

After a bit of juggling and budgeting my Phase One build will look like this:

Internal Hive Temp Sensor
External Hive Temp Sensor
XYZ Accelerometer
High Capacity Battery
Solar Charging Battery Charger
USB WiFi Transmitter

I don’t want to host the data from the hive locally (on the BeePi), so I will write a program to gather up the sensor data periodically and then send the data to a database hosted somewhere (more to come on that as it is developed).

I want to capture the internal brood temperature, external atmospheric temperature, XYZ geometry of the hive. The BeePi will be powered by a chunky long life battery which will be maintained by a solar panel. The hive will be connected to my WiFi network via USB WiFi stick.

To aide development and keep phases in line with each other I will design any PCB’s to include the optional bits; RFiD reader, Hive Disassembly Sensor, 3G data stick. So that should I need to add these to my project or as requirements change I don’t have to go back to square one and make a new base-board.

For the sensors I am going to be using; I’ve chosen to keep things simple:

Internal and External Temperature Sensor: DS18B20 3 Pin 1 wire temperature, these are particularly handy and cool as you can connect several to the same GPIO pin but capture data from them all separately via serial interface. The tutorial guide I am using is: (http://l-k.me/K).

XYZ Accelerometer: ADXL345 a simple I2C accelerometer which you connect  via the BeePi’s GPIO Pins (http://l-k.me/M).

Power and Solar: Power will come from a 12V 7AmpHour battery which will be charged via solar panel regulated with a solar charge controller. The board I will design will take 12V and step down to 5V which will be used to power the Raspberry Pi, WiFi and connected devices. The hope is that the battery and sun will maintain the project indefinitely however as this is all theoretical (at time of writing!) I may need A) a bigger battery B) a bigger solar panel C) BOTH.

While you can source all of these components from UK distributors, I HIGHLY recommend looking at eBay and sellers who are based on HK or china as I have found the price difference to be considerable between UK and Asian sellers.

More to come as the project develops!

*FYI this idea is still a concept and needs to be ironed out!*

It’s worth mentioning one of the great technology releases of 2011 / 2012 was the Raspberry PI (www.raspberrypi.org), a credit card sized computer powered by an ARM processor which can run a select few flavours of Linux.

One of the great selling points of the Pi, are it’s GPIO Pins (General Input Output Pins) which allows you to connect up a vast multitude of sensors, lights, relays directly to the Pi and engage with it via the command line or computer program.

As an avid bee keeper I have spent my last few summers tending to a few bee hives, growing up two colonies to hopefully gather up lots of honey for me! (a treat I love!).

At a recent bee keeping event I ran into a man who had developed a bee hive sensor that is able to be placed inside the bee hive to capture a number of different aspects of a bee hive, such as; temperature, hive geometry to name a few. It was a great product but A) well out of my price range and B) not flexible enough to further development.

So I thought to myself, could I make something similar and what would it look like. Well the short answer is yes, and below are the (incomplete) specifications for what I would want my ‘BeePi” to look like and operate.

Project BeePi; An autonomous data gathering tool use to sense, collect and report back on a bee hive and hive surroundings.

It will feature;

Sensors:Hive internal temperature sensor, external temperature sensor, XYZ accelerometer and hive disassembly removal sensor.

Communications: The BeePi can connect via Wifi to a hub, Wifi to a master BeePi (collecting data from a whole apiary) or communicate via a 3G/4G dongle. Potential exists for a RFID based  ‘Check-In & Check-Out’ style system – useful if many people manage the hives in a particular area.

What will these sensors do?

Well, imagine your bee-hive(s) is located in an area where you suspect animals (or people) could knock the bee hive over. Using the accelerometer when the box is turned at an angle (for example being knocked over) the BeePi could send a message (via sms, pre-recorded message or email) with details about the hive, its location and at what time the event occurred.

Using an internal temperature sensor placed close to the cluster of the hive in the brood box it will give you an indication on the current status of your bees, including if the queen is laying and overall health of the hive. Typically happy brood = happy hive.

An external sensor placed close to the enterence the hive will give you an indication on if the bees are flying, as generally lower than 13 – 10c and they will stay inside and keep warm.

Hive disassembly sensor will alert you to when your hive is being dissembled, this could be handy if you believe someone is stealing from your hive and you wish to track times and events.

I believe that this is a valuable idea and project and will document my progress as I develop it further.

 

So more recently I have started to make use of Cloud based systems, VPN’s, Web Services / Servers etc. One of the things I have wanted to build for a while is a portable Router / WiFi hub that can support a VPN connection.

There has recently been a lot of published warnings about people being exposed while surfing the internet at cafes or other public WiFi hot spots.

The idea of this project is to make use of a Raspberry PI, a second Ethernet Dongle, a Wifi Dongle and a VPN connection. One of the Raspberry Pi’s Ethernet sockets plugs into the public internet while the other (and soon to come WiFi Access Point) acts as its own private network, tunneling all data to the internet via a VPN connection.

Below are some of my notes about how I have build a Raspberry PI, VPN secured Router:

Raspberry Pi VPN Router Config

eth0 (on the PI) connected to the internal network
eth1 (USB to Ethernet) connected to the internet / network
tun0 The VPN Tunnel created when the PI connects to the VPN server
wlan0 (Usb to Wifi) Not Configured

Start with a NEW blank image of Raspberry ArmHF from http://www.raspberrypi.org/downloads

The first thing you should do is run:

sudo apt-get update && sudo apt-get install ca-certificates

which will update and upgrade your PI’s base image and also install certificates information

Once all the updates and installs have taken place we need to reboot the pi:

Sudo shutdown now -r

From here we need to configure all the network interfaces 1st
Then configure the VPN, test the vpn, and then install all the packages to make the Pi into a VPN’ed Router

To configure the network interfaces we need to edit the following file:

/etc/network/interfaces to do this we will use nano:

sudo nano /etc/network/interfaces

To keep things flexible and easy to manage we will want the INTERNET facing ethernet socket to be a DHCP Client, remember this is the USB to Ethernet port (eth1). We want the INTERNAL facing Ethernet socket (On the Pi, eth0) to be static and issue out IP addresses to connected computers. When the VPN connection goes live we will link the Eth0 to Tun0 so that all data traffic from Eth0 goes via the VPN connection.

Inside /etc/network/interfaces we need to add the following (removing the old data):


# interfaces(5) file used by ifup(8) and ifdown(8)

auto lo
iface lo inet loopback

#Onboard NIC connecting to the Internal Network
auto eth0
iface eth0 inet static
address 192.168.50.1
netmask 255.255.255.0
network 192.168.50.0
broadcast 192.168.50.255
gateway 192.168.50.1
#USB NIC serving as internet gateway
auto eth1
iface eth1 inet dhcp

Save the file and close the editor, as it stands now, your file has been saved but not loaded. You can load the file by either rebooting the PI or rebooting networking interfaces:

sudo /etc/init.d/networking restart

You can either do this now or in my case, wait and install all packages needed and then give the system a reboot to load everything in one go.
From here we need to install the following tools:

bind9 isc-dhcp-server perl libnet-ssleay-perl openssl openvpn libauthen-pam-perl libpam-runtime libio-pty-perl libdigest-md5-perl apt-show-versions libapt-pkg-perl this is done by:

sudo apt-get install bind9 isc-dhcp-server perl libnet-ssleay-perl openssl openvpn libauthen-pam-perl libpam-runtime libio-pty-perl libdigest-md5-perl apt-show-versions libapt-pkg-perl

Installing the VPN Tunnel:
With OpenVPN installed we can load our provided .OVPN file. This will have been generated (or provided from your VPN provider) by your server and needs to be loaded into:

/etc/openvpn/

In my case, i have the file loaded on an internal webserver so I just issue the commands:

cd /etc/openvpn/

sudo wget http://server.local/files/PI_VPN.ovpn

This downloads the .ovpn file to the directory, now we need to edit the file’s name so that OpenVPN picks it up on the next reload.

sudo mv PI_VPN.ovpn openvpn.conf

Now you need to reboot the VPN Server to pick up the new settings:

sudo /etc/init.d/openvpn restart

Installing the Router section:
Now we need to edit the DHCP server config details so that when users connect to the PI it will issue a DHCP address and resolve DNS Queries.

sudo nano /etc/dhcp/dhcpd.conf

As we want this DHCP server to have command of the IP network we need to make it authoritative, so you need to find and remove the # uncommenting out the following line:

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

Now we need to add a new subnet to the network:

subnet 192.168.50.0 netmask 255.255.255.0 {
range 192.168.50.10 192.168.50.250;
option broadcast-address 192.168.50.255;
option routers 192.168.50.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name “local”;
option domain-name-servers 8.8.8.8, 8.8.4.4;
}

This sets the reference IP range from 192.168.50.10 to 192.168.50.250 – more than enough for a small local network.
The networks domain is called ‘local’ you can also change this to anything you want ie home

Ive also appended the DNS Settings for Google’s Domain servers to this note, this means any DNS lookups perfomed by the PI will resolve against Google and not your ISP. If your using a custom DNS Server this is the place to change the information to reflect this.

Now Save the file and exit.

You can reboot the DHCP Service by typing in:

sudo /etc/init.d/isc-dhcp-server restart

You should recieve two OK messages.

If you have more than one device connected to your (new) internal network you should be able to ping them by typing in:

Ping 192.168.50. 55 (assuming your ping’ing device has an IP of 192.168.50.55) but it wont allow you to connect out to the wider world just yet.

Now we need to edit the IP Tables of the PI, to allow the forwarding of traffic from the VPN gateway into the internal network.

To do this type:

sudo echo 1 > /proc/sys/net/ipv4/ip_forward

which will allow the forwarding of IPV4 IP traffic, we also need to edit:

sudo nano /etc/sysctl.conf

and uncomment out (remove the #) around the line:

# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

Save the file and exit.

Now we need to edit the IP Tables rules to allow for traffic. Type in:

iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

Unfortunately, due to the nature of IP Tables if the PI looses power, it will reset it the IP tables back, loosing all your settings (not handy if you plan on moving the PI about) so we need to now backup and save your new settings.
This is done by saving your IP Tables as a rule file:

sudo iptables-save > /etc/iptables.up.rules

You can call the saved file anything you like, but it helps to keep things organised.
Now we need to create and edit a script to load the IP Tables Rule file:

sudo nano /etc/network/if-pre-up.d/iptables

and insert:

#!/bin/sh
#This script restores iptables upon reboot

iptables-restore < /etc/iptables.up.rules

exit 0

Now we need to edit the ownership & permissions of this file so it will run on boot:

sudo chown root:root /etc/network/if-pre-up.d/iptables && sudo chmod +x /etc/network/if-pre-up.d/iptables && sudo chmod 755 /etc/network/if-pre-up.d/iptables

You should now be able to reboot your PI as much as you like and it will retain all your data settings! (YaY).

Its worth giving your PI a reboot now, Given all the things you have now loaded onto the PI you will need to give it a reboot to get it going properly.