sending value of dht sensor using nodemcu
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Laura Gautschi
2020-10-13
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 个评论
社区
更多回答在 ThingSpeak Community
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Read Data from Channel 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!