Esp.deepsleep examples

32 views
Skip to first unread message

Jammoyano

unread,
Apr 27, 2019, 9:50:23 AM4/27/19
to souliss
Hi all !

I've been looking for examples about esp.deepsleep and souliss, but I had no luck.

Has anyone a working example?

I'm building a temperature and humidity solar station with Wemos D1 mini pro (external antenna is mandatory) with bme280.

That's  my code. It works fine without esp.deepsleep (but serial monitor has no output).
So what's wrong?  How could I improve it?

Thanks in advance

/**************************************************************************
    Esp8266 gestionando BME280, a través de Souliss - JAMMOYANO
******************************
*********************************************/

// Let the IDE point to the Souliss framework
#include "SoulissFramework.h"

// Configure the framework
#include "bconf/MCU_ESP8266.h"              // Load the code directly on the ESP8266
#include "conf/DynamicAddressing.h"         // Use dynamically assigned addresses
#include "conf/IPBroadcast.h"

// **** Define the WiFi name and password ****
#define WIFICONF_INSKETCH
#define WiFi_SSID               "xxxxxxx"
#define WiFi_Password           "xxxxxxx"

// Include framework code and libraries
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <SPI.h>
#include <EEPROM.h>
#include <BME280I2C.h>
#include <Wire.h>

/*** All configuration includes should be above this line ***/
#include "Souliss.h"

BME280I2C bme
;

// Definicion slots souliss
#define TEMPERATURE 0            
#define HUMIDITY    2
#define PRESSURE    4
#define BATTERY     6

#define Debug Serial

int bat_read = analogRead(A0);
int bat_val;

void setup() {  
   
Initialize();
    delay
(2000);
   
Serial.begin(115200);
   
Serial.println("BME test!!");
   
while(!Serial) {} // Wait
   
Wire.begin();
   
while(!bme.begin())  {
   
Serial.println("Could not find BME280 sensor!");
    delay
(1000);
   
}

 
WiFi.mode(WIFI_STA);
 
WiFi.begin(WiFi_SSID, WiFi_Password);
 
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
   
Serial.println("Connection Failed! Rebooting...");
    delay
(5000);
    ESP
.restart();
 
}
 
 
Serial.println("Ready");
 
Serial.print("IP address: ");
 
Serial.println(WiFi.localIP());
//******************
   
// Connect to the WiFi network and get an address from DHCP
   
GetIPAddress();
   
SetDynamicAddressing(); //obtener direccion de dynamic address
   
GetAddress();

   
Set_Temperature(TEMPERATURE);
   
Set_Humidity(HUMIDITY);
   
Set_T58(PRESSURE);
   
Set_T55(BATTERY);
}

void loop() {
 
float temp(NAN), hum(NAN), pres(NAN);
  BME280
::TempUnit tempUnit(BME280::TempUnit_Celsius);
  BME280
::PresUnit presUnit(BME280::PresUnit_hPa);
    EXECUTEFAST
() {                    
        UPDATEFAST
();  
       FAST_50ms
()
       
{   // Just process communication as fast as the logics
           
ProcessCommunication();
       
}
       FAST_2110ms
()
       
{
           
Logic_Temperature(TEMPERATURE);
           
Logic_Humidity(HUMIDITY);
           
Logic_T58(PRESSURE);
           
Logic_T55(BATTERY);
       
}
       
// Here we handle here the communication with Android
        FAST_PeerComms
(); //Usar en peers                                      
   
}
    EXECUTESLOW
() {
    UPDATESLOW
();
            SLOW_110s
(){
             
// Get data every 110 seconds  
             
float h = bme.hum();
             
// Get temperature as Celsius
             
float t = bme.temp();
             
//Get atmospheric pressure data
             
float p = bme.pres(presUnit);
             
// Read batt level
             
float bat_read = analogRead(A0); // raw data
             
float bat_val = map (bat_read,0,920, 0, 5); // % from total
           
             
// Check if any reads failed and exit early (to try again).
             
if (isnan(h) || isnan(t) || isnan(p)) {
               
Serial.println("Failed to read from sensor!");
               
//return;
             
}
             
Serial.print("Humidity: ");
             
Serial.print(h);
             
Serial.print(" %\t");
             
Serial.print("Temperature: ");
             
Serial.print(t);
             
Serial.print(" *C ");
             
Serial.print(" \t");
             
Serial.print("Pressure: ");
             
Serial.print(p);
             
Serial.print(" hPa ");
             
Serial.print(" \t");
             
Serial.print("Battery raw: ");
             
Serial.print(bat_read);
             
Serial.print(" volt ");
             
Serial.print(" \t");
             
Serial.print("Battery porc: ");
             
Serial.print(bat_val);
             
Serial.print(" %/t ");
             
Serial.println(" \t");
             
           
Souliss_ImportAnalog(memory_map, TEMPERATURE, &t);
           
Souliss_ImportAnalog(memory_map, HUMIDITY, &h);
           
Souliss_ImportAnalog(memory_map, PRESSURE, &p);
           
Souliss_ImportAnalog(memory_map, BATTERY, &bat_val);
                       
}
           SLOW_50s
(){
           ESP
.deepSleep(5 * 60 * 1000000, WAKE_NO_RFCAL); // deepSleep in microseconds.
           
}
           SLOW_PeerJoin
(); //solo para peers
           
}
           
}


