Hello I have been using the WifiEsp to send and receive data from Thingspeak. All is well until I put my http request on the Void Loop() section.
My Goal: I want to receive data every loop not on only on setup. Here is my code
#include <WiFiEsp.h>
#include <WiFiEspClient.h>
#include <SoftwareSerial.h>
SoftwareSerial Serial1(6, 7); // RX, TX
WiFiEspClient client;
int status = WL_IDLE_STATUS;
#define SSID "Benok4G"
#define PASS "password"
char reply;
char server[] = "184.106.153.149";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial1.begin(9600);
WiFi.init(&Serial1);
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(SSID);
// Connect to WPA/WPA2 network
status = WiFi.begin(SSID, PASS);
}
Serial.println("You're connected to the network");
}
void loop() {
Serial.println();
Serial.println("Receiving Data...");
if (client.connect(server, 80)) {
Serial.println("Connected to server");
client.println("GET /channels/344468/fields/3/last?key=ABCDEFGH
HTTP/1.1");
client.println("Host: api.thingspeak.com");
client.println("Connection: close");
client.println();
while (client.available()) {
char c = client.read();
Serial.write(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting from server...");
client.stop();
while(true);
}
}
I can receive the letter "a" properly. However, I want it too loop and give me updated value every loop.
BUT! when I put the code from the void setup() to the the void loop(). I get this error..
Any ideas on how can I loop it without getting the error? I tried adding delays and putting it on another function, still the same. It will only work when I put in inside the void setup()
Thanks!