【问题标题】:Check feed for updates检查提要以获取更新
【发布时间】:2012-07-26 19:29:42
【问题描述】:

我创建了一个 thingspeak 频道(供稿),用于监控 Twitter 流 API。一旦使用我设置的匹配标准发送了一条新推文,我的提要就会更新。我正在编写一个Arduino sketch,当我的提要更新时,它将引脚 13 设置为高一秒钟。我有一个有效的GET 请求,但我不知道如何解析提要并检查它是否收到了新的更新。

作为一个起点,我使用a sketch provided by thingspeak,它旨在检查他们的提要以获取更新,从推文中获取关键字,并根据该关键字更改灯光颜色。我已经修改了大部分草图,从原始草图中删除了与 GE 灯库相关的部分。我的问题是了解循环中需要检查的内容。这是我一直在制作的草图:http://pastebin.com/NP13A2Ht

【问题讨论】:

    标签: get arduino ethernet


    【解决方案1】:

    在循环内部,您有以下内容:

    if (client.available()) {
        char c = client.read();
        Serial.print(c);
    }
    

    这是从 ThingSpeak 读取响应的代码部分。

    您可以使用“while”循环读取更多字符,然后使用“indexOf”测试字符串中的关键字。

    这里是一些示例代码:

    if(client.available() > 0)
    {  
        delay(100); 
    
        String response;
        char charIn;
    
        do {
            charIn = client.read(); // read a char from the buffer
            response += charIn; // append that char to the string response
        } while (client.available() > 0); 
    
        // Check the string if it contains the word "test"
        if (response.indexOf("test") > 0)
        {  
            // Do something!
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多