Post topics, source code that relate to the Arduino Platform

User avatar
By mchlrv
#80719
schufti wrote:and you don't help us helping YOU.
How do you think we are supposed to find YOUr error without at least knowing the faintest details about YOUr setup and sketch ???

I thought I provided enough information about the setup (as far as it is related to deep sleep) as in includes all my hardware connections for deep sleep.

In case you expected more details about the setup and sketch you can just ask me instead giving such a hostile reply, I'm happy to share it.

Please find my sketch below and if you require more info, just ask, thanks!
Code: Select all#include <ESP8266WiFi.h>
#include <Homey.h>
#include <SimpleDHT.h>

#define PIN_DHT 5

SimpleDHT22 dht22;

unsigned long sleepPreviousMillis = 0;
unsigned long dhtPreviousMillis = 0;
const unsigned long sleepInterval = 20000; //Interval in milliseconds after which the WiFi will sleep
const unsigned long dhtInterval = 2000; //Interval in milliseconds after which the DHT22 sensor will be read

const char* ssid     = "SSID";
const char* password = "SSID_Password";

void wifi() {
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Conneting to: " + String(ssid));
    WiFi.begin(ssid, password);
    uint8_t timeout = 30;
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
      if (timeout < 1) break;
    }
    if (WiFi.status() == WL_CONNECTED) {
      Serial.print("Connected to " + String(ssid) + " (");
      Serial.print(WiFi.localIP());
      Serial.println(")");
    }
  }
}

void toSleep() {
  Serial.println("Going into deep sleep");
  ESP.deepSleep((60e6), WAKE_RF_DEFAULT);
  delay(500);
}

void wakeUp() {
  delay(500);
  Serial.println();
  Serial.println("Waking up from deep sleep");
}

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

  // Wake up
  wakeUp();

  Homey.begin("DHT22 sensor");
  Homey.setClass("sensor");
  Homey.addCapability("measure_humidity");
  Homey.addCapability("measure_temperature");

}

void loop() {
  // Connect to wifi
  wifi();
  Homey.loop();
 
  unsigned long currentMillis = millis();
  // Read the DHT22 sensor and update Homey
  if(currentMillis - dhtPreviousMillis > dhtInterval) {
    dhtPreviousMillis = currentMillis;
    updateSensor();
  }
  // Put WiFi to sleep
  if(currentMillis - sleepPreviousMillis > sleepInterval) {
    sleepPreviousMillis = currentMillis;
    toSleep();
  }
}

void updateSensor() {
  float temperature = 0;
  float humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht22.read2(PIN_DHT, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT22 failed, err="); Serial.println(err);
    return;
  }

  Serial.print((float)temperature); Serial.print(" *C, ");
  Serial.print((float)humidity); Serial.println(" H");

  Homey.setCapabilityValue("measure_temperature", (float) temperature);
  Homey.setCapabilityValue("measure_humidity", (float) humidity);
}
User avatar
By QuickFix
#80722
mchlrv wrote:This unfortunately doesn't help me with this problem.

What schufti meant is that there's not enough data and he cannot compute.
It's a variant on this one:
crystalball.png

In other words: please post sketches, pictures and/or schematics. :idea:

[EDIT]
Oops, missed schufti's reply on the next page. :oops:
You do not have the required permissions to view the files attached to this post.
User avatar
By rudy
#80723 While there was some important information missing he did post more than some people do when asking for help.

My thought was to use a schottky diode in place of the resistors he has tried.