Abhishek
Published

Secure YUN

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

IntermediateFull instructions provided2,433
Secure YUN

Things used in this project

Hardware components

Arduino Yun
Arduino Yun
×1
Seeed Studio Grove - PIR Motion Sensor
×1
Seeed Studio Grove - Base shield
×1

Software apps and online services

AWS SQS (Simple Queue Service)
Amazon Web Services AWS SQS (Simple Queue Service)
Temboo
Temboo
Arduino IDE
Arduino IDE
AWS IoT
Amazon Web Services AWS IoT

Story

Read more

Schematics

Circuit

Diagram

Code

Sketch

Arduino
#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 File

Arduino
/*
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.
*/

Credits

Abhishek

Abhishek

3 projects • 8 followers

Comments