0
votes

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
Why are you sending all the nodemcu instructions from your Arduino? I mean, why not write a separated code in nodemcu and then just exchange some data with arduino through serial port ?user5510633

1 Answers

0
votes

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

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