Do not enable web_workflow background callbacks if wifi is not enabled/connected
This commit is contained in:
parent
93b0e5b746
commit
9c45551880
|
@ -258,7 +258,7 @@ void supervisor_web_workflow_status(void) {
|
|||
}
|
||||
#endif
|
||||
|
||||
void supervisor_start_web_workflow(void) {
|
||||
bool supervisor_start_web_workflow(void) {
|
||||
#if CIRCUITPY_WEB_WORKFLOW && CIRCUITPY_WIFI && CIRCUITPY_OS_GETENV
|
||||
|
||||
// Skip starting the workflow if we're not starting from power on or reset.
|
||||
|
@ -268,7 +268,7 @@ void supervisor_start_web_workflow(void) {
|
|||
reset_reason != RESET_REASON_DEEP_SLEEP_ALARM &&
|
||||
reset_reason != RESET_REASON_UNKNOWN &&
|
||||
reset_reason != RESET_REASON_SOFTWARE) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
char ssid[33];
|
||||
|
@ -276,7 +276,7 @@ void supervisor_start_web_workflow(void) {
|
|||
|
||||
os_getenv_err_t result = common_hal_os_getenv_str("CIRCUITPY_WIFI_SSID", ssid, sizeof(ssid));
|
||||
if (result != GETENV_OK) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
result = common_hal_os_getenv_str("CIRCUITPY_WIFI_PASSWORD", password, sizeof(password));
|
||||
|
@ -284,7 +284,7 @@ void supervisor_start_web_workflow(void) {
|
|||
// if password is unspecified, assume an open network
|
||||
password[0] = '\0';
|
||||
} else if (result != GETENV_OK) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
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) {
|
|||
|
||||
if (_wifi_status != WIFI_RADIO_ERROR_NONE) {
|
||||
common_hal_wifi_radio_set_enabled(&common_hal_wifi_radio_obj, false);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// (leaves new_port unchanged on any failure)
|
||||
|
@ -363,6 +363,7 @@ void supervisor_start_web_workflow(void) {
|
|||
// Wake polling thread (maybe)
|
||||
socketpool_socket_poll_resume();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void web_workflow_send_raw(socketpool_socket_obj_t *socket, const uint8_t *buf, int len) {
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
void supervisor_web_workflow_background(void *data);
|
||||
bool supervisor_web_workflow_status_dirty(void);
|
||||
void supervisor_web_workflow_status(void);
|
||||
void supervisor_start_web_workflow(void);
|
||||
bool supervisor_start_web_workflow(void);
|
||||
void supervisor_stop_web_workflow(void);
|
||||
|
||||
// Share the MDNS object with user code.
|
||||
|
|
|
@ -45,8 +45,9 @@
|
|||
|
||||
#if CIRCUITPY_WEB_WORKFLOW
|
||||
#include "supervisor/shared/web_workflow/web_workflow.h"
|
||||
#endif
|
||||
static background_callback_t workflow_background_cb = {NULL, NULL};
|
||||
#endif
|
||||
|
||||
|
||||
// Called during a VM reset. Doesn't actually reset things.
|
||||
void supervisor_workflow_reset(void) {
|
||||
|
@ -56,17 +57,23 @@ void supervisor_workflow_reset(void) {
|
|||
|
||||
#if CIRCUITPY_WEB_WORKFLOW
|
||||
if (workflow_background_cb.fun) {
|
||||
supervisor_start_web_workflow();
|
||||
supervisor_workflow_request_background();
|
||||
if (supervisor_start_web_workflow()) {
|
||||
supervisor_workflow_request_background();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void supervisor_workflow_request_background(void) {
|
||||
#if CIRCUITPY_WEB_WORKFLOW
|
||||
if (workflow_background_cb.fun) {
|
||||
workflow_background_cb.data = NULL;
|
||||
background_callback_add_core(&workflow_background_cb);
|
||||
} else {
|
||||
// Unblock polling thread if necessary
|
||||
socketpool_socket_poll_resume();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Return true if host has completed connection to us (such as USB enumeration).
|
||||
|
@ -98,9 +105,11 @@ void supervisor_workflow_start(void) {
|
|||
#endif
|
||||
|
||||
#if CIRCUITPY_WEB_WORKFLOW
|
||||
supervisor_start_web_workflow();
|
||||
memset(&workflow_background_cb, 0, sizeof(workflow_background_cb));
|
||||
workflow_background_cb.fun = supervisor_web_workflow_background;
|
||||
if (supervisor_start_web_workflow()) {
|
||||
// Enable background callbacks if web_workflow startup successful
|
||||
memset(&workflow_background_cb, 0, sizeof(workflow_background_cb));
|
||||
workflow_background_cb.fun = supervisor_web_workflow_background;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue