首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Temboo to Xively

Temboo to Xively
EN

Stack Overflow用户
提问于 2014-03-09 07:28:11
回答 1查看 440关注 0票数 0

因此,在最近收购了Arduino Yun之后,我正在使用Temboo,但是我在通过组合Choreo获取和发布数据时遇到了问题。

我正在使用雅虎GetWeatherByAddress Choreo,并试图将我想要的个人价值张贴到Xively上。我正在使用Xively Write Choreo,并以JSON格式输入FeedData。

到目前为止,我已经成功地一次发布了两个值(湿度和压力)。不幸的是,我想使用更多,并有湿度,温度,WeatherConditions(公平,刮风等)和LDR值读数从一个面包板。所以它每10秒循环一次,读取所有这些值,然后将它们发布到Xively。即使打印到串行监视器,温度值似乎也有问题,如果我有任何比温度值更多的未注释。它也不会完成整个过程(如果成功,则返回Http 200 ),它会发布这些值,然后直接“等待”下一组要检索的值。我在哪里做错了?

代码语言:javascript
复制
      /*
    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
    }
EN

回答 1

Stack Overflow用户

发布于 2014-03-19 22:49:04

我在Temboo工作。我相信我们已经通过Temboo支持解决了这个问题,所以我在这里为子孙后代回答。

通常,如果草图断断续续地工作,而您没有更改任何代码,那么很可能是RAM即将耗尽(这是资源受限设备上的常见问题)。当你的电路板RAM不足时,它会导致Choreo输入数据在你的Yün的32U4侧被覆盖和损坏。你的草图可能正好在RAM限制,这解释了为什么它有时工作,而另一些则不工作,这取决于所涉及的字符串数据量。

您可以释放一些RAM,方法是将未更改的输入(您的Temboo证书、您的Xively证书、您正在搜索的地址、任何其他静态字符串)放入存储在Linino端的设置文件中,如下链接所述:

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

如果这还不能释放足够的内存,您可以通过删除任何不必要的串行或控制台打印语句来释放更多的内存。

希望这将有助于解决您所看到的问题。如果没有,请让我知道,我们将继续调查。

最后,这里有一些关于如何检查草图使用了多少内存的信息:

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

祝你好运,科马克

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22276445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档