Stap 5: Uploaden van de code
Nu, is het de tijd code uploaden naar onze WiFi Micro-board. Download de bijgevoegde code schetsen.
- 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. */
Het wijzigen van de referenties in de TembooAccount.h als uw Temboo accountnaam, Temboo App en de App sleutel we in de vorige stap hebt gegenereerd.
Upload de code aan uw RBL WiFi Micro door de stekker in de MK20 USB dongle gebundeld met de kit.