Hello everyone,
My task aims to show temperature and humidity level using DHT22 temperature sensor. However, after connecting Wifi NodeMCU module and upload it, I am unable to show the ThinkSpeak data. After sending to ThinkSpeak through the output serial monitor, ThinkSpeak data does not detect it and does not show any graphs.
I am using NodeMCU and DHT22 temperature sensor.
Any ideas how to solve this problem?
I will show my Arduino coding here.
Attached a photo of ThinkSpeak graph, that does not detect the coding.
#include <ESP8266WiFi.h>
#include "DHT.h"
#define DHTPIN D2 // Pin D2
#define DHTTYPE DHT22 // DHT 22
// Wi-Fi Settings
const char* ssid = "JM"; // your wireless network name (SSID)
const char* password = "12345678"; // your Wi-Fi network password
DHT dht(DHTPIN, DHTTYPE);
WiFiClient client;
const int channelID = 1241864; // ThingSpeak Settings
String writeAPIKey = "I1KWNDJ4I4MI9GT0"; // write API key for your ThingSpeak Channel
const char* server = "api.thingspeak.com";
void setup()
{
Serial.begin(115200);
delay(10);
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("");
}
void loop() {
if (client.connect(server, 80)) {
// Measure Analog Input (A0)
float h = dht.readHumidity();
float t = dht.readTemperature();
// Construct API request body
String body = "&field1=";
body += String(t);
body += "&field2=";
body += String(h);
client.println("POST /update HTTP/1.1");
client.println("Host: api.thingspeak.com");
client.println("User-Agent: ESP8266 (nothans)/1.0");
client.println("Connection: close");
client.println("X-THINGSPEAKAPIKEY: " + writeAPIKey);
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Content-Length: " + String(body.length()));
client.println("");
client.print(body);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
delay(8000);
}
Thank You!!