Hi, I'm trying to have my Yun get info from Yahoo.weather using Temboo, parse the data and send it to my emic2 to read out to me in a robot voice. This all works fine when it's connected through usb, but when I connect through wifi it either generates a "board at X.X.X.X is not available" error or it uploads but then nothing happens and no transfer of data seems to be occurring.
emicSerial works fine so I know the problem is in the Serial I'm using for the Temboo connection. Also I've noticed that the Yun over wifi doesn't always appear in my port options, but if it's not there, I just refresh the myYun.local page and then it's fine.
I know that the Leonardo works a little differently with "Serial" so I have tried "Serial1" and creating a new SoftwareSerial. None of them seem to work and only the plain "Serial" version works when connected to usb. What am I doing wrong?
Thanks for the help.
P.S. it might have to do with this part -- while(!Serial); or while(!Serial1.available()); (depending on the version) but that is just spitballin'.
The code I've attached is the version with regular old "Serial" that works when plugged into the usb but not over wifi
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
#include <SoftwareSerial.h>
// the address for which a weather forecast will be retrieved
String ADDRESS_FOR_FORECAST = "Jerusalem, Israel";
int numRuns = 1; // execution count, so that this doesn't run forever
int maxRuns = 4; // max number of times the Yahoo WeatherByAddress Choreo should be run
String sdate;
String stemp;
String scity;
String srise;
String sset;
#define rxPin 10 // Serial input (connects to Emic SOUT)
#define txPin 11 // Serial output (connects to Emic SIN)
#define ledPin 13 // Arduino built-in LED
String botSpeak = "I did not succeed in getting the weather but I have managed to talk"; //string to hold text to be converted to robot speech
// set up a new serial port
SoftwareSerial emicSerial = SoftwareSerial(rxPin, txPin);
void setup() {
// put your setup code here, to run once:
// define pin modes
pinMode(ledPin, OUTPUT);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
emicSerial.begin(9600);
digitalWrite(ledPin, LOW); // turn LED off
emicSerial.print('\n'); // Send a CR in case the system is already up
while (emicSerial.read() != ':'); // When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it
delay(10); // Short delay
emicSerial.flush();
Serial.begin(9600);
// for debugging, wait until a serial console is connected
delay(4000);
while(!Serial);
Bridge.begin();
}
void loop() {
// put your main code here, to run repeatedly:
// while we haven't reached the max number of runs...
if (numRuns < maxRuns) {
// print status
Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "...");
// create a TembooChoreo object to send a Choreo request to Temboo
TembooChoreo GetWeatherByAddressChoreo;
// invoke the Temboo client
GetWeatherByAddressChoreo.begin();
// add your temboo account info
GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT);
GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY_VALUE);
// set the name of the choreo we want to run
GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress");
// set choreo inputs; in this case, the address for which to retrieve weather data
// the Temboo client provides standardized calls to 100+ cloud APIs
GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST);
// add an output filter to extract the name of the city.
GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response");
// add an output filter to extract the current temperature
GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response");
// add an output filter to extract the date and time of the last report.
GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response");
// add an output filter to extract the sunrise time.
GetWeatherByAddressChoreo.addOutputFilter("sunrise", "/rss/channel/yweather:astronomy/@sunrise", "Response");
// add an output filter to extract the sunset time.
GetWeatherByAddressChoreo.addOutputFilter("sunset", "/rss/channel/yweather:astronomy/@sunset", "Response");
// run the choreo
GetWeatherByAddressChoreo.run();
// parse the results and print them to the serial monitor
while(GetWeatherByAddressChoreo.available()) {
// read the name of the next output item
String name = GetWeatherByAddressChoreo.readStringUntil('\x1F');
name.trim(); // use “trim” to get rid of newlines
// read the value of the next output item
String data = GetWeatherByAddressChoreo.readStringUntil('\x1E');
data.trim(); // use “trim” to get rid of newlines
if (name == "date") {
Serial.println(data);
sdate = data;
Serial.println(sdate);
} else if (name == "temperature") {
Serial.println(data);
stemp = data;
Serial.println(stemp);
} else if (name == "city") {
Serial.println(data);
scity = data;
Serial.println(scity);
} else if (name == "sunrise") {
Serial.println(data);
srise = data;
Serial.println(srise);
} else if (name == "sunset") {
Serial.println(data);
sset = data;
Serial.println(sset);
}
}
delay(10000);
botSpeak = "Hello Master. The temperature today, " + sdate + ", in the city of " + scity + " is " + stemp + ". Sunrise is at " + srise + " and sunset is at " + sset + ". Have a pleasant day.";
Serial.println(botSpeak);
if (numRuns >= 3) {
//change language
emicSerial.print('L');
emicSerial.print("0"); //Change to 0 for English, 1 for Castillian Spanish and 2 for Latin Spanish
emicSerial.print('\n');
delay(20);
// Make the robot talk
emicSerial.print('S');
emicSerial.print(botSpeak); // Send the string botSpeak to convert to speech, may need a single or double quotation mark
emicSerial.print('\n');
digitalWrite(ledPin, HIGH); // Turn on LED while Emic is outputting audio
while (emicSerial.read() != ':'); // Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command
digitalWrite(ledPin, LOW);
delay(500); // 1/2 second delay
}
}
}