Skip to content

Commit e38b549

Browse files
committed
Add device name env variable for web workflow
1 parent 76f9c18 commit e38b549

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
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

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ void supervisor_start_web_workflow(void) {
269269

270270
char ssid[33];
271271
char password[64];
272+
char web_instance_name[50];
272273

273274
os_getenv_err_t result = common_hal_os_getenv_str("CIRCUITPY_WIFI_SSID", ssid, sizeof(ssid));
274275
if (result != GETENV_OK) {
@@ -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,8 @@ 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+
char *instance_name = strndup(web_instance_name, strlen(web_instance_name));
339+
common_hal_mdns_server_set_instance_name(&mdns, instance_name);
333340
}
334341
}
335342
if (!common_hal_mdns_server_deinited(&mdns)) {
@@ -796,9 +803,11 @@ static void _reply_with_version_json(socketpool_socket_obj_t *socket, _request *
796803
mp_print_t _socket_print = {socket, _print_chunk};
797804

798805
const char *hostname = "";
806+
const char *instance_name = "";
799807
#if CIRCUITPY_MDNS
800808
if (!common_hal_mdns_server_deinited(&mdns)) {
801809
hostname = common_hal_mdns_server_get_hostname(&mdns);
810+
instance_name = common_hal_mdns_server_get_instance_name(&mdns);
802811
}
803812
#endif
804813
_update_encoded_ip();
@@ -807,13 +816,13 @@ static void _reply_with_version_json(socketpool_socket_obj_t *socket, _request *
807816
"{\"web_api_version\": 2, "
808817
"\"version\": \"" MICROPY_GIT_TAG "\", "
809818
"\"build_date\": \"" MICROPY_BUILD_DATE "\", "
810-
"\"board_name\": \"" MICROPY_HW_BOARD_NAME "\", "
819+
"\"board_name\": \"%s\", "
811820
"\"mcu_name\": \"" MICROPY_HW_MCU_NAME "\", "
812821
"\"board_id\": \"" CIRCUITPY_BOARD_ID "\", "
813822
"\"creator_id\": %u, "
814823
"\"creation_id\": %u, "
815824
"\"hostname\": \"%s\", "
816-
"\"port\": %d, ", CIRCUITPY_CREATOR_ID, CIRCUITPY_CREATION_ID, hostname, web_api_port, _our_ip_encoded);
825+
"\"port\": %d, ", instance_name, CIRCUITPY_CREATOR_ID, CIRCUITPY_CREATION_ID, hostname, web_api_port, _our_ip_encoded);
817826
#if CIRCUITPY_MICROCONTROLLER && COMMON_HAL_MCU_PROCESSOR_UID_LENGTH > 0
818827
uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH];
819828
common_hal_mcu_processor_get_uid(raw_id);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy