ESP8266 – WiFiManager and EEPROM

ESP8266 WiFiManager EEPROM

My next addition to previous projects battery-wifi-iot-temp-hum-soil-moisture-sensors and battery-powered-esp8266-iot-logger is to make wifi configuration smooth and fast.

I have created 2 prototypes, that utilizes all my sensors, wifimanager, influxDB storage and low power consuption:

Low power Wemos Si7021

Wemos ESP8266 with 4 temp & hum sensors

If successfully connected to the access point, the structure is stored in EEPROM.

  #include <EEPROM.h>
  #define WIFI_CONFIG_ADDRESS 10
  
  struct package {
    char WIFI_SSID[20] = "";
    char WIFI_PASS[20] = "";
    uint8 bssid[6];
    IPAddress ip; //Node static IP
    IPAddress gateway;
    IPAddress subnet;
    uint8 APchannel = 0;
  };
  
  typedef struct package Package;
  Package data;

On every start, ESP tries to start with the stored values:

  EEPROM.begin(sizeof(package) + WIFI_CONFIG_ADDRESS)
  EEPROM.get(WIFI_CONFIG_ADDRESS, data);
  
  IPAddress dns(8, 8, 8, 8); // Google DNS
  WiFi.config(data.ip, dns, data.gateway, data.subnet); // Set static IP config to save time of DHCP
  WiFi.mode(WIFI_STA);
  WiFi.begin(data.WIFI_SSID, data.WIFI_PASS, data.APchannel, data.bssid, true); // static AP BSSID and channel

The version with only Si7021 sensor and Samsung 18650-26f 2600mAh battery was able to transmit 25800 values that should be enough for 1 year to send data every 20min.

Arduino IDE Sketch

Whole sketch: https://gitlab.com/snippets/1853442

Main libs used in the sketch:

  • WiFiManager
  • DoubleResetDetector
  • EEPROM

Sensors libs:

  • SI7021
  • DHTesp
  • BME280I2C

Storage lib:

  • InfluxDb

Next steps

  • Create PCB
  • Make influxdb tags configurable via WifiManager
  • test with various batteries

Other sources

  • You can also check SPIFFS and JSON to save configurations on an ESP8266 in a nice video.
  • Good source of usage of various libs (including SPIFFS storage) thermometer project.
  • For some hints regarding WiFi connection time and static AP MAC address and channel you can check also comments in this reddit post. The WiFi connection time is decreased under 500ms!

PCB under design

Wemos PCB
ESP-01 PCB


Related Posts

Program ATtiny13A via Arduino board

Programming ATtiny micro-controller is quite easy if you have all the needed information in one place. That is the reason to put all needed files, hints in one post so next time I will need it,[…]

Continue reading ...

Programming ESP-01 (ESP8266)

I was inspired by several DIY projects. The ESP8266 WiFi 802.11 b/g/n Module is a self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network. The ESP8266[…]

Continue reading ...

ESP8266 Temperature Humidity IoT Logger

I learned how to program ESP8266 so I created my first temperature IoT ESP8266 project. I used DHT22 as a temperature and humidity sensor and also I did some testing of power consumption using LIGHT SLEEP[…]

Continue reading ...