This project demonstrates accessing and controlling various components such as LED, Buzzer, Push Button, Temperature Sensor and Light Sensor. This project can be easily extended to home automation. AWS IoT console's MQTT Protocol is used for achieving this. MQTT is a machine to machine messaging protocol widely used in Internet of Things projects. The protocol has MQTT Broker (Server) and MQTT Clients. In our case AWS IoT acts as a secure MQTT Broker and Intel Galileo acts as MQTT Client. MQTT follows publisher-subscriber model. A message published to a topic will be received in all clients which has subscribed to that topic. Hence two-way communication is easily possible with MQTT.
- AWS IoT Console: Amazon Web Services recently launched support for the IoT. It is a very secured platform compared to the other open source and free platfroms. You will have to register your device first and download certificates before publishing the data to the cloud.
- Intel Galileo Gen 2: Galileo is a x86 SoC based embedded development board with Arduino Pin outs. You can use the board as Arduino or use it as embedded Linux platform. It runs Yocto-Linux distribution.
- Grove Starter Kit: Grove is an easy to use learning kit designed for Intel and Arduino boards. It contains ready to use components such as Buzzer, Light Sensor, Relay Module etc. This project will cover few components but the other components can be easily controlled by modifying the source code.
Sparkfun has a very good getting started guide. Connect your galileo board to internet either by using ethernet or WiFi. For WiFi setup you will have to use connmanctl command line. Once you are able to login to the Linux terminal, it is required to download few necessary libraries.
AWS IoT library for node js: Install by tying the command
$ npm install aws-iot-device-sdk
Wiring x86: Install by typing the following commands sequentially:
$ mkdir wiringx86-src
$ cd wiringx86-src
$ curl -O -L http://github.com/emutex/wiring-x86/archive/master.tar.gz
$ tar zxvf master.tar.gz
$ cd wiring-x86-master/
$ sudo python setup.py instal
Create an account in Amazon Webservices and navigate to AWS IoT Console. If you are a new user you will see this page. Click Get Started.
Give a Client or Device name, leave the attributes empty and press Create button.
The thing will be displayed in your dashboard. Click on the thing (intel_galileo in my case). It will load a small window on the right.
Press on Connect a device button. This will guide you to connecting a new device to the thing. This step will generate a public key, private key and certificate for your device.
Since Intel Galileo official Yocto image comes with NodeJS and Python, we will chose our sdk as NodeJS. Now click on Generate Certificate and policy.
Download all the files to your computer and press Confirm & Start Connecting.
The next screen will show you a JSON format of your connecting details. Make a note of it.
Login to Intel Galileo Terminal via SSH. (I am using Putty for SSH and WinSCP for SCP)
Create a new folder for AWS by typing the command:
$ mkdir aws-iot
$ cd aws-iot
Make a folder to place the certificates:
$ mkdir cert
$ cd cert
Using the WinSCP tool move the certifcates downloaded to the folder cert.
Use ls
command in Terminal to verify the certificates are correctly placed. Note that your beginning of your certificate and key name might be different.
In addition to the above certificate and key, we will be also needing a key from Symantec. You can download it using the following command:
$ curl https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem > rootCA.pem
Connecting Intel Galileo to AWS IoT:In this step we will be registering our device to the AWS IoT Console. Download the connectToAWS.js
file to your computer and move to Intel Galileo's aws-iot folder using WinSCP.
Note that you will have to change the name of the certificate, key and region name according to you account.
Run the file using the command
$ node connectToAWS.js
If you have followed all the steps correctly you will see something like this.
Once you have seen the above output press Ctrl+C
to terminate the program.
Go to your AWS IoT Console and select the thing intel_galileo. Press Update Shawdow button. You will find your Intel Galileo's local ip address. Congratulations! You have successfully connected your device to AWS IoT.
This is the fun part of the project. We are going to communicate to and fro between Galileo and AWS.
Connect the Grove shield to the Intel Galileo and make the following connections:
Temperature Sensor --> A0
Light Sensor --> A1
Button --> D2
Buzzer --> D3
LED --> D4
Save the controlThings.py in your aws-iot folder. Make sure you update your certificates and server address. Server address varies depending upon user to user. It can be found here:
Run the program by typing the following command:
$ python controlThings.py
The program will publish temperature and light sensor values to AWS IoT for every 10 seconds. Also it continuously monitors whether the button is pressed. If the button is pressed, message will get published to the AWS.
To view the messages go to AWS IoT Console and click on MQTT Client option.
Enter the client ID and intel_galileo and press connect.
Select Subscribe to topic and enter the topic name things/temp
Repeat the same step for things/light and things/button.
You will be able to see three different tabs for the topics.
And soon for every 10 seconds you will be able to see the temperature and light values getting populated. Also, when you press the button, "button pressed" message will get posted to AWS.
We have achieved communication between Intel Galileo and AWS IoT. Lets see how we can control things connected to Intel Galileo via AWS IoT.
In order to do this you will have to publish messages to necessary topics. In the python you can see that we have subscribe to the topics things/buzzer and things/led.
Select Publish to topic in the AWS IoT console and enter things/buzzer. Enter the message:
{"Period" : 2, "PWM" : 200}
and press publish. You will hear the buzzer sound for two seconds.
Try the following message:
{"Period" : 5, "PWM" : 120}
You will hear the sound for 5 seconds but the sound will be different this time since we have changed the PWM value.
Similarly you can control the LED by posting the message in things/led
Eg: {"Period" : 1, "loopFor" : 10}
This will blink the LED 10 times for every 1 second. Play around by changing these values
Comments