The compute module of Intel called Intel Edison is slightly larger than a SD card. It has an onboard Wi-Fi and Bluetooth, perfect for IoT projects. We can connect to Edison remotely and run commands or access the file system. This gives lots of flexibility to developers via SSH.

Edison can be used with Arduino IDE but to get the most out of it you can use other programming languages like Python, Node.js, C/C++. Intel has its own IDE called Intel XDK IoT edition which makes programming with Edison easy. While setting up the programming environment for Edison you can choose between Arduino IDE, Intel XDK or Eclipse.

Let us create a simple temperature monitor with Edison which will monitor the room temperature and notify us through an email. We will be using AWS Cloud in this project. AWS environment consists of a number of different AWS services providing security, transport, and storage of the sender data produced by your device. All services in AWS are delivered via a rich set of REST APIs. You can use a service programmatically through the APIs or can invoke manually using the console which make AWS Cloud powerful. It also offers numbers of API to speed our development with the language of our choice. Hence I have chosen its Node.Js library to interact with my Edison.

Follow the steps to setup the cloud environment:

Create an account at AWS Cloud.

Create an account at AWS Cloud

Figure 1:
Create an account at AWS Cloud

Sign in to AWS IoT Console https://aws.amazon.com/iot.

Sign in to AWS IoT
Figure 2: Sign in to AWS IoT

Create and attach a thing.

Create and attach thing
Figure 3: Create and attach thing

Generate and download the keys and certificates to make connections.

Certificates to make connections
Figure 4: Certificates to make connections

Set up AWS SNS and create a topic.

Simple notification service
Figure 5: Simple notification service

Create an Email Subscription in SNS and publish the topic.

Email Subscription in SNS
Figure 6: Email Subscription in SNS

In AWS IoT page, Create a Rule from the Resource panel and select “Send message as a push notification (SNS)” from Action dropdown. Create a new Role and add the recently created SNS action.

Create SNS action

Figure 7: Create SNS action

Send message as a push notification (SNS)
Figure 8: Send message as a push notification (SNS)

Create an IAM Role. Enter a User Name as snsReceiver and click Create. Now attach the Policy. From the list select AmazonSNSFullAccess&AmazonIoTFullAccess and click on Attach Policy.

Attach Policy
Figure 9: Attach Policy

Setting up Edison

Flash your Edison and enable WIFI on it.

Enable WIFI
Figure 10: Enable WIFI

Transfer Certificates and key files to Edison.

Key files to Edison
Figure 11: Key files to Edison

Establish a serial connection with Edison and run this command to install the AWS IoT SDK.

npm install aws-iot-device-sdk

Install aws-iot-device-sdk
Figure 12: Install aws-iot-device-sdk

Create a new project in Intel XDK, and paste the code.

