User Tools

Site Tools


Home-grown ESP32-based Counter

Configuration of the WiFi credentials

To provision the board with your WiFi credentials a smartphone app is required.

For an iPhone it would be this one, for an Android phone this one

In the app select “Provision Device”, next “I don't have a QR code”, if there comes a dialog to select the device type choose “BLE”. Although you won't use the camera it seems to be required to allow the app to use the camera, otherwise it won't even display the “I don't have a QR code” option.

When the device is in provisioning mode (before the first provisioning or when you set the below mentioned jumper) it will be found now, select it (I expect a name beginning with “PROV_”).

Enter abcd1234 as “proof of possession PIN” (it is prefilled for me).

Now the device will scan available WiFis. Select one and enter the credentials. Usually there will be a message of success in the app but I also saw the case that this message will not come although the provisioning was successful and the device connects to WiFi.

Although prepare in the firmware I forgot to put the pin for the forced reprovisioning on a header on the PCB. So, I've added a quick-fix just in case it is needed to change the WiFi credentials for some reason.

Initial Preparation of a Device for Shipment

The paragraph is not to be performed by users of the device. It is just a note to myself - and for your curiosity.

The below image shows the device connected for downloading firmware and configuration.

(Connect the RXD line of the FTDI cable (yellow) to the TX pin of the board and the TXD line (orange) to the RX pin.)

Firmware Upload

  • Load the development environment using . ~/esp/esp-idf/
  • Make sure to set the program mode jumper and connect the FTDI cable according to the photo below
  • Reset the device
  • Use the tool from the above mentioned project mains-frequency-counter-esp32

Configuration Preparation and Upload

  • Prepare a configuration image using a CSV file like this
  • Make sure the shared secret has exactly 31 characters, use only upper and lower case letters and digits.
  • Run the command
 ~/esp/esp-idf/components/nvs_flash/nvs_partition_generator/ generate --version 1 config.csv config.bin 0x6000
  • Upload the configuration image into the device (still in program mode) using the command
 esptool -p /dev/ttyUSB0 write_flash 0x9000 config.bin

First Start

  • Remove the program mode jumper
  • cd into src directory and use the following command to start the serial device monitor -p /dev/ttyUSB0 monitor
  • Reset the device and observe the output of the serial device monitor, look for a line beginning with
 I (692) ss: finally deviceId: aabbccddeeff
  • The number in the beginning of the line may be different, the code in the end is the MAC address of the device, which is also used as deviceid in the data packets

Prepare database

  • Enter a device entry in the mainscnt database using
 INSERT INTO device_t (deviceid, sharedsecret, location, active) 
   VALUES('aabbccddeeff', '0123456789012345678901234567890', 'XXXX_XX', false);
  • Make sure to use the correct device id (read from monitor output) and shared secret (taken from configuration image). Set the location according to the future deployment location.

WiFi Test

  • Provision the WiFi credentials as described above
  • Observe in the monitor whether the device connects to the WiFi and synchronizes to the NTP server
  • Observe whether the device sends data to the sink server after above two minutes and whether this data is received at the sink server
  • If everything is fine, put the device in program mode again, reset it, upload the configuration again. This will overwrite the test WiFi credentials and puts the device in provisioning mode again for provisioning in the final deployment location.
  • Reset and check in monitor whether the device is in provisioning mode again.
  • Done, device is ready for shipment
deviceesp32.txt · Last modified: 2022/01/11 10:09 by admin