Why thingspeak cant receive data from sensor ?

7 Ansichten (letzte 30 Tage)
Cristin Manora
Cristin Manora am 19 Aug. 2021
Bearbeitet: Vinod am 20 Aug. 2021
I made a project with a soil moisture sensor but thingspeak can't receive the measurement data. i am using esp8266 nodemcu. I've also tried via https://api.thingspeak.com/update?api_key=xxxxxxxxxxxxxxxx&field1=0 manually..the result is incoming data.
But not logging in by using esp866.
this is my code :
th#include <ESP8266WiFi.h>
char ssid [] = "Manorangi";
char pw [] = "carpediem";
String apiKey = "xxxxxxxxxxxxxxxx";
char server [] = "api.thingspeak.com";
int soil_sensor = A0;
WiFiClient client;
void setup() {
Serial.begin (115200);
delay (10);
WiFi.begin (ssid, pw);
while (WiFi.status () != WL_CONNECTED)
{
delay (100);
Serial.print ("...");
}
Serial.print ("\n Connect to... ");
Serial.println (ssid);
Serial.print (" IP Address : ");
Serial.print (WiFi.localIP ());
Serial.print ("\n");
}
void loop ()
{
int persenhumid = map (analogRead (soil_sensor),0,1023,100,0);
if (client.connect (server,80))
{
String postStr = apiKey+"&field1="+String(persenhumid)+"\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 ("Kelembaban: ");
Serial.print (persenhumid);
Serial.println ("%");
Serial.print ("Mengirim data ke Thingpeak");
Serial.print ("\n");
}
client.stop ();
Serial.println ("Waiting...");
for (unsigned int i = 0; i< 20 ; i++)
{
delay (1000);
}
}

Antworten (1)

Vinod
Vinod am 19 Aug. 2021
I'd recommend taking a look at the examples in the ThingSpeak library as a starting point for your project.
  1 Kommentar
Christopher Stapels
Christopher Stapels am 19 Aug. 2021
Vinod is right. The library helps you deal with conection issues. In your code, you are also disconnecting too fast.

Melden Sie sich an, um zu kommentieren.

Communitys

Weitere Antworten in  ThingSpeak Community

Kategorien

Mehr zu Read Data from Channel finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by