问题出在哪里?每次都会触发看门狗复位。我对这种类型的项目有点陌生。在任何地方都找不到解决方案。我在某个地方发现分解延迟值可能会有所帮助。但这对我来说不起作用。
#include <DHT.h> // Including library for dht
#include <ESP8266WiFi.h>
String apiKey = "******"; // Enter your Write API key from ThingSpeak
const char *ssid = "*********"; // replace with your wifi ssid and wpa2 key
const char *pass = "*************";
const char* server = "api.thingspeak.com";
使用引脚 7 作为 DHT22 传感器的输入
#define DHTPIN 7 //pin where the dht22 is connected
DHT dht(DHTPIN, DHT22);
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
这个命令有问题吗?我很困惑
while (WiFi.status() != WL_CONNECTED)
{
delay(50);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\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: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates
delay(200);
}
}
此 ESP 文档 告诉我们,您的应用程序正在由硬件看门狗定时器重置,只有当软件看门狗定时器禁用太长时间时,该定时器才会打开。可能有某种方法可以禁用硬件 WDT,但我目前不知道那是什么。
您应该能够通过启用软件 WDT 并定期维护它来防止这种情况。
#include <Esp.h>
void setup() {
// specifying the timeout isn't currently available
ESP.wdtEnable();
}
void loop() {
// do useful stuff
ESP.wdtFeed(); // service the WDT here
}
我不确定默认的WDT超时是多少,但是代码中的注释表明我们不能指定非默认超时。
Esp.h
在github上
在我的例子中,我只需将
delay(50);
添加到 loop()
方法中,它就会停止重新启动。
ESP8266 Wemos d1r1 板上的相同问题已得到解决
在挣扎 1