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

ESP8266 & NRF24L01 Breadboard Adapter

esp8266 & nrf24L01 on breadboard

You can find several breadboard adapters for ESP8266 WiFi module or nRF24L01+ RF transceiver and also several DIY manuals how to create your own, but I decided to use my new WiFi WSP8266 and NRD24L01 as soon[…]

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

Platforms for IoT Sensor Data

I have several IoT sensors at home and now I came to the point that I would like to introduce some solid platform for storing sensor data and visualizing them. This post summarize all platforms[…]

Continue reading ...