ESP12 Wifi module User interface


  • User can activate WIFI configuration mode with a button external to the case. The button needs to be pressed again to turn off WIFI mode in order to reduce power consumption and preserve battery life.
  • Nestbox device creates a local hotspot (Access Point - AP) to which the user can connect with a laptop.
  • Various parameters of the nestbox are configurable/readable in a web interface, stored on the user's computer.
  • Minimum configurable parameters/readable values:
    • [R/W] Timestamp to be set to current time in UTC seconds
    • [R] Current ADC value
    • [R] Last read Tag ID
    • [R] Current battery voltage
    • [W] Trigger temporary memory flush to SD card
  • Optional:
    • [R/W] Calibration value pairs (ADC value; real weight; temperature)
    • [R] Current temperature
    • [W] Manually turn on/off RFID reader
    • [R] Time since last boot
  • Long term:
    • [R] Download content on SD card

ESP12 <-> MSP430 communication

The wifi module is connected to the main controller by UART, using the MIN Protocol v2.0. It is enough to include the .h and .c file into the Arduino sketch folder.

The protocol definitions are as follows (R=read variable, W=write variable, X=execute action):

Variable Description W/R Length (Bytes) Answer Type Code
Heartbeat R 1 uint8 'H'
Battery R 2 uint16 'B'
UNIX timestamp R/W 4 uint32 'Z'
Current Load Cell Value (raw) R 4 int32 'W'
Last Load Cell Offset (raw) R 4 int32 'O'
Current Load Cell Threshold value (raw) R/W 4 int32 'D'
Last RFID ID value (only the data bits) R 4 int32 'R'
RTC system pause and resume hours/minutes [uint8_t p_hour, uint8_t p_min, uint8_t r_hour, uint8_t r_min] R/W 4 uint32 'S'
Trigger FRAM memory flush to SD card X 1 uint8 'F'
Check if SD card write is finished X 1 uint8 'f'
Trigger load cell tare X 1 uint8 't'
TURN ON Load Cell polling X 1 uint8 'L'
TURN OFF Load Cell polling X 1 uint8 'l'
TURN ON RFID reader X 1 uint8 'I'
TURN OFF RFID reader X 1 uint8 'i'

ESP12 <-> User communication

The user connects to the locally set up access point of the ESP12. It's name shall be Nestbox-XXX where XXX must be a unique value (e.g. depending on the Mac address).

HTTP requests

Setup on ESP12 firmware

First, we create a server instance that listens for HTTP requests on port 80. This is the default port for web servers.

ESP8266WebServer server (80);

Then we setup a DNS server:

// global variable: 
DNSServer dnsServer;
// inside init function:
// start DNS server for a specific domain name
dnsServer.start(DNS_PORT, "www.nestbox.local", apIP);
HTTP Codes

With server.send(HTTP_CODE, “text/plain”, text_variable), we send a response code, HTTP_CODE, which will be 200 most of the time as confirmation. The codes that can be returned from the server are as follows (from the ESP8266 Guide):

Flashing the ESP12

ESP12 module needs to be flashed BEFORE the MSP430, due to the connected ENABLE pin. If the MSP has already been flashed, it needs to be re-flashed with all GPIO's configured as inputs!

Use a USB-Serial converter and build a flashing adapter with two buttons for CTS and DTR. Those pins shall be pulled high for normal operation. Just before flashing, CTS must be pulled low, then DTR low, then DTR high and CTS high again.

Arduino settings are as follows:  Select board NodeMCU 1.0 (ESP-12E Module

The user interface is done via a javascript app: