NodeMCU ESP8266 GET request response

1.8k views Asked by At

I'm trying to push data to Thingspeak from my Arduino via ESP8266 with NodeMCU firmware.

I'm successfully sending and posting to Thingspeak, but occasionally a data point will be missed. I want to add a check in my code to confirm the response from the thingspeak server.

I'm trying to understand how to receive the response on the NodeMCU sent from the Thingspeak server.

Here's my code for sending to Thingspeak:

// Create connection to server
ser.println("conn=net.createConnection(net.TCP, 0)");
delay(500);
ser.println("conn:on(\"receive\", function(conn, pl) print(pl) end)");
delay(500);
ser.println("conn:connect(80,\"" + thingServerIP + "\")");
delay(5000);

// Send data
ser.println("conn:send(\"" + getStr + "\")");

// Close connection
delay(5000);
ser.println("conn:close()");

Any advise on how to receive the response?

1

There are 1 answers

0
anon On

ser.println("conn:on(\"receive\", function(conn, pl) print(pl) end)");

replace "print(pl)" with "receivedResponse = pl". the response is now saved in receivedResponse