Code

  1. varawsIot = require('aws-iot-device-sdk'); //require for awsiot
  2. varmraa = require('mraa'); //require mraa for analog/digital read/write
  3. console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the console
  4. /*
  5. * CONFIGURATION VARIABLES
  6. * To set your AWS credentials, export them to your environment variables.
  7. * Run the following from the Edison command line:
  8. * export AWS_ACCESS_KEY_ID='AKID'
  9. * export AWS_SECRET_ACCESS_KEY='SECRET'
  10. */
  11. // AWS IoT Variables
  12. varmqttPort = 8883;
  13. varrootPath = '/home/root/awscerts/';
  14. varawsRootCACert = "root-CA.pem.crt";
  15. varawsClientCert = "certificate.pem.crt";
  16. varawsClientPrivateKey = "private.pem.key";
  17. vartopicName = "Edison";
  18. varawsClientId = "Edison";
  19. varawsIoTHostAddr = "https://AWVI662RQY269.iot.us-west-2.amazonaws.com";
  20. /*
  21. * Instance AWS variables for use in the application for
  22. * AWS IoT Certificates for secure connection.
  23. */
  24. varprivateKeyPath = rootPath + awsClientPrivateKey;
  25. varclientCertPath = rootPath + awsClientCert;
  26. varrootCAPath = rootPath + awsRootCACert;
  27. /*
  28. *Initializing Device Communication for AWS IoT
  29. */
  30. varmyThingName = 'Edison';
  31. varthingShadows = awsIot.thingShadow({
  32. keyPath: privateKeyPath,
  33. certPath: clientCertPath,
  34. caPath: rootCAPath,
  35. clientId: awsClientId,
  36. region: 'us-west-2'
  37. });
  38. console.log("AWS IoT Device object initialized");
  39. mythingstate = {
  40. "state": {
  41. "reported": {
  42. "ip": "unknown"
  43. }
  44. }
  45. }
  46. varnetworkInterfaces = require( 'os' ).networkInterfaces( );
  47. mythingstate["state"]["reported"]["ip"] = networkInterfaces['wlan0'][0]['address'];
  48. vartemperaturePin = new mraa.Aio(2); //setup access analog input Analog pin #2 (A2)
  49. vartemperatureValue = temperaturePin.read(); //read the value of the analog pin
  50. console.log(temperatureValue); //write the value of the analog pin to the console
  51. // calculate temperature
  52. vartmpVoltage = ((temperatureValue*5.0)/1023.0); // convert analog value to voltage
  53. var temperature = (5.26*Math.pow(tmpVoltage,3))-(27.34*Math.pow(tmpVoltage,2))+(68.87*tmpVoltage)-17.81;
  54. console.log(temperature);
  55. thingShadows.on('connect', function() {
  56. console.log("Connected...");
  57. console.log("Registering...");
  58. thingShadows.register(myThingName );
  59. // An update right away causes a timeout error, so we wait about 2 seconds
  60. setTimeout( function() {
  61. console.log("Updating my IP address...");
  62. clientTokenIP = thingShadows.update(myThingName, mythingstate);
  63. console.log("Update:" + clientTokenIP);
  64. }, 2500 );
  65. // Code below just logs messages for info/debugging
  66. thingShadows.on('status',
  67. function(thingName, stat, clientToken, stateObject) {
  68. console.log('received '+stat+' on '+thingName+': '+
  69. JSON.stringify(stateObject));
  70. });
  71. thingShadows.on('update',
  72. function(thingName, stateObject) {
  73. console.log('received update '+' on '+thingName+': '+
  74. JSON.stringify(stateObject));
  75. });
  76. thingShadows.on('delta',
  77. function(thingName, stateObject) {
  78. console.log('received delta '+' on '+thingName+': '+
  79. JSON.stringify(stateObject));
  80. });
  81. thingShadows.on('timeout',
  82. function(thingName, clientToken) {
  83. console.log('received timeout for '+ clientToken)
  84. });
  85. thingShadows
  86. .on('close', function() {
  87. console.log('close');
  88. });
  89. thingShadows
  90. .on('reconnect', function() {
  91. console.log('reconnect');
  92. });
  93. thingShadows
  94. .on('offline', function() {
  95. console.log('offline');
  96. });
  97. thingShadows
  98. .on('error', function(error) {
  99. console.log('error', error);
  100. });
  101. //Watch for temperature
  102. if(temperature > 35 ){
  103. thingShadows.publish('arn:aws:sns:us-west-2:316723939866:TemperaturAlarm',
  104. 'Your room temperature is greater than 35deg C');
  105. }
  106. });
Enter the credentials.

Connect the temperature sensor to A2 pin of Edison.

Temperature sensor to A2 pin of Edison
Figure 13: Temperature sensor to A2 pin of Edison

Upload and Run the code.

Now you will notice if the temperature exceeds 35 degree Celsius you will receive an Email Notification.

Email Notification
Figure 14: Email Notification

If you are a beginner with Amazon AWS, stay tuned for a detailed article.
Read more articles on Internet of Things (IoT):