sending value of dht sensor using nodemcu
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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);
}
0 comentarios
Respuestas (1)
Laura Gautschi
el 13 de Oct. de 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?
0 comentarios
Comunidades de usuarios
Más respuestas en ThingSpeak Community
Ver también
Categorías
Más información sobre Read Data from Channel en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!