micropython-bootconfig to configure a device with a remote app

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Posts: 38
Joined: Mon May 16, 2016 6:35 pm

micropython-bootconfig to configure a device with a remote app

Post by dwight.hubbard » Thu Jun 16, 2016 6:11 am

I have been aiming to have my micropython boards easier to configure. So I have been working on a configuration system that works similar to how particle IoT devices are configured (which is similar to configuring a chromecast for that matter).

At this point I have the basic configuration functionality working. Here's an example run, I have added the bootconfig package to the scripts directory on the esp8266 that I'm working with and I modified the inisetup.py to run the bootconfig.device.configuration() function at the start of the boot.py it creates.

First I flash the device so its completely unconfigured
dhubbard@dwighttablet:~/git/micropython/esp8266$ esptool.py --port /dev/ttyUSB0 erase_flash;sleep 5;make PORT=/dev/ttyUSB0 deploy
esptool.py v1.2-dev
Erasing flash (this may take a while)...
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
GEN build/genhdr/qstrdefs.collected.h
QSTR not updated
Writing build/firmware-combined.bin to the board
esptool.py v1.2-dev
Running Cesanta flasher stub...
Flash params set to 0x0020
Writing 512000 @ 0x0... 512000 (100 %)
Wrote 512000 bytes at 0x0 in 47.5 seconds (86.3 kbit/s)...
Verifying just-written flash...
Verifying 0x7cfe0 (511968) bytes @ 0x00000000 in flash against build/firmware-combined.bin...
-- verify OK (digest matched)
#@esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --flash_size=8m 0 build/firmware.elf-0x00000.bin 0x9000 build/firmware.elf-0x0[1-f]000.bin

Now the board is flashed and reset it's possible to scan and find it
dhubbard@dwighttablet:~/git/micropython/esp8266$ micropython_board_manager scan
DEBUG:micropython_board_manager:Scanning wifi adapter 'wlp2s0' for micropython boards

Once we find a board the example configuration client can configure it. They keyval arguments can be used to push arbitrary key/value pairs into the configuration so things other than wifi settings can be configured by the same client.
dhubbard@dwighttablet:~/git/micropython/esp8266$ micropython_board_manager configure micropython-esp8266-04d0d5 --keyval=redishost:myhost.local --ssid=sprinkles24 --wifi_passphrase=**********
DEBUG:micropython_board_manager:Sending configuration {'wifi_ssid': 'sprinkles24', 'wifi_password': '********', 'redishost': 'myhost.local'} to device 'micropython-esp8266-04d0d5'
DEBUG:micropython_board_manager:Connecting to the micropython board via wifi
Device 'wlp2s0' successfully activated with 'e9d64d2d-f90c-45ab-902f-1791610d2d63'.
DEBUG:micropython_board_manager:Sending over the device configuration
DEBUG:micropython_board_manager:Destroying the temporary wifi connection
Connection 'micropython-esp8266-04d0d5' (e9d64d2d-f90c-45ab-902f-1791610d2d63) successfully deleted.
DEBUG:micropython_board_manager:Restoring the original wifi connection
DEBUG:micropython_board_manager:No previous active connection specified

Here's the serial console output after the above finished running (if the configuration changes it does a machine.reset() so the device starts from a clean state)

Configuring device with configuration {'wifi_password': '*************', 'redishost': 'myhost.local', 'wifi_ssid': 'sprinkles24'}
Attempting to connect to {'sprinkles24': '*************'}
f r0, scandone
Found networks [(b'VPSAPT257', b',03\xc6\x89\x93', 1, -74, 3, 0), (b'CrawDaddyPOS', b'lp\x9f\xee\x98~', 1, -85, 3, 0), (b'CypressNet', b'T\xbe\xf7\xd3F`', 1, -92, 4, 0), (b'NETGEAR14', b]
VPSAPT257 sprinkles24
CrawDaddyPOS sprinkles24
CypressNet sprinkles24
NETGEAR14 sprinkles24
sprinkles24 sprinkles24
Network 'sprinkles24' found!
f r0, scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 5

connected with sprinkles24, channel 6
dhcp client start...
WLAN connection to 'sprinkles24' succeeded!
Network Configuration:
could not open file 'main.py' for reading

#5 ets_task(40100350, 3, 3fff6360, 4)
MicroPython v1.8.1-43-g422396c-dirty on 2016-06-15; ESP module with ESP8266
Type "help()" for more information.

Code is at https://github.com/dwighthubbard/microp ... config.git

Post Reply