WDT Reset using DHT11
Posted: Wed Oct 26, 2016 7:48 am
I recently started working on a ESP8266 12E Nodemcu 1.0 and already got it working on my WLAN also sending strings via PHP to a MySQL database on my RPi.
Unfortunately I can't get a DHT (and maybe also other sensors) working.
I always get the WDT reset when adding the dht.begin() within the void setup().
My next step would be to send the sensor data to mysql instead of the static string.
Unfortunately I can't get a DHT (and maybe also other sensors) working.
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <DHT.h>
//DHT
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
//WiFi
const char* ssid = "My Wifi";
const char* password = "My Wifi PW";
IPAddress ip(192,168,1,167);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
//StatusLED
int StatusLED = 13;
int StatusLEDoff = 12;
//Server
char server[] = "192.168.1.166";
//Ethernet Client
WiFiClient client;
void setup(){
//ESP
ESP.wdtDisable();
ESP.wdtEnable(WDTO_8S);
//StatusLED
pinMode(StatusLED, OUTPUT);
digitalWrite(StatusLED, LOW);
pinMode(StatusLEDoff, OUTPUT);
digitalWrite(StatusLEDoff, HIGH);
//Wifi
WiFiSetup();
//DHT11 setup
dht.begin();
}
void WiFiSetup(){
ESP.eraseConfig();
Serial.begin(115200);
Serial.setDebugOutput(true);
delay(10);
WiFi.setOutputPower(0);
WiFi.persistent(false);
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet);
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(StatusLEDoff, HIGH);
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("Connected to ");
Serial.println(ssid);
Serial.println("IP Address");
Serial.println(WiFi.localIP());
}
void loop(){
ESP.wdtFeed();
//WiFi status LED
if (WiFi.status() == WL_CONNECTED)
{
delay(500);
digitalWrite(StatusLED, HIGH);
digitalWrite(StatusLEDoff, LOW);
}
//Serial.println("Hello, Internet");
// Connect to the server
if (client.connect(server, 80)) {
client.print("GET /store.php?");
client.print("testcol1=");
client.print("test123");
client.print("&testcol2=");
client.print("test234");
client.println(" HTTP/1.1"); // Part of the GET request
client.println("Host: 192.168.1.166");
client.println("Connection: close");
client.println(); // Empty line
client.println(); // Empty line
client.stop(); // Closing connection to server
}
else {
// If Arduino can't connect to the server
Serial.println("--> connection failed\n");
}
delay(20000);
}
I always get the WDT reset when adding the dht.begin() within the void setup().
My next step would be to send the sensor data to mysql instead of the static string.