Project tutorial
Secure YUN

Secure YUN

In this project I am trying to use amazon SQS and IOT services with temboo and arduino YUN to detect intruders.

  • 1,544 views
  • 1 comment
  • 12 respects

Components and supplies

Apps and online services

About this project

The project revolves around building a messaging interface for the arduino yun incorporating Amazon AWS services for detecting intruders . For a beginner like me, it was quite difficult to get the AWS quickly. So I relied on the temboo services which are actually very easy to get and learn. It offers choreos from a lot of different services like youtube and khanacademy. Having said that I particularly used it to communicate with the arduino yun. I used the Amazon SQS and IOT services to send messages to my arduino yun which was retrieved on the serial console of the arduino yun. The yun is particularly impressive in this regard. The Yun is very easy to setup and operate.

Parts

Arduino Yun

PIR Motion sensor

Getting started with YUN

Install the Arduino IDE 1.5.4 or later from this link : https://www.arduino.cc/en/Main/Software

Yun can be easily configured to connect to your local network. Connect the new arduino yun to the computer and wait for a minute for the yun to boot. When you first start the Yun, it will create a WiFi network called ArduinoYun-xxx. Connect to this network.

Once you've obtained an IP address, open chrome, and enter http://arduino.local or 192.168.240.1. After a few moments, a web page will appear asking for a password. Enter "arduino" and click the Log In button.

Press configure and in the consequent webpage enter the required details like password and credentials of your wifi network basically the SSID, password and network security type.

Save the changes and reboot.

Configure Temboo

Now connect to your local wifi network and enter http://arduino.local/ to confirm if the arduino is connected to the network. When the arduino is connected move on to the next part temboo : http://www.temboo.com/

Create a temboo user account and login.

In the left side choose the Amazon choreo. In the amazon services choose the SQS services.

Configure AWS SQS

Now move to the AWS IOT page to create a free AWS account. 

http://aws.amazon.com/iot/

Complete the account registration and move to the Security Credentials under the dropdown on your username.

 

 

 

 Download the Key file and save it for future reference.

Change the region on the upper right corner of the AWS account near the username to U.S. East. Among the Services dropdown choose SQS from Application services. Create a new queue. Give your queue a name and ignore the rest of the details. 


Configure AWS IOT (Windows)

Download the AWS-IoT-Arduino-Yún-SDK zip package and extract it from here :

https://s3.amazonaws.com/aws-iot-device-sdk-arduino-yun/AWS-IoT-Arduino-Yun-SDK-latest.zip

Download Putty and WinSCP from 

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html and

http://winscp.net/eng/download.php

Download AWS IOT CA file from here. Move the AWS IOT CA file, private key and certificate into certs folder of the Arduino Yun SDK. With WinSCP upload the certs and aws_iot_mqtt_client.py file to the root directory of Yun. ssh into the yun and execute :

opkg update

opkg install distribute

opkg install python-openssl

easy_install pip

pip install paho_mqtt

Copy the AWS-IOT-ARDUINO-YUN-LIBRARY to the arduino libraries folder in My Documents. Restart the arduino IDE and the examples will appear in the IDE.

Send the Message

In the SendMessage choreo turn on the IOT mode and connect the Arduino Yun to the computer.

In the Send Message choreo choose "Is this choreo triggered by a sensor event?" and choose Digital pin 0 to be the trigger event so that when pin 0 is high the choreo is run and the message is sent. Connect the PIR motion sensor to the Arduino Yun's VCC, GND and D1 of the sensor to pin 0 of the Yun. 

Now fill the Input fields AWSAccessKeyId with the Access key Id and AWSSecretKeyId with the Secret Access Key. Fill the AWSAccountId with your account ID from account settings. For the message body insert "Intruder detected". The QueueName field should be filled with the name of the new queue created in the Configure AWS field. Run the choreo and download the code.

Uploading the Sketch

Download the Sketch and the header file representing your temboo account, make necessary changes and compile. Upload the sketch on the arduino yun .

When any intruder is detected in front of the PIR motion sensor the D1 signal is high, the port 0 is triggered and the choreo is run. Open the serial monitor and you will get the message "Intruder detected".    

For AWS IOT create an instance of the aws_iot_mqtt_client through :

