I have an Arduino project that needs to receive data from ThingSpeak. This is the data that I'm supposed to get.
When the data is "true" it must turn the LED on. I tried this code in hope of getting "true".
void loop() {
Serial.println();
Serial.println("Receiving Trigger Data...");
if (client.connect(server, 80)) {
Serial.println("Connected to server");
client.println("GET /channels/344468/fields/3/last?key=XXXXXXX HTTP/1.1");
client.println("Host: api.thingspeak.com");
client.println("Connection: close");
client.println();
}
while (client.available()) {
reply = client.read();
content.concat(reply);
}
delay(3000);
Serial.println(content);
if(content.indexOf("Content-Length: 4") > 0) {
digitalWrite(ledPin, HIGH);
}
The Serial Monitor gives this reply. I don't see the word "true" being returned at all and I don't also see the content length. I tried putting delays but still I don't receive the "true" or even just the content length. Please help.
client.connected()
to determine whether there is still data coming in (since you are sending the Connection: close header).