Di Maio, Dario

unread,
May 5, 2019, 6:04:57 AM5/5/19
to sou...@googlegroups.com
Hi,

likely when your node turns on, the Gateway doesn't know that he is up and so it doesn't request data. You should instead publish pbsh() data from your node when it wakes up.

Dario.

--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/souliss/9bc3b1ad-8f83-468e-b600-a302c54fb7a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jammoyano

unread,
May 14, 2019, 3:17:35 AM5/14/19
to souliss
Hi Dario,

Thanks for your answer ... but now I've a new question: How should be used pblsh() function ?

It's the first time I've never heard about it, and I don't really understand this Wiki. (Peer2Peer)

Do you have a working code to learn from ?

To unsubscribe from this group and stop receiving emails from it, send an email to sou...@googlegroups.com.

Di Maio, Dario

unread,
May 17, 2019, 1:56:06 AM5/17/19
to sou...@googlegroups.com
Seach on github for plinioseniore user and you will get my running code, there publish is used.

In few words, is a broadcasted message. The nodes that has a subscribe for that message will do somenthing, what will be done is defined with an if(subscr(MESSAGE)==true) {....}

Dario.

To unsubscribe from this group and stop receiving emails from it, send an email to souliss+unsubscribe@googlegroups.com.

To post to this group, send email to sou...@googlegroups.com.

Jammoyano

unread,
May 19, 2019, 12:21:59 PM5/19/19
to souliss
Hi Dario,

Thanks for your help.

I've updated my code with pblsh() function and now data are send ...  but when node wakes up show 0 as value and a bit later values are shown.

Here's a openhab graph showing:

Captura de pantalla de 2019-05-19 17-55-54.png

It's very annoing watching wrong data and too much vertical lines.

Here's my new code (if there's something wrong please let me know)

Thanks in advance.

/**************************************************************************
    Esp8266 gestionando BME280, a través de Souliss
***************************************************************************/
// Let the IDE point to the Souliss framework
#include "SoulissFramework.h"

// Configure the framework
#include "bconf/MCU_ESP8266.h"              // Load the code directly on the ESP8266
#include "conf/DynamicAddressing.h"         // Use dynamically assigned addresses
#include "conf/IPBroadcast.h"

// **** Define the WiFi name and password ****
#define WIFICONF_INSKETCH
#define WiFi_SSID               "xxxx"
#define WiFi_Password           "xxxx"

// Include framework code and libraries
#include <ESP8266WiFi.h> //OTA
#include <ESP8266mDNS.h> //OTA
#include <WiFiUdp.h> //OTA
#include <SPI.h>
#include <EEPROM.h>
#include <BME280I2C.h>
#include <Wire.h>

// Define broadcast
#define  envio   0xFF01,0x01

/*** All configuration includes should be above this line ***/ 
#include "Souliss.h"

BME280I2C bme;

