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

Main libs used in the sketch:

  • WiFiManager
  • DoubleResetDetector

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

Related Posts

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

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

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