This is an example of how you can connect a Linino ONE or an Arduino Yún board running LininoOS to intercommunicate with the Relayr platform.
These boards are like Arduino UNOs which, additionally, run a Linux distribution and are WiFi compatible. Hence, you can export all the existing projects for the Arduino UNO, program them using high-level languages and connect them to the Internet.
Now, with the help of the WunderBar and the Relayr platform, you can use the Linino to develop your projects for the IoT easy as ABC.
Security Alarm
In this project, we connect a motion sensor and an strobe light to different digital inputs of a Linino ONE. Using the PyMata library, we can use Python to talk directly to the Arduino without the need of flashing our program using the Arduino IDE. In the script, the board connects to the Relayr's MQTT server so it can publish the data captured by the motion sensor to the Dashboard and listen to the data sensed by the different WunderBar's modules.
Whoa! That was a a lot of condensed information? Don't worry, I'll try to make it simple.
What will you need?
For this example to work you will need a WunderBar, a Linino ONE or an Arduino YÚN, the last version of the LininoOS, the Python environment and the needed libraries, a working internet connection, a motion sensor, a relay and an strobe light.
First step: Linino configuration
To be sure that the code will work without problems, download and install the last version of the LininoOS. You can find the links to the image and the instructions to do it, here.
(Make yourself sure to download the last version of the binaries, since by the time that I am writing this, the "latest" folder in the repository doesn't point correctly to it.)
After that, you need to upload Firmata in the Arduino part of the board. Firmata is a sort of translator that lets you control the Arduino from the Linux system. To do so, connect via SSH to the Linino and run the following command:
run-avrdude /etc/linino/FirmataSPI.hex
Second step: Install libraries
The LininoOS comes already with Python installed and almost all you need to start coding. But to run our script, at least, you will need to install:
-
PyMata, to control Arduino using Python using Firmata instructions
-
Python Requests (use pip to be sure that you install all dependancies), to handle the HTTP protocol
-
Paho MQTT client, to connect to the Relayr's server
However, be sure that you are able to import all the libraries listed in the script provided.
Third step: Connect your circuit
We want to activate our alarm either by detecting sound or movement. To sense sound we will use the microphone module of the WunderBar while to capture movement we will use a PIR motion sensor connected to the Linino board.
Our motion sensor has three pins: two for power input (at 5V) and one output that activates when it detects movement. So, we will connect it to the Arduino VCC and GND for power and to one DIGITAL pin for sensing.
If the alarm activates, one strobe light will turn on. To do so, we will connect the light to a relay controlled by Arduino. Ours has three pins, so we will use the VCC, GND pins for power and another DIGITAL pin for activation.
And voilà, that's how should it look like:
Last step: Script Set-up
The last thing you need to do to get your board working with your WunderBar is setting in the script your own user credentials, to be able to connect to the server, and the devices IDs, the number that identifies each module, of the sensors you are going to use.
For the Linino to publish we will pretend to be the Grove module, which is designed to provide data from external sensors. Also, we will listen the IR module to activate the alarm; since it is already programmed to control a LED strip sending commands, this will be a good graphical example to see how you can make your board work by sending a command.
You will find this information by clicking the configuration button of the module you are interested in:
And putting it in this lines:
dev_id_grove = 'your grove id here'
dev_id_IR = 'your IR id here'
Finally, to connect to the server, click the configuration button of the WunderBar you want to use and take the "Transmitter ID" and the "Transmitter secret":
And write it here:
client.username_pw_set("Transmitter ID", "Transmitter secret")
Last but not least, you need to put the SSL certificate of the Relayr site in the /home of your Linino:
Run the script and, tada!
Now you should be able to see the information sent from your Linino in the Relayr Dashboard (click the grey dot for the log of the module box you want to see). Also, if you select the LED Strip on the IR box and click ON, you'll power the alarm. To turn it off, well, you know, just click OFF.
BONUS
This tuturial should give you a good starting point to develop you own ideas and develop your own App. But, if you want to see this in action, here I provide you a modified code of the CantTouchThis web App. This version listens to the motion sensor attached to your Linino and to the microphone module of the WunderBar. If someone moves or there is an noise loud enough... the alarm will be triggered!
Just remember to create an App Key and replace the App Id, the token and DeviceID values in the protected.js and alarm.js files with yours.
Comments