// Definicion slots souliss
#define TEMPERATURE 0             
#define HUMIDITY    2
#define PRESSURE    4
#define BATTERY     6

#define Debug Serial

int bat_read = analogRead(A0);

void setup() {   
    Initialize();
    Serial.begin(115200);
    delay(2000);    
    Serial.println("BME test!!");
    while(!Serial) {} // Wait
    Wire.begin();
    while(!bme.begin())  {
    Serial.println("Could not find BME280 sensor!");
    delay(1000);
    }

  WiFi.mode(WIFI_STA);
  WiFi.begin(WiFi_SSID, WiFi_Password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }
 
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
//******************
    // Connect to the WiFi network and get an address from DHCP
    GetIPAddress();
    SetDynamicAddressing(); //obtener direccion de dynamic address
    GetAddress();
    //SetAsGateway(myvNet_dhcp);       // Set this node as gateway for SoulissApp  

    Set_Temperature(TEMPERATURE);
    Set_Humidity(HUMIDITY);
    Set_T58(PRESSURE);
    Set_T55(BATTERY);
}

void loop() {
  float temp(NAN), hum(NAN), pres(NAN);
  BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
  BME280::PresUnit presUnit(BME280::PresUnit_hPa);
    EXECUTEFAST() {                    
        UPDATEFAST();  
       FAST_50ms()
        {   // Just process communication as fast as the logics
            ProcessCommunication();
        }
       FAST_2110ms()
        {
           Logic_Temperature(TEMPERATURE);
           Logic_Humidity(HUMIDITY);
           Logic_T58(PRESSURE);
           Logic_T55(BATTERY);
        }
       // Here we handle here the communication with Android
        FAST_PeerComms(); //Usar en peers                                       
    }
    EXECUTESLOW() {
    UPDATESLOW();
            SLOW_50s(){
              // Get temperature and humidity from DHT every 110 seconds  
              float h = bme.hum();
              // Get temperature as Celsius
              float t = bme.temp();
              //Get atmospheric pressure data
              //float pressure = bme280.getPressure(); // pressure in Pa
              float p = bme.pres(presUnit);
              // Read batt level
              float bat_read = analogRead(A0); // raw data
           
              // Check if any reads failed and exit early (to try again).
              if (isnan(h) || isnan(t) || isnan(p)) {
                Serial.println("Failed to read from sensor!");
                //return;
              }
              Serial.print("Humidity: ");
              Serial.print(h);
              Serial.print(" %\t");
              Serial.print("Temperature: ");
              Serial.print(t);
              Serial.print(" *C ");
              Serial.print(" \t");
              Serial.print("Pressure: ");
              Serial.print(p);
              Serial.print(" hPa ");
              Serial.print(" \t");
              Serial.print("Battery raw: ");
              Serial.print(bat_read);
              Serial.print(" volt ");
              Serial.println(" \t");
              
            Souliss_ImportAnalog(memory_map, TEMPERATURE, &t);
            Souliss_ImportAnalog(memory_map, HUMIDITY, &h);
            Souliss_ImportAnalog(memory_map, PRESSURE, &p);
            Souliss_ImportAnalog(memory_map, BATTERY, &bat_read);
            pblsh(envio);
            }
            SLOW_x10s(6){
            ESP.deepSleep(5 * 60 * 1000000, WAKE_NO_RFCAL); // deepSleep time is defined in microseconds. Multiply seconds
            }
           SLOW_PeerJoin(); //solo para peers
           }
       //delay(2000);
      }

Di Maio, Dario

unread,
May 19, 2019, 1:03:46 PM5/19/19
to sou...@googlegroups.com
My apologize but I'm not able to read your mind, I have no idea of what's that chart about and how you got it.

Anyhow, likely you are on the wrong lane, you have to:
1) Have a sleppy node that publish some values, not only a topic
2) Have an always on node listeing on that topic, getting published data into a Typical
3) Having so your data in openhab.

Regards,
Dario.

To unsubscribe from this group and stop receiving emails from it, send an email to souliss+unsubscribe@googlegroups.com.

To post to this group, send email to sou...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages