Paso 5: Cargar el código
Ahora, es el momento para subir el código a nuestra placa WiFi Micro. Descargar los bosquejos de código adjunto.
- Gmail_buddy.ino
#include <WiFi.h>#include <WiFiClient.h>#include <Temboo.h>#include "TembooAccount.h" // Contains Temboo account informationWiFiClient client;// We limit this so you won't use all of your Temboo calls while testing int maxCalls = 50;// The number of times this Choreo has been run so far in this sketch int calls = 0;int outputPin = 7;void setup() { Serial.begin(9600); int wifiStatus = WL_IDLE_STATUS; // Determine if the WiFi Shield is present Serial.print("\n\nShield:"); if (WiFi.status() == WL_NO_SHIELD) { Serial.println("FAIL"); // If there's no WiFi shield, stop here while(true); } Serial.println("OK"); // Try to connect to the local WiFi network while(wifiStatus != WL_CONNECTED) { Serial.print("WiFi:"); wifiStatus = WiFi.begin(WIFI_SSID, WPA_PASSWORD); if (wifiStatus == WL_CONNECTED) { Serial.println("OK"); } else { Serial.println("FAIL"); } delay(5000); } // Initialize pins pinMode(outputPin, OUTPUT); Serial.println("Setup complete.\n"); }void loop() { if (calls < maxCalls) { Serial.println("Calling GetUnreadMail Choreo..."); runGetUnreadMail(); calls++; } else { Serial.println("Skipping to save Temboo calls. Adjust maxCalls as required."); } delay(60000); }void runGetUnreadMail() { TembooChoreo GetUnreadMailChoreo(client); // Set Temboo account credentials GetUnreadMailChoreo.setAccountName(TEMBOO_ACCOUNT); GetUnreadMailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); GetUnreadMailChoreo.setAppKey(TEMBOO_APP_KEY); // Set profile to use for execution GetUnreadMailChoreo.setProfile("GmailProfile"); // Identify the Choreo to run GetUnreadMailChoreo.setChoreo("/Library/Google/Gmail/GetUnreadMail"); // Run the Choreo unsigned int returnCode = GetUnreadMailChoreo.run(); // A return code of zero means everything worked if (returnCode == 0) { while (GetUnreadMailChoreo.available()) { String name = GetUnreadMailChoreo.readStringUntil('\x1F'); name.trim(); String data = GetUnreadMailChoreo.readStringUntil('\x1E'); data.trim(); if (name == "FullCount") { if (data.toInt() >= 1) { digitalWrite(outputPin, HIGH); } else{ digitalWrite(outputPin, LOW); } } } } GetUnreadMailChoreo.close(); }
2. TembooAccount.h
/*IMPORTANT NOTE about TembooAccount.hTembooAccount.h contains your Temboo account information and must be included alongside your sketch. To do so, make a new tab in Energia, call it TembooAccount.h, and copy this content into it. */#define TEMBOO_ACCOUNT "YourAcountNameHere" // Your Temboo account name #define TEMBOO_APP_KEY_NAME "YourAppNameHere" // Your Temboo app name #define TEMBOO_APP_KEY "YourAppKeyHere" // Your Temboo app key#define WIFI_SSID "YourWiFiName" #define WPA_PASSWORD "YourWiFiPassword"/* The same TembooAccount.h file settings can be used for all Temboo 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. */
Cambiar las credenciales en el TembooAccount.h como su Temboo cuenta nombre, Temboo App y la Clave de la aplicación que hemos generado en el paso anterior.
Subir el código a su RBL WiFi Micro enchufándolo en el MK20 USB dongle incluido con el kit.