-->
Page 1 of 2

WDT Reset using DHT11

PostPosted: Wed Oct 26, 2016 7:48 am
by ChristianG79
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.

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.

Re: WDT Reset using DHT11

PostPosted: Mon Sep 17, 2018 12:48 pm
by Adrianwtf
I’ve got the exact same problem, when i do dht.begin on arduino uno board it works perfectly, but if I run that same line on generic esp8266 board it crashes even without any wifi operations, I can connect to wifi, do everything but when i do anything with the dht22 it crashes. Please someone reply to this

Re: WDT Reset using DHT11

PostPosted: Fri Sep 21, 2018 4:18 pm
by schufti
so somewhere in the initialization of your DHT lib it is probably waiting on sth too long (while loop w/o delay, etc) and therefor not compatible with esp8266 -> wdt.
There are myriads of arduino compatible DHT libs out therer, the one you used on UNO most likely not the most recent and esp8266 compatible.
look here for a recommended one

Re: WDT Reset using DHT11

PostPosted: Wed Oct 17, 2018 1:55 am
by vibhu18
1.Use the same 3.3 v to power DHT 11 because if you are using the DHT module it has internal pull up resistors which makes use of the same voltage that you are giving to its vcc pin. So, it is better to use the same voltage to DHT and to ESP8266

2.DHT 11 is a slow sensor it takes a while to get the values. so it's better to add a small delay before calculating the values of temperature and humidity. the delay should be made using millis().

I had done this before using ESP-01 see herehttps://github.com/vbshightime
or you can use other temperature sensors like SHT 3x, SHT2x, HIH6130 etc. these sensors have I2C compatibility and are musch faster than DHT https://store.ncd.io/product/sht31-humidity-and-temperature-sensor-%C2%B12rh-%C2%B10-3c-i2c-mini-module/