I've wired my LM35 temperature sensor to my Node MCU ESP8266 12E I've tried to see the data on my serial monitor it works fine, now I want to show data on ThingSpeak I've actually used this code below, created my channel, but the data are not displayed on the chart even if the entries value keep incrementing.
and on the serial monitor I can see that it's connected to the router and it's sending the data to thingspeak
#include <ESP8266WiFi.h>
String apiKey = "myAPIkey";
const char* ssid = "Myroutername";
const char* password = "myrouterpw";
const char* server = "api.thingspeak.com";
float temp = 0;
int analog = 0;
WiFiClient client;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(10);
WiFi.begin(ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED){
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi conected");
}
void loop() {
// put your main code here, to run repeatedly:
analog = analogRead(17);
float temp = analog * 0.2785;
if (client.connect(server,80)){
String postStr = apiKey;
postStr +="&field1=";
postStr += String(temp);
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");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature");
Serial.print(temp);
Serial.println("% send to Thingspeak");
}
client.stop();
Serial.println("waiting...");
delay(20000);
}
Thanks