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

Battery Powered ESP8266 IoT – Door Sensor

I successfully run DHT22 battery ESP8266 temperature/humidity IoT sensor so my next project is a simple IoT Door Sensor. It is up and running and sending a simple event to my HTTP server via wifi[…]

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

Simple Low Voltage Disconnect Circuit for Arduino

I have read several forums regarding the disconnecting the Arduino power from the Lithium Ion battery by itself (measuring the battery voltage and when the low limit is reached the Arduino signal turns off itself).

Continue reading ...