Skip to content

Commit 99a7047

Browse files
authored
Merge pull request #7960 from thess/workflow_init
Do not enable web_workflow background callbacks if wifi is not enabled/connected
2 parents 6b703ea + 9c45551 commit 99a7047

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void supervisor_web_workflow_status(void) {
258258
}
259259
#endif
260260

261-
void supervisor_start_web_workflow(void) {
261+
bool supervisor_start_web_workflow(void) {
262262
#if CIRCUITPY_WEB_WORKFLOW && CIRCUITPY_WIFI && CIRCUITPY_OS_GETENV
263263

264264
// Skip starting the workflow if we're not starting from power on or reset.
@@ -268,23 +268,23 @@ void supervisor_start_web_workflow(void) {
268268
reset_reason != RESET_REASON_DEEP_SLEEP_ALARM &&
269269
reset_reason != RESET_REASON_UNKNOWN &&
270270
reset_reason != RESET_REASON_SOFTWARE) {
271-
return;
271+
return false;
272272
}
273273

274274
char ssid[33];
275275
char password[64];
276276

277277
os_getenv_err_t result = common_hal_os_getenv_str("CIRCUITPY_WIFI_SSID", ssid, sizeof(ssid));
278278
if (result != GETENV_OK) {
279-
return;
279+
return false;
280280
}
281281

282282
result = common_hal_os_getenv_str("CIRCUITPY_WIFI_PASSWORD", password, sizeof(password));
283283
if (result == GETENV_ERR_NOT_FOUND) {
284284
// if password is unspecified, assume an open network
285285
password[0] = '\0';
286286
} else if (result != GETENV_OK) {
287-
return;
287+
return false;
288288
}
289289

290290
result = common_hal_os_getenv_str("CIRCUITPY_WEB_INSTANCE_NAME", web_instance_name, sizeof(web_instance_name));
@@ -309,7 +309,7 @@ void supervisor_start_web_workflow(void) {
309309

310310
if (_wifi_status != WIFI_RADIO_ERROR_NONE) {
311311
common_hal_wifi_radio_set_enabled(&common_hal_wifi_radio_obj, false);
312-
return;
312+
return false;
313313
}
314314

315315
// (leaves new_port unchanged on any failure)
@@ -363,6 +363,7 @@ void supervisor_start_web_workflow(void) {
363363
// Wake polling thread (maybe)
364364
socketpool_socket_poll_resume();
365365
#endif
366+
return true;
366367
}
367368

368369
void web_workflow_send_raw(socketpool_socket_obj_t *socket, const uint8_t *buf, int len) {

supervisor/shared/web_workflow/web_workflow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
void supervisor_web_workflow_background(void *data);
3737
bool supervisor_web_workflow_status_dirty(void);
3838
void supervisor_web_workflow_status(void);
39-
void supervisor_start_web_workflow(void);
39+
bool supervisor_start_web_workflow(void);
4040
void supervisor_stop_web_workflow(void);
4141

4242
// Share the MDNS object with user code.

supervisor/shared/workflow.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@
4545

4646
#if CIRCUITPY_WEB_WORKFLOW
4747
#include "supervisor/shared/web_workflow/web_workflow.h"
48-
#endif
4948
static background_callback_t workflow_background_cb = {NULL, NULL};
49+
#endif
50+
5051

5152
// Called during a VM reset. Doesn't actually reset things.
5253
void supervisor_workflow_reset(void) {
@@ -56,17 +57,23 @@ void supervisor_workflow_reset(void) {
5657

5758
#if CIRCUITPY_WEB_WORKFLOW
5859
if (workflow_background_cb.fun) {
59-
supervisor_start_web_workflow();
60-
supervisor_workflow_request_background();
60+
if (supervisor_start_web_workflow()) {
61+
supervisor_workflow_request_background();
62+
}
6163
}
6264
#endif
6365
}
6466

6567
void supervisor_workflow_request_background(void) {
68+
#if CIRCUITPY_WEB_WORKFLOW
6669
if (workflow_background_cb.fun) {
6770
workflow_background_cb.data = NULL;
6871
background_callback_add_core(&workflow_background_cb);
72+
} else {
73+
// Unblock polling thread if necessary
74+
socketpool_socket_poll_resume();
6975
}
76+
#endif
7077
}
7178

7279
// Return true if host has completed connection to us (such as USB enumeration).
@@ -98,9 +105,11 @@ void supervisor_workflow_start(void) {
98105
#endif
99106

100107
#if CIRCUITPY_WEB_WORKFLOW
101-
supervisor_start_web_workflow();
102-
memset(&workflow_background_cb, 0, sizeof(workflow_background_cb));
103-
workflow_background_cb.fun = supervisor_web_workflow_background;
108+
if (supervisor_start_web_workflow()) {
109+
// Enable background callbacks if web_workflow startup successful
110+
memset(&workflow_background_cb, 0, sizeof(workflow_background_cb));
111+
workflow_background_cb.fun = supervisor_web_workflow_background;
112+
}
104113
#endif
105114

106115
}

0 commit comments

Comments
 (0)