Arduino_Scuola
Published © GPL3+

Simple, Robust M2M Messaging Via Amazon with Temboo

Here we'll show you how to pass short messages and commands to your Arduino Yún via Amazon SQS, a simple cloud-based message queue service.

IntermediateProtip30 minutes1,125
Simple, Robust M2M Messaging Via Amazon with Temboo

Things used in this project

Hardware components

Arduino Yun
Arduino Yun
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Code snippet #1

Arduino
/*
  ReceiveAmazonSQSMessage

  Demonstrates reading a message from an Amazon SQS queue using the Temboo Arduino Yun SDK.
  
  This example code is in the public domain.
*/

#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information, as described below

/*** SUBSTITUTE YOUR VALUES BELOW: ***/

// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.

// your Amazon AWS Access Key ID
const String AWS_ACCESS_KEY_ID = "xxxxxxxxxxxxxxxxx";

// your Amazon AWS Secret Key ID
const String AWS_SECRET_KEY_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

// your Amazon AWS Account ID
const String AWS_ACCOUNT_ID = "xxxxxxxxxxxx";

// your message queue name
const String MESSAGE_QUEUE_NAME = "xxxxxxxxxxxxx";

// the message visibility timeout sets the duration in seconds that a received message
// is hidden from future requests to retrieve messages.It is an optional input that is 
// specified in seconds.
const String VISIBILITY_TIMEOUT = "43200";


void setup() {
  Serial.begin(9600);
  
  // For debugging, wait until a serial console is connected.
  delay(4000);
  while(!Serial);
  Bridge.begin();
}
void loop()
{   
    TembooChoreo ReceiveMessageChoreo;

    // invoke the Temboo client
    ReceiveMessageChoreo.begin();
    
    // set Temboo account credentials
    ReceiveMessageChoreo.setAccountName(TEMBOO_ACCOUNT);
    ReceiveMessageChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    ReceiveMessageChoreo.setAppKey(TEMBOO_APP_KEY);
    
    
    // set choreo inputs
    ReceiveMessageChoreo.addInput("AWSAccountId", AWS_ACCOUNT_ID);
    ReceiveMessageChoreo.addInput("AWSAccessKeyId", AWS_ACCESS_KEY_ID);
    ReceiveMessageChoreo.addInput("AWSSecretKeyId", AWS_SECRET_KEY_ID);
    ReceiveMessageChoreo.addInput("QueueName", MESSAGE_QUEUE_NAME);
    ReceiveMessageChoreo.addInput("VisibilityTimeout", VISIBILITY_TIMEOUT);   
    
    // identify choreo to run
    ReceiveMessageChoreo.setChoreo("/Library/Amazon/SQS/ReceiveMessage");
    
    // set output filters
    ReceiveMessageChoreo.addOutputFilter("messageID", "/ReceiveMessageResponse/ReceiveMessageResult/Message/MessageId", "Response");
    ReceiveMessageChoreo.addOutputFilter("messageText", "/ReceiveMessageResponse/ReceiveMessageResult/Message/Body", "Response");
    
    
    // run the choreo; when results are available, print them to serial
    ReceiveMessageChoreo.run();

    String messageText; 
    String messageID;
    
    while(ReceiveMessageChoreo.available()) {
       // read the name of the next output item
        String name = ReceiveMessageChoreo.readStringUntil('\x1F');
        name.trim(); // use Ã

Credits

Temboo_OFFICIAL

Posted by Arduino_Scuola

Comments