Filter löschen
Filter löschen

sending value of dht sensor using nodemcu

1 Ansicht (letzte 30 Tage)
pranjal gurav
pranjal gurav am 21 Mär. 2020
Beantwortet: Laura Gautschi am 13 Okt. 2020
I am using this code for sending the temperature to my channel but getting nun and did not received any value. plz help
#include <ESP8266WiFi.h>
#include "DHT.h"
String apiWritekey = "KSB45J7R0MLLKF7U"; // replace with your THINGSPEAK WRITEAPI key here
const char* ssid = "vivo"; // your wifi SSID name
const char* password = "20051999" ;// wifi pasword
const char* server = "api.thingspeak.com";
#define DHTPIN 14 // Data Pin of DHT 11 , for NodeMCU D5 GPIO no. is 14
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
//float resolution=3.3/1023;// 3.3 is the supply volt & 1023 is max analog read value
WiFiClient client;
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.disconnect();
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.print("NodeMcu connected to wifi...");
Serial.println(ssid);
Serial.println();
}
void loop() {
//float temp = (analogRead(A0) * resolution) * 100;
float temp = dht.readTemperature();
Serial.println(temp);
if (client.connect(server,80))
{
String tsData = apiWritekey;
tsData +="&field1=";
tsData += String(temp);
tsData += "\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: "+apiWritekey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n"); // the 2 carriage returns indicate closing of Header fields & starting of data
client.print(tsData);
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println("uploaded to Thingspeak server....");
}
client.stop();
Serial.println("Waiting to upload next reading...");
Serial.println();
// thingspeak needs minimum 15 sec delay between updates
delay(15000);
}

Antworten (1)

Laura Gautschi
Laura Gautschi am 13 Okt. 2020
Did you use the correct api key? the WRITE key not the read key.
And is you computer connected to the same wlan as you mentioned in your sketch?

Communitys

Weitere Antworten in  ThingSpeak Community

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by