Skip to content

Hardware configuration for ESP8285

Thomas Maier-Komor edited this page May 3, 2021 · 1 revision

Setting up Atrium on an ESP8285

The ESP8285 has 1MB of internal flash. Therefore, flash is very limited comparted to the usual 4MB of external flash of the D1 Mini board with an ESP8266 or integrated modules like the ESP12S. You can find the ESP8285 in the Sonsoff/Itead smart sockets and similar products.

The Atrium setup for 1MB restricts a flash image to 448 kiBytes, while the default partition table for 4MB flash has 1024 kiBytes per application partition. That makes it necessary to strip down Atrium a bit. One of the things that does not fit into the preconfigured flash image for the 1MB setup with 448kiB partitions, is the support for on-device hardware configuration. Of course, you could create a custom configuration with different trade-offs that includes hwconf.

So how do you configure such a device? Simple answer: with the off-line configuration tool. This tool is included in the source tree, and must be build before use. The tool can create configuration binaries, and NVS partitions. The hardware confiuration is actually stored in the NVS partition, but the NVS partition also holds the node or software configuration as well as the WiFi parameter information. Therefore, overwriting the whole partition is often not what you want to do. But it is easier, if the device is already attached to a development machine, then providing the coding hex to the running device.

Below both methods are described. Which one you need to use, you have to decide depending on the restrictions you have, and your personal preferences.

Building atriumcfg

Building atriumcfg is straight forward. Just type make atriumcfg. For this to work, you need WFC (https://www.github.com/maierkomor/wfc), GNU make, and G++. Furthermore, you will need the development packages of libmd (on Debian/Ubuntu libmd-dev) and libeditline (on Debian/Ubuntu libeditline-dev). I have never tested if this works on MinGW. So currently, Windows as development host is untested. Tests were all performed on Linux.

Using atriumcfg

After building, you will fing atriumcfg in the bin subdirectory. As a standalone tool, atriumcfg is able to parse and wirte hardware, and software configuration binaries. To create an NVS partition or flash it on a device, you will need the apropriate Espressif IDF for the relevant device.

The IDFs for ESP32 and ESP8266 can either be downloaded with the setup script of Atrium, or manually from the website. Anyway, you need to tell atriumcfg, where the IDF is. And you need to pass the correct IDF to atriumcfg, otherwise the created NVS partitions will not work on the target device, as the binary seems to differ between those two controllers.

Atrium and atriumcfg themselves are completely agnostic to the ESP controller variant regarding the configurations. You can even create a config file that includes stuff that does not exist on the target controller, and Atrium will simply ignore the settings which cannot be used on that device. Therefore, make sure to set the correct directory with the idf command. E.g. type idf /opt/idf-esp8266.

As written above, the tool atriumcfg can read and create both hardware and software configuration binaries. When started with a binary on the command-line, atriumcfg will switch to the appropriate mode. You can switch between hardware and software configuration, by either typing hw or sw respectively. Typing show shows you all available settings. When typing json you get a JSON output that includes only the relevant information that has been set.

To expand vector configurations, such as holidays, use the add command. E.g. add holidays. After that show will also show the empty fields of the newly added vector element. To set an element value, use the set command. To reset or clear a specific settings, you can use the clear command. E.g. clear holdiays[0]. For vectors, the given element will be erased. Regular fields will be set to the unset state.

At any point, you can save the current configuration, using the write <filename> command. Be aware that hardware and software configurations are handled independently of eachother, and therefore need to be stored in different files.

Writing the NVS partition

To write a configuration consisting of the current software and hardware configuration to the NVS parititon of a device, you need to attach the device to your development computer, and set the port of the UART connection for flashing using the port command. Per default the port is set to /dev/ttyUSB0. Then you must boot the device into programming mode. Popular development boards don't need that manual step, as the flashing tool esptool can do it over CTS and RTS.

Then simply type updatenvs and the relevant partition will be overwritten with a new NVS image.

On-Line Update of the hardware configuration

To update the hardware configuration on a running devce, you need a binary configuration file that should be written to the device. This binary must be dumped as hex, either with the xxd command in atriumcfg or with xxd -p <config.bin>. Then either connect to the serial console of the device (if enabled) or telnet into the device. Once connected use su 1 to gain admin rights.

Next, copy the hex output of the binary, then enter hwconf parsexxd, and paste the hex afterwards followed by a newline or simply hitting enter. As a result you should get an output with the number of successfully parsed bytes.

At that point nothing has been written to the NVS. So you can safely check, if the length is the expected one, and if parsing errors occured. Printing the configuration is not possible. Once convinced that the configuration should be written to nvs, type hwconf writebuf. Now, the configuration is persistent in NVS, and you can reboot to activate the new configuration.