0

I created a thingspeak channel (feed) which monitors Twitter streaming API. My feed gets updated once a new tweet is sent out with matching criteria I've set. I working on writing an Arduino sketch which sets pin 13 high for one second when my feed gets updated. I have a working GET request, but I do not know how to parse the feed and check to see if it has received a new update.

As a starting place, I'm using a sketch provided by thingspeak which was designed to check their feed for an update, grab a keyword from the tweet, and change lights colors base on that keyword. I've modified most of the sketch removing the parts associated with GE light library from the original. My issue is understanding what needs to be checked in my loop. Here is the sketch I've been working on: http://pastebin.com/NP13A2Ht.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Justjoe
  • 371
  • 1
  • 4
  • 10

1 Answers1

0

Inside of your loop, you have the following:

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

This is the section of code that reads the response from ThingSpeak.

You can use a "while" loop to read in more characters, then test the string for a keyword using "indexOf".

Here is some sample code:

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!
    }
}
iohans
  • 838
  • 1
  • 7
  • 15