0
votes

So I am using Temboo after recently acquiring a Arduino Yun, however I am having an issue with getting and posting data by combining Choreos.

I am using the Yahoo GetWeatherByAddress Choreo and trying to post the individual values I want to a Xively Feed. I am using the Xively Write Choreo and inputting FeedData in JSON format.

So far I have had some success with posting 2 values (humidity and pressure) at a time. Unfortunately I want to use more than this and have Humidity, Temperature, WeatherConditions(Fair, Windy etc) and a LDR reading from a breadboard. So It loops every 10 seconds, reads all those values and then posts them to Xively. The Temperature value seems to have an issue with even printing to Serial Monitor if I have any more than the Temperature value uncommented. It also doesn't go through with the whole process (returning Http 200 for success) It posts the values and the just goes straight to "waiting" for the next set of values to be retrieved. Where am I going wrong here?

      /*
    YahooWeather

    This example code is in the public domain.
  */

  #include <Bridge.h>
  #include <Temboo.h>
  #include "TembooAccount.h" // contains Temboo account information

  // the address for which a weather forecast will be retrieved
  String ADDRESS_FOR_FORECAST = "Plymouth, United Kingdom";

  int numRuns = 1;   // execution count, so that this doesn't run forever
  int maxRuns = 10;  // max number of times the Yahoo WeatherByAddress Choreo should be run
  String pData;
  String qData;
  String rData;
  String tData;
  String cData;



  void setup() {
    Serial.begin(9600);

    // for debugging, wait until a serial console is connected
    delay(4000);
    while(!Serial);
    Bridge.begin();
    pinMode(A0, INPUT);
    pinMode(13, OUTPUT);


  }

  void loop()
  {
      if (numRuns <= maxRuns) {
      int sensorValue = analogRead(A0);

      if (sensorValue < 100) { 
        digitalWrite(13,HIGH);
        delay(1000);
        digitalWrite(13,LOW);
      }



    // while we haven't reached the max number of runs...


    Serial.println("Sensor value: " + String(sensorValue));  }

      TembooChoreo WriteDataChoreo;

      // Invoke the Temboo client
      WriteDataChoreo.begin();

      // Set Temboo account credentials
      WriteDataChoreo.setAccountName(TEMBOO_ACCOUNT);
      WriteDataChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
      WriteDataChoreo.setAppKey(TEMBOO_APP_KEY);




      // 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);



      // 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("pressure", "/rss/channel/yweather:atmosphere/@pressure", "Response");
         GetWeatherByAddressChoreo.addOutputFilter("humidity", "/rss/channel/yweather:atmosphere/@humidity", "Response");
          GetWeatherByAddressChoreo.addOutputFilter("text", "/rss/channel/item/yweather:condition/@text", "Response");
           // GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response");  //    
      // add an output filter to extract the current temperature





      // add an output filter to extract the date and time of the last report.

      // 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 == "humidity") {

               qData = data;

               Serial.println("The humidity is " + qData);

           }
            else if (name == "temperature") {

             tData = data;

               Serial.println("The temperature is " + tData);

           } 

           else if (name == "pressure") {

               rData = data;

               Serial.println("The pressure is " + rData);

           } 

           else if (name == "text") {


             cData = data;
               Serial.println("The code is " + cData);

           } 


       }

    WriteDataChoreo.addInput("FeedID", "1508368369");
    WriteDataChoreo.addInput("APIKey", "6Z4tvi6jUOC0VhFkgngijR3bZWMXr2NNu1PHl4Js0hHGqE6C");
    // WriteDataChoreo.addInput("FeedData", "{\"version\":\"1.0.0\",\"datastreams\":[ {\"id\" : \"Pressure\",\"current_value\" : \"" + rData + "\"} ,{\"id\" : \"Humidity\",\"current_value\" : \"" + qData + "\"} ,{\"id\" : \"Conditions\",\"current_value\" : \"" + cData + "\"}]}"); 
    WriteDataChoreo.addInput("FeedData", "{\"version\":\"1.0.0\",\"datastreams\":[{\"id\":\"Humidity\",\"current_value\":\""+qData+"\"},{\"id\":\"Pressure\",\"current_value\":\""+rData+"\"},{\"id\":\"Conditions\",\"current_value\":\""+cData+"\"},{\"id\":\"Temp\",\"current_value\":\""+tData+"\"}]}");
     // Identify the Choreo to run




     // Identify the Choreo to run
     WriteDataChoreo.setChoreo("/Library/Xively/ReadWriteData/WriteData");

     // Run the Choreo; when results are available, print them to serial
      WriteDataChoreo.run();

           while(WriteDataChoreo.available()) {
        char c = WriteDataChoreo.read();
        //Serial.print(c);



           }

           while(GetWeatherByAddressChoreo.available()) {
        char c = GetWeatherByAddressChoreo.read();
        //Serial.print(c);



           }
      WriteDataChoreo.close();
      GetWeatherByAddressChoreo.close();

      Serial.println("");
      Serial.println("Waiting...");
      Serial.println("");
      delay(10000); // wait 30 seconds between GetWeatherByAddress calls
    }
1

1 Answers

2
votes

I work at Temboo. I believe we've resolved this issue already via Temboo support, so I'm answering here for posterity.

Generally, if a sketch is working intermittently and you haven't changed any code, then it's likely that you're running out of RAM (a common issue on resource-constrained devices). When your board is out of RAM it causes Choreo input data to get overwritten and corrupted on the 32U4 side of your Yún. Your sketch is probably right at the RAM limit, which explains why it's working sometimes but not others, dependent on the amount of String data involved.

You can free up some RAM by putting the inputs that don't change (your Temboo creds, your Xively creds, the address you're searching for, any other static strings) into settings files that are stored on the Linino side, as described at the link below:

https://temboo.com/arduino/using-settings-files

If that doesn't free enough memory, you can free some more by eliminating any unnecessary Serial or Console print statements.

Hopefully this will help solve the issue you're seeing. Please let me know if it doesn't and we will continue to investigate.

Finally, here's some info on how you can check on how much memory a sketch is using:

http://jeelabs.org/2011/05/22/atmega-memory-use/

Good luck, Cormac