フィルターのクリア

sending value of dht sensor using nodemcu

1 回表示 (過去 30 日間)
pranjal gurav
pranjal gurav 2020 年 3 月 21 日
回答済み: Laura Gautschi 2020 年 10 月 13 日
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);
}

回答 (1 件)

Laura Gautschi
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?

コミュニティ

その他の回答  ThingSpeak コミュニティ

カテゴリ

Help Center および File ExchangeRead Data from Channel についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by