Hi, I use Temboo with Gmail to get information if I have new email or not. I am using this with an Arduino Yun. It works when I open up my Serial Monitor, but want it to run automatically (I want to connect it to a battery pack later). What do I need to change in my code?
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // Contains Temboo account information
#include <LiquidCrystal.h>
// 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 outputPin = 13;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
Serial.begin(9600);
// For debugging, wait until the serial console is connected
delay(4000);
while(!Serial);
Bridge.begin();
// Initialize pins
pinMode(outputPin, OUTPUT);
pinMode(4, OUTPUT);
Serial.println("Setup complete.\n");
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Loading");
// set the cursor to column 0, line 1
// line 1 is the second row, since counting begins with 0
lcd.setCursor(0, 1);
// print to the second line
lcd.print("Gmail");
}
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(30000);
}
void runGetUnreadMail() {
TembooChoreo GetUnreadMailChoreo;
// Invoke the Temboo client
GetUnreadMailChoreo.begin();
// 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("Gmail");
// 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() > 0) {
digitalWrite(outputPin, HIGH);
digitalWrite(4, LOW);
lcd.clear();
lcd.print("New messages: " + data);
} else {digitalWrite(outputPin, LOW);
digitalWrite(4, HIGH);
lcd.clear();
lcd.print("All read!");
}
}
}
}
GetUnreadMailChoreo.close();
}