Chat freely about anything...

User avatar
By Bruce Markey
#74621 I have about 10 esp's doing temp/humidity. Nothing complicated, they just read the temp/humid and then send it to a web API I wrote.

They've been randomly not sending data. I manually power cycle them and their fine for a bit. Finally put on up on the bench to see. No error is thrown, they still show on the network but they just don't do anything.

That being said I started to look at the esp's watchdog timers and I'm a bit confused. https://techtutorialsx.com/2017/01/21/e ... functions/ If I'm reading that right the integer send along with wdtEnable doesn't matter. Looks like its about 6 seconds.

So my question, is there a way to set a 30 second or so timer to reset if not reset? Or is there a better way to implement this so they stop hanging.


Code: Select all#include <DHT.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#define DHTTYPE DHT22   // DHT 11


const char* ssid = "HexHome";
const char* password = "xxxxxxxxx";
const char* host = "api.hexhome.int";
const int port = 80;

// DHT Sensor
const int DHTPin = 2;

DHT dht(DHTPin, DHTTYPE);

HTTPClient http;

void setup () {
 
  Serial.begin(115200);
  delay(10);


  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.mode(WIFI_STA);
  WiFi.hostname("LivingRoomESP");
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
 
}
 
void loop() {
 
  if (WiFi.status() == WL_CONNECTED) {
 
    HTTPClient http;  //Declare an object of class HTTPClient

      float h = dht.readHumidity();
      float f = dht.readTemperature(true);

      if (isnan(h) || isnan(f)) {
        Serial.println("Failed to read from Sensor!");     
      }
      else{
        Serial.print("Humidity: ");
        Serial.print(h);
        Serial.print(" %\t Temperature: ");
        Serial.print(f);             
        Serial.println(" *F");
      }

  String url = "/thlog";
    url += "?nodeName=";
    url += "Living_Room";
    url += "&temperature=";
    url += String(f);
    url += "&humidity=";
    url += String(h);

  sendAPI(url);
  }
 
  delay(30000);    //Send a request every 30 seconds
 
}

void sendAPI(String url){
  Serial.print("connecting to ");
  Serial.println(host);
  Serial.print("Requesting URL: ");
  Serial.println(url);
  http.begin(host,port,url);
  int httpCode = http.GET();
    if (httpCode) {
      if (httpCode == 200) {
        String payload = http.getString();
        Serial.println("API response ");
        Serial.println(payload);
      }
    }
  Serial.println("closing connection");
  http.end();
}