Hackster is hosting Impact Spotlights: Smart Home. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Smart Home. Stream on Thursday!
bigboystoys13
Published

Trigger IFTTT using 1Sheeld

Use your 1Sheeld to trigger IFTTT.

BeginnerFull instructions provided2,061
Trigger IFTTT using 1Sheeld

Things used in this project

Hardware components

DIYmall Arduino UNO
×1
1Sheeld
1Sheeld
×1

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Code

Untitled file

Arduino
/*

Used "Internet Shield Example" as a starting point.

By using this example, you can get response of certain GET request and
print it all out on the terminal shield 64 bytes by 64 bytes.

*/

#define CUSTOM_SETTINGS
#define INCLUDE_INTERNET_SHIELD
#define INCLUDE_TERMINAL_SHIELD

/* Include 1Sheeld library. */
#include <OneSheeld.h>

/* Create an Http request with 1Sheeld website's url. */
/* It's important to be created here as a global object. */
HttpRequest oneSheeldRequest("https://maker.ifttt.com/trigger/1sheeld-on/with/key/#SECRETKEY#");
/* REPLACE #SECRETKEY# ABOVE WITH YOUR SECRET KEY FROM IFTTT MAKER CHANNEL */

void setup() 
{
  /* Start communication. */
  OneSheeld.begin();
  Terminal.println("Begin 1Sheeld IFTTT Test");
  /* Subscribe to success callback for the request. */
  oneSheeldRequest.setOnSuccess(&onSuccess);
  /* Subscribe to failure callback for the request. */
  oneSheeldRequest.setOnFailure(&onFailure);
  /* Subscribe to start callback for the request. */
  oneSheeldRequest.setOnStart(&onStart);
  /* Subscribe to finish callback for the request. */
  oneSheeldRequest.setOnFinish(&onFinish);
  /* Sunbscribe to setOnNextResponseBytesUpdate to be notified once the bytes is updated in the response object. */
  oneSheeldRequest.getResponse().setOnNextResponseBytesUpdate(&onBytesUpdate);
  /* Subscribe to response errors. */
  oneSheeldRequest.getResponse().setOnError(&onError);
  /* Perform a GET request using the Internet shield. */
  Internet.performGet(oneSheeldRequest);
}

void loop()
{}

void onSuccess(HttpResponse &response)
{
  /* Print out the data on the terminal. */
  Terminal.println(response.getBytes());
  /* Ask for the next 64 bytes. */
  response.getNextBytes();
}

void onFailure(HttpResponse &response)
{
  /* Print out the status code of failure.*/
  Terminal.println(response.getStatusCode());
  /* Print out the data failure.*/
  Terminal.println(response.getBytes());
}

void onStart()
{
}

void onFinish()
{
}

void onBytesUpdate(HttpResponse &response)
{
  /* Print out the data on the terminal. */
  Terminal.println(response.getBytes());
  /* Check if the reponse is sent till the last byte. */
  if(!response.isSentFully())
    {       
      /* Ask for the next 64 bytes. */
      response.getNextBytes();
    }

}

void onError(int errorNumber)
{
  /* Print out error Number.*/
  Terminal.print("Error:");
  switch(errorNumber)
  {
    case INDEX_OUT_OF_BOUNDS: Terminal.println("INDEX_OUT_OF_BOUNDS");break;
    case RESPONSE_CAN_NOT_BE_FOUND: Terminal.println("RESPONSE_CAN_NOT_BE_FOUND");break;
    case HEADER_CAN_NOT_BE_FOUND: Terminal.println("HEADER_CAN_NOT_BE_FOUND");break;
    case NO_ENOUGH_BYTES: Terminal.println("NO_ENOUGH_BYTES");break;
    case REQUEST_HAS_NO_RESPONSE: Terminal.println("REQUEST_HAS_NO_RESPONSE");break;
    case SIZE_OF_REQUEST_CAN_NOT_BE_ZERO: Terminal.println("SIZE_OF_REQUEST_CAN_NOT_BE_ZERO");break;
    case UNSUPPORTED_HTTP_ENTITY: Terminal.println("UNSUPPORTED_HTTP_ENTITY");break;
    case JSON_KEYCHAIN_IS_WRONG: Terminal.println("JSON_KEYCHAIN_IS_WRONG");break;
  }
}

Arduino UNO Code

Credits

bigboystoys13
11 projects • 46 followers
Contact

Comments

Please log in or sign up to comment.