Skip to content

Commit a9a58f2

Browse files
committed
Merge branch 'main' into m5stack_core2
2 parents 8864461 + 0aea455 commit a9a58f2

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

docs/environment.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ CIRCUITPY_WEB_API_PORT
7474
~~~~~~~~~~~~~~~~~~~~~~
7575
TCP port number used for the web HTTP API. Defaults to 80 when omitted.
7676

77+
CIRCUITPY_WEB_INSTANCE_NAME
78+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
79+
Name the board advertises as for the WEB workflow. Defaults to human readable board name if omitted.
80+
7781
CIRCUITPY_WIFI_PASSWORD
7882
~~~~~~~~~~~~~~~~~~~~~~~
7983
Wi-Fi password used to auto connect to CIRCUITPY_WIFI_SSID.

docs/workflows.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ Read-only characteristic that returns the UTF-8 encoded version string.
7272
The web workflow is depends on adding Wi-Fi credentials into the `settings.toml` file. The keys are
7373
`CIRCUITPY_WIFI_SSID` and `CIRCUITPY_WIFI_PASSWORD`. Once these are defined, CircuitPython will
7474
automatically connect to the network and start the webserver used for the workflow. The webserver
75-
is on port 80 unless overridden by `CIRCUITPY_WEB_API_PORT`. It also enables MDNS.
75+
is on port 80 unless overridden by `CIRCUITPY_WEB_API_PORT`. It also enables MDNS. The name
76+
of the board as advertised to the network can be overridden by `CIRCUITPY_WEB_INSTANCE_NAME`.
7677

7778
Here is an example `/settings.toml`:
7879

@@ -86,6 +87,7 @@ CIRCUITPY_WIFI_PASSWORD="secretpassword"
8687
CIRCUITPY_WEB_API_PASSWORD="passw0rd"
8788

8889
CIRCUITPY_WEB_API_PORT=80
90+
CIRCUITPY_WEB_INSTANCE_NAME=""
8991
```
9092

9193
MDNS is used to resolve [`circuitpython.local`](http://circuitpython.local) to a device specific

mpy-cross/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ int main(int argc, char **argv) {
310310
return main_(argc, argv);
311311
}
312312

313-
uint mp_import_stat(const char *path) {
313+
mp_import_stat_t mp_import_stat(const char *path) {
314314
(void)path;
315315
return MP_IMPORT_STAT_NO_EXIST;
316316
}

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ static socketpool_socket_obj_t active;
125125
static _request active_request;
126126

127127
static char _api_password[64];
128+
static char web_instance_name[50];
128129

129130
// Store the encoded IP so we don't duplicate work.
130131
static uint32_t _encoded_ip = 0;
@@ -283,6 +284,11 @@ void supervisor_start_web_workflow(void) {
283284
return;
284285
}
285286

287+
result = common_hal_os_getenv_str("CIRCUITPY_WEB_INSTANCE_NAME", web_instance_name, sizeof(web_instance_name));
288+
if (result != GETENV_OK || web_instance_name[0] == '\0') {
289+
strcpy(web_instance_name, MICROPY_HW_BOARD_NAME);
290+
}
291+
286292
if (!common_hal_wifi_radio_get_enabled(&common_hal_wifi_radio_obj)) {
287293
common_hal_wifi_init(false);
288294
common_hal_wifi_radio_set_enabled(&common_hal_wifi_radio_obj, true);
@@ -329,7 +335,7 @@ void supervisor_start_web_workflow(void) {
329335
mdns_server_construct(&mdns, true);
330336
mdns.base.type = &mdns_server_type;
331337
if (!common_hal_mdns_server_deinited(&mdns)) {
332-
common_hal_mdns_server_set_instance_name(&mdns, MICROPY_HW_BOARD_NAME);
338+
common_hal_mdns_server_set_instance_name(&mdns, web_instance_name);
333339
}
334340
}
335341
if (!common_hal_mdns_server_deinited(&mdns)) {
@@ -796,9 +802,11 @@ static void _reply_with_version_json(socketpool_socket_obj_t *socket, _request *
796802
mp_print_t _socket_print = {socket, _print_chunk};
797803

798804
const char *hostname = "";
805+
const char *instance_name = "";
799806
#if CIRCUITPY_MDNS
800807
if (!common_hal_mdns_server_deinited(&mdns)) {
801808
hostname = common_hal_mdns_server_get_hostname(&mdns);
809+
instance_name = common_hal_mdns_server_get_instance_name(&mdns);
802810
}
803811
#endif
804812
_update_encoded_ip();
@@ -807,13 +815,13 @@ static void _reply_with_version_json(socketpool_socket_obj_t *socket, _request *
807815
"{\"web_api_version\": 2, "
808816
"\"version\": \"" MICROPY_GIT_TAG "\", "
809817
"\"build_date\": \"" MICROPY_BUILD_DATE "\", "
810-
"\"board_name\": \"" MICROPY_HW_BOARD_NAME "\", "
818+
"\"board_name\": \"%s\", "
811819
"\"mcu_name\": \"" MICROPY_HW_MCU_NAME "\", "
812820
"\"board_id\": \"" CIRCUITPY_BOARD_ID "\", "
813821
"\"creator_id\": %u, "
814822
"\"creation_id\": %u, "
815823
"\"hostname\": \"%s\", "
816-
"\"port\": %d, ", CIRCUITPY_CREATOR_ID, CIRCUITPY_CREATION_ID, hostname, web_api_port, _our_ip_encoded);
824+
"\"port\": %d, ", instance_name, CIRCUITPY_CREATOR_ID, CIRCUITPY_CREATION_ID, hostname, web_api_port, _our_ip_encoded);
817825
#if CIRCUITPY_MICROCONTROLLER && COMMON_HAL_MCU_PROCESSOR_UID_LENGTH > 0
818826
uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH];
819827
common_hal_mcu_processor_get_uid(raw_id);

0 commit comments

Comments
 (0)