Software apps and online services
When it comes to Internet of Things, Wireless Sensor Nodes are one of the most popular devices. They have small dimensions, low power consumption and may come equipped with lots of sensors, in accordance with one's needs.
We are presenting here our own Wireless Sensor Node solution for both indoor and outdoor monitoring: Sparrow v3. It can be used for temperature, light and relative humidity monitoring, being capable of many years of running if proper duty-cycling and power saving techniques are used.
In order to be able to see the data collected by our WSNs in real time, we used DeviceHub.net. It was very useful to us not only because we could see how the monitored parameters evolved in real time, but it also stored our data for a period long enough to be able to see some trends.
Sparrow v3 is a WSN equipped with three types of sensors: temperature, relative humidity and ambient light. It has an Atmega128RFA1 micro controller, which incorporates a 2.4GHz radio transceiver, compatible with IEEE standard 802.15.4, over which the popular high-level communication protocol ZigBee is implemented. However, ZigBee was not used in our project, although this is possible.
ATmega128RFA1 is an 8-bit architecture micro controller. It has low power consumption (starting from 250nA while in deep sleep and up to 18,6mA when transmitting data), but still offers high computational performance (almost 1MIPS/MHz). On memory terms, it has 16KB of Flash for code download, 4KB of EEPROM and 16KB of RAM. Moreover, ATmega128RFA1 operates at CPU speeds up to 16 MHZ and at voltages between 1.8V and 3.6V.
- Download Arduino
- Download and unzip the patch in a separate folder
- Locate the installation folder of Arduino on your drive (for Windows it's usually Program Files)
- Copy in Arduino\hardware\arduino\cores the contents of the folder sparrow_patch\Arduino\hardware\arduino\cores\sparrow
- Replace the file Arduino\hardware\arduino\boards.txt with sparrow_patch\Arduino\hardware\arduino\boards.txt
- Copy in Arduino\hardware\arduino\variants the folder named sparrow from sparrow_patch\Arduino\hardware\arduino\variants
- Restart the Arduino IDE
After a successful patch, you should be able to select a new board named Sparrow from the Tools>Board menu. Also select the appropriate COM port from the Tools>Port menu.
You're all set up!
The binary will be installed on flash memory through a bootloader. Most probably Sparrow v3 will come with the bootloader already installed, but in case it won't or in case it somehow gets erased, one will need to install it. You can download the bootloader from here.
In order to install the bootloader, a flash programmer will be needed (we used AVRISP mkII). We then installed AtmelStudio and used its built in Flash Programmer utility (Tools→Device Programming in AtmelStudio menu).
Fusebits: EXT 0XFE, HI 0xD0, LO 0xF7
We'll now check that everything is alright with our setup by writing a simple test program that blinks a led on Sparrow:
1. Create a new Arduino IDE project (File→New) and copy the first code snippet from the Code section
2. In Tools→Programmer choose USBasp
3. In Tools→Board select Sparrow
4. From Tools→Serial Port choose the COM port to which the node was connected
5. Compile and upload the binary, using Upload button
There is one more thing that we must take care of before we can start playing with our WSN monitoring project. We'll need a library for reading values from SHT21, our relative humidity and temperature sensor, connected to the micro controller through an I2C interface. You'll need to use the files stored in this archive in the following way:
1. In folder Arduino\libraries create a new folder, named sht21
2. Copy the files from the attached archive in it
After this it will be possible to import sht21.h header into a project and use functiones defined in it, as you'll see in the first part of the Code section below.
NOTE: If Arduino IDE was already started, a restart will be needed.
The topology of our Wireless Sensor Network is a simple one, where a single node is the gateway one and the rest are sending data to it. The gateway node is the only one that is listening for packages, there is no communication between non-gateway nodes.
The gateway waits to receive a complete package from one of the other nodes. This event is represented by interrupt TRX24_RX_END, the received package being parsed in the handler of this interrupt. The gateway writes the parsed data through the serial interface, then waits for the next package.
All non-gateway nodes are duty-cycling, in order to consume as less energy as possible. After each package sending, every non-gateway node enters in a deep sleep state, where all sensors and micro controller peripherals are deactivated. For waking up from this deep sleep state, MAC symbol counter is used together with SCNT_CMP1_vect interrupt. This interrupt is triggered when Symbol Counter Register has the same value as Symbol Counter Output Compare Register, the latter being previously initialized for the sleep period wanted.
You can see below a representation of the topology we've used. Multiple nodes are sending the data they've read from their sensors towards the gateway node, which further sends them through serial interface towards a Raspberry Pi board, on which a DeviceHub mqtt script is running. The Raspberry Pi board may be connected to Internet either by an Ethernet cable or by a Wifi adapter, which is further connecting to a Wifi network. The monitoring project code is presented in the second part of Code section.
In the third part of the Code section you can see the DeviceHub API we've used to monitor the parameters read by our Wireless Sensor Nodes. For simplicity, the code is an example for only one monitoring node. If you'll use multiple nodes you'll need to add sensors / devices on DeviceHub for each of them, then add code in the script for each of them. Of course, you'll also need to add your own PROJECT_ID, DEVICE_UUID and API_KEY, which will be different from the ones shown in the script.