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

WiFi Energy Monitor

My new project consists of HW with cost under 20€. It is able to accurately measure electric power consumption and sends data via WiFi. Great source of knowledge is openenergymonitor.org which includes also Arduino library.

Continue reading ...

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 ...

Battery Powered Wifi IoT – Temperature, Humidity & Soil Moisture Sensors

I have just made a prototype of ESP8266 (ESP-01) IoT temperature & humidity SI7021 sensor and also 2x three pin soil moisture sensors with only 0.006mA (6µA) current drain during the sleep.

Continue reading ...