aws_iot_mqtt_client inst1;

Then load the configuration in setup() and connect like :

if((x = inst1.setup(AWS_IOT_CLIENT_ID)) == 0) {

if((x = inst1.config(AWS_IOT_MQTT_HOST, AWS_IOT_MQTT_PORT, AWS_IOT_ROOT_CA_PATH, AWS_IOT_PRIVATE_KEY_PATH, AWS_IOT_CERTIFICATE_PATH)) == 0) {

if((x = inst1.connect()) == 0) {

success_connect = true;

Now subscibe to a topic and then publish messages as in :

myClient.subscribe("topic", 1, msg_callback);

myClient.publish("topic", msg, strlen(msg), 1, false);

In this way the Intruders detected can be monitored from the AWS IOT platform.

Code

SketchArduino
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // Contains Temboo account information   

// The number of times to trigger the action if the condition is met
// We limit this so you won't use all of your Temboo calls while testing
int maxCalls = 10;

// The number of times this Choreo has been run so far in this sketch
int calls = 0;

int inputPin = 0;


void setup() {
  Serial.begin(9600);
  
  // For debugging, wait until the serial console is connected
  delay(4000);
  while(!Serial);
  Bridge.begin();
  
  // Initialize pins
  pinMode(inputPin, INPUT);

  Serial.println("Setup complete.\n");
}

void loop() {
  int sensorValue = digitalRead(inputPin);
  Serial.println("Sensor: " + String(sensorValue));

  if (sensorValue == HIGH) {
    if (calls < maxCalls) {
      Serial.println("\nTriggered! Calling SendMessage Choreo...");
      runSendMessage(sensorValue);
      calls++;
    } else {
      Serial.println("\nTriggered! Skipping to save Temboo calls. Adjust maxCalls as required.");
    }
  }
  delay(250);
}

void runSendMessage(int sensorValue) {
  TembooChoreo SendMessageChoreo;

  // Invoke the Temboo client
  SendMessageChoreo.begin();

  // Set Temboo account credentials
  SendMessageChoreo.setAccountName(TEMBOO_ACCOUNT);
  SendMessageChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
  SendMessageChoreo.setAppKey(TEMBOO_APP_KEY);

  // Identify the Choreo to run
  SendMessageChoreo.setChoreo("/Library/Amazon/SQS/SendMessage");

  // Run the Choreo
  unsigned int returnCode = SendMessageChoreo.run();

  // Read and print the error message
  while (SendMessageChoreo.available()) {
    char c = SendMessageChoreo.read();
    Serial.print(c);
  }
  Serial.println();
  SendMessageChoreo.close();
}
Header FileArduino
/*
IMPORTANT NOTE about TembooAccount.h

TembooAccount.h contains your Temboo account information and must be included
alongside your sketch. To do so, make a new tab in Arduino, call it TembooAccount.h,
and copy this content into it. 
*/

#define TEMBOO_ACCOUNT ""  // Your Temboo account name 
#define TEMBOO_APP_KEY_NAME ""  // Your Temboo app key name
#define TEMBOO_APP_KEY ""  // Your Temboo app key

/* 
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.  
Keeping your account information in a separate file means you can share the 
main .ino file without worrying that you forgot to delete your credentials.
*/

Schematics

Circuit
Diagram
Capture

Comments

Similar projects you might like

Ultrasonic Map-Maker using an Arduino Yun

Project tutorial by Satyavrat Wagle

  • 51,878 views
  • 37 comments
  • 152 respects

Plant Monitoring System using AWS IoT

Project tutorial by CJA3D

  • 30,570 views
  • 6 comments
  • 77 respects

Yun Light

Project tutorial by Tony ZHANG

  • 6,761 views
  • 3 comments
  • 25 respects

Secure Package Delivery Trunk for Your Front Porch

Project tutorial by Castle Locker

  • 2,951 views
  • 1 comment
  • 19 respects

Secure Your Home by a Password

Project tutorial by يمنى السيد ندا

  • 2,347 views
  • 0 comments
  • 3 respects

Create Your First Connected Light using Arduino Yun

Project tutorial by andreareginato

  • 1,379 views
  • 0 comments
  • 0 respects
Add projectSign up / Login