Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By DinoN
#53549 HI,

power led has been removed. This is actual pic from deep sleep
Image


To make it easier here is the code used:

Code: Select all#include <PietteTech_DHT.h>     //https://github.com/chaeplin/PietteTech_DHT-8266
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager
#include <TimeLib.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WebServer.h>
#include <Wire.h>

#include "Adafruit_BMP085.h"

const unsigned long SLEEP_INTERVAL = 20 * 1000 * 1000; // 20 sec

extern "C" {
  #include "user_interface.h"
}

//DHT22 config
#define DHTPIN 10 // what pin DHT is connected to
#define SENSPWR 12
#define DHTTYPE DHT22 // DHT 11
//declaration
void dht_wrapper(); // must be declared before the lib initialization

// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);

// globals
bool bDHTstarted;       // flag to indicate we started acquisition
bool bmp085_present=true;

// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper() {
  DHT.isrCallback();
}
// BMP Sensor connections
#define I2C_SCL 5      // Barometric Pressure Sensor (BMP085)
#define I2C_SDA 4      // Barometric Pressure Sensor (BMP085)
Adafruit_BMP085 bmp;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// VARIABLE DEFINITIONS

float h = 0;
float t = 0;
byte rtcStore[2];
float   temperature   = 0.0;
float   humidity    = 0.0;

String ClientIP;
String deviceType   = "TEMP";
String NodeID    = "30";
String APIKey     = "some key";
String host   = "some host";
#define SLEEP_TIME 3*60*1000000                    // sleep intervalls in us

//WIFI credentials go here
const char* ssid     = "wlan";
const char* password = "wlanpass";


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void send_data() {

  digitalWrite(SENSPWR, HIGH);
  Serial.println("Sensor should be powered now!");
  String yourdata;

  // Setup BMP085 (i2c)
  delay(500);
  Wire.begin(I2C_SDA, I2C_SCL);
  delay(100);
  if (!bmp.begin()) {
    Serial.println("No BMP085 sensor detected!");
    bmp085_present=false;
  }

  int acquireresult;
  int acquirestatus;
  int repeats = 0;

repeat:   
    delay(500);
    acquireresult = DHT.acquireAndWait(2000);
        if ( acquireresult == 0 ) {
            // get data
            float t = DHT.getCelsius();
            float h = DHT.getHumidity();
            delay(10);
            Serial.println("Read from DHT sensor!");
            temperature = t;
            humidity    = h;
       
            HTTPClient http;
           
              h = h * 100;
              t = t * 100;

              // now read BMP sensor
              float bt,bp;
              if(bmp085_present) {
                Serial.println("Reading BMP sensor!");
                bp = bmp.readPressure();
                bp = bp * 0.1;
              }
              else {
                 bp = 9000;
              }
             
              if (t != -500 && h != -500 && bp != 0)
              {
                  char STRBUff[4];
                  String StrHum;
                  String StrTemp;
                  String StrPres;
           
                  dtostrf(h,4,0,STRBUff);
                  StrHum = STRBUff;
                  dtostrf(t,4,0,STRBUff);
                  StrTemp = STRBUff;
                  dtostrf(bp,4,0,STRBUff);
                  StrPres = STRBUff;
                 
                  Serial.println(StrTemp);
                  Serial.println(StrHum);
                  Serial.println(StrPres);
                 
                  // configure target server and url
                  String url = "/Serv/SendInput?apikey=";
                  url += APIKey;
                  url += "&time=1403200449.87&node=";
                  url += NodeID;
                  url += "&json={1:";
                  url += StrTemp;
                  url += ",2:";
                  url += StrHum;
                  url += ",3:";
                  url += StrPres;
                  url += "}" ;
               
                  String HTTPReq = "http://";
                  HTTPReq += host;
                  HTTPReq += url;
               
                  Serial.println(HTTPReq);
                  http.begin(HTTPReq);
               
                  // start connection and send HTTP header
                  int httpCode = http.GET();
                  if(httpCode) {
                      if(httpCode == 200 && httpCode < 300) {
                        String payload = http.getString();
                        Serial.println("Sent OK");
                      }
                  } else {
                      Serial.println("Send failed!");
                      goto repeat;
                  }
              }
              else
              {
                Serial.println("Failed to read from DHT sensor, h = -5 !");
              }
          } else {
            Serial.println("Failed to read from DHT sensor!");
            if (repeats <= 3)
            {
                repeats = repeats + 1 ;
                digitalWrite(SENSPWR, LOW);
                delay(500);
                digitalWrite(SENSPWR, HIGH);
                delay(1500);
                goto repeat;
            }
          }



          digitalWrite(SENSPWR, LOW);
}


void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.print("WAKE UP: ");
  Serial.println(millis());
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
 
  Serial.print("CONNECT WLAN: ");
  Serial.println(millis());

  pinMode(SENSPWR, OUTPUT);
  delay(100);
 
 
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print("CALLING SEND DATA: ");
  Serial.println(millis());
  send_data();

  Serial.print("GOING FOR DEEP SLEEP AFTER SENDING: ");
  Serial.println(millis());

 
  //ESP.deepSleep(SLEEP_TIME, WAKE_RF_DEFAULT);
  ESP.deepSleep(SLEEP_TIME);
  delay(500);
 
}
User avatar
By schufti
#53555 i guess the grey rectangles should be identified as pull-ups. What value are they?
xpd and rst should not be directly tied together, better use 4k7 with 47k pullups.
User avatar
By DinoN
#53556 HI,

It looks like some libraries have effect on power usage (and I suspect that ESP8266WebServer) is the one.

I cleaned the includes and left only:
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#include <Wire.h>
#include <PietteTech_DHT.h>     //https://github.com/chaeplin/PietteTech_DHT-8266
#include "Adafruit_BMP085.h"


did a flash erase and fresh flashing and suddenly we are in micro Amps territory.

Thanx,
D