Hosted Control Library by doing python to C translationctypes library to translate python into ctrl_api.h APIscommands_lib.pyctypes libraryInstallation
Install the dependency libraries, prompt_toolkit, docstring_parser,fire and requests. Below command could be used to install:
$ sudo python3 -m pip install prompt_toolkit fire argparse docstring_parser requests
On Raspberry Pi or other linux distributions, you may see this error when running that command:
error: externally-managed-environment
If you get that error, you can try this alternative method, which is to setup a python virtual environment (venv) to install the packages:
$ python -m venv my-venv
$ my-venv/bin/pip install prompt_toolkit fire argparse docstring_parser requests
To run the demo app in a venv (see below section):
$ sudo my-venv/bin/python ./test.py
sudo permission as interface up and down are executed as network IOCTL for command like connect_ap, start_softapShell mode and CLI mode
test.py, the app runs in CLI modeHosted Control LibHelp
For example,
$ make clean; make
$ sudo python3 ./test.py
hosted > help
command specific help is also available which describes supported mandatory and optional options
For example,
hosted > connect_ap --help OR
hosted > connect_ap help
Exit from CLI mode
exit, quit and q will exit the demo appHelp for available commands
$ make clean; make
$ sudo python3 ./test.py --help
Command specific help is also available
$ sudo python3 ./test.py start_softap --help
Example of command execution:
$ sudo python3 ./test.py connect_ap --ssid SaveEarth --pwd PlantMoreTrees123
Hosted Control LibraryList of commands
wifi_get_modewifi_set_modewifi_get_macwifi_set_macget_available_apconnect_apethsta0 and up ethsta0 interfaceget_connected_ap_infodisconnect_apethsta0 interfacesoftap_vendor_iestart_softapethap0 and up ethap0 interfaceget_softap_infosoftap_connected_clients_infostop_softapset_wifi_power_saveget_wifi_power_saveset_wifi_max_tx_powerget_wifi_curr_tx_powerota_updateheartbeatsubscribe_eventunsubscribe_eventdisable_wifienable_wifidisable_btenable_btget_fw_versionNote:
Shell modeCLI mode and Shell mode, a single command is supported at a time.STRESS_TEST_COUNT iterations$ make clean; make
$ sudo python3 stress.py
As explained above, OTA is run as
$ cd esp_hosted_fg/host/linux/host_control/python_support/
$ sudo python3 ota_update <URL of ESP firmware binary>
This script assumes the station is connected to an AP, an IP is assigned to ethsta0 and HTTP URL is accessible.
It downloads a chunk of OTA image data using HTTP client over ethsta0 interface and writes on ESP flash
Once all chunks are successfully written, it restarts ESP after 5 sec.
Suggestion of steps for OTA with python
The following python command can be used to start the HTTP server if it's not running already.
$ python3 -m http.server <port_number>
Example:
python3 -m http.server 9999
Pass OTA image URL as command line argument to ota_update.py.
$ sudo python3 test.py ota_update "http://<IP_address>:<port_number>/ota_image.bin"
Example:
$ sudo python3 test.py ota_update "http://192.168.0.106:9999/network_adapter.bin"
It will perform the following operations.
Erase OTA flash partition of ESP
Download chunk from URL and write that chunk into flash, one by one, till whole binary is written
Validate the complete written binary in flash
Sets newly written OTA partition as boot partition
Reboot the ESP after 5 second