Skip to main content

Configure MicroPython WLAN/AP/WebRepl startup with your own code

Project description

MPyConfigBase

Configure automatic startup of MicroPython WLAN / AP / WebRepl / NTP time during boot

General information

Use this together with mpycntrl for automation of the setup/deployment and configuration of MicroPython base interfaces. see also mpycntrl on github

Usage

The information given in the files wlan.cfg, softap.cfg and webrepl_cfg.py are used for configuration.

wlan.cfg and softap.cfg are text files containing ESSID and password in 2 lines

webrepl_cfg.py is a python file containing a single line like

PASS = '123456'

During wlan start the time from NTP is fetched by default.

Best practice

  • send cntrl+c
  • upload the module file along with the configuration files directly (the config files are wlan.cfg, softap.cfg and webrepl_cfg.py)
  • send reset

Sample Code (in boot.py)

from mpyconfigbase import *
try:
    configbase = MPyConfigBase()
    configbase.start()
except Exception as ex:
    print( "error:", ex )

print("set ntp time", configbase.ntp )

import time
while True:
    print( "->", time.localtime( time.time() ) )
    time.sleep(1)

Installation during deployment

The python class code can be retrieved by calling:

fnam, src = MPyConfigBase.get_class_source() # get the module code
cfgbootcode = MPyConfigBase.get_boot_install_code() # get the minimal autconfig code

Sample Code (deployment)

Some sample code for automatic deployment and configuration. In case of timeouts (error message: could not enter raw-repl) consider to use with mpyc.timeout(1) as tout: code block.

The code is also available here on github

Reset the board during the deployment is required since MicroPython needs to bring in the new code before the configuration can take place. If you follow the best practice given above this dont needs to be done.

Limitations

on esp8266 the combined startup with start will probably fail.

on esp32 it will work :-)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpyconfigbase-0.0.4.tar.gz (5.1 kB view hashes)

Uploaded source

Built Distribution

mpyconfigbase-0.0.4-py3-none-any.whl (7.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page