Internet of Things in the Public Sector

Today I will talk about you how the Internet of Things can be used in the public sector, and I will show you how reports on pollen levels can be shared with the public in an efficient and fun way using a smart and connected device.

For people who are allergic to pollen (like myself) the periods with high levels can be challenging, and it becomes important to be prepared with medication and other remedies when that happens. Most countries have web sites and even apps to keep track of pollen levels, but they are easily forgotten, so what if there was something that would immediately let you know the current levels in an intuitive way?

Let’s build a device that could be connected to a public API, and to do that, I will use an Arduino Yun with an LED dot matrix display, and to connect everything, you need a breadboard, 8 220 ohm resistors, and 16 jumper wires.

To setup the hardware, you start by disconnecting everything from its power source, and then connect the pins according to this table and diagram.

This is the Arduino code (Sketch) to read a pollen level value from an MQTT broker, and show a corresponding smiley on the dot matrix display…

…and after the initial includes (on lines 1-3), the patterns to show on the dot matrix display are defined (on lines 5-47). The MQTT client object is defined and created (on lines 49-50, and I’m using the sandbox provided by Eclipse, but you can use any MQTT broker), followed by the declaration of two arrays that define the pins for the rows and column on the dot matrix display (on lines 51-52), and then some more variables (on line 53-55). In the setup, I set all the pins as writable (on lines 59-63) and initialize the bridge (on line 64, which allows communication between the microcontroller and the microprocessor). Then I connect the MQTT client to the server (on line 65) and subscribe to the topic (on line 66). I set up a timer that will call the display function every other millisecond (on lines 67-68), and you can get the MsTimer2 library on www.pjrc.com/teensy/td_libs_MsTimer2.html. The eternal loop simply runs the MQTT library loop (on line 73) that checks for publications on the server. When a callback is received, it sets the corresponding pattern (on line 78). The letter “1” select pattern 1 that is the happy smiley that indicates a low pollen level, the letter “2” is the neutral smiley for a medium level, and the letter “3” is the sad smiley that indicates a high pollen level. The display function simply turn on the pixels on the dot matrix display according to the currently selected pattern (on lines 83-89).

With that in place, a server application can publish a pollen level on the MQTT topic, and to simulate that, you can open a terminal and give the command at the top…

curl -X PUT --data-binary "1" http://eclipse.mqttbridge.com/my/pollen/level

…and see how our pollen level indicator changes accordingly. Imagine this device in a nice box and put on the wall at home or in the office where it can be easily seen by everyone.

That’s how the Internet of Things can be used in the public sector.