I have problem using ESP32 with ThingSpeak; viceversa, when I use the ESP8266 no problem.
The problem is related to that no any data is published.
I attach the code I am using to push the data:
if (client.connect(serverTS,80)) { // "184.106.153.149" or api.thingspeak.com String postStr = apiKey; postStr +="&field1="; postStr += String(t); postStr += "\r\n\r\n"; client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr.length()); client.print("\n\n"); client.print(postStr); Serial.print("Temperature: "); Serial.print(t); Serial.println("% send to Thingspeak"); } client.stop(); Serial.println("Waiting..."); // thingspeak needs minimum 15 sec delay between updates
Hi Domenico.
Modify your first lines so that you have something as follows.
String postStr = "api_key="; postStr += apiKey; postStr +="&field1="; postStr += String(t); postStr += "\r\n\r\n";
Then, tell me if it works.
Regards,
Sara
Yes, thanks, I tried it unsuccessfully.
I attach the link to monitor the data, best regards.
https://thingspeak.com/channels/80188
Hi Domenico.
Try this code instead:
https://pastebin.com/m3gsfgsv
Replace with your network credentials and the thingspeak Write API key.
As an example, it is publishing a random number. Replace with your sensor readings.
I’ve tried the example and it is working fine.
I hope this helps.
Regards,
Sara