Closed szczys closed 1 year ago
The workaround I'm currently using utilizes a semaphore that is given the first time the app connects to Golioth and checked for in the main loop to run the fw status report function:
K_SEM_DEFINE(dfu_status_update, 0, 1);
static void golioth_on_connect(struct golioth_client *client)
{
k_sem_give(&connected);
LOG_INF("Registering observations with Golioth");
app_dfu_observe();
app_register_settings(client);
app_register_rpc(client);
app_state_observe();
static bool initial_connection = true;
if (initial_connection) {
initial_connection = false;
/* Report current DFU version to Golioth */
//FIXME: we can't call this here because it's sync (deadlock)
//app_dfu_report_state_to_golioth();
//This semaphore is a workaround
k_sem_give(&dfu_status_update);
/* Indicate connection using LEDs */
golioth_connection_led_set(1);
}
}
int main(void) {
while (true) {
if (k_sem_take(&dfu_status_update, K_NO_WAIT) == 0) {
app_dfu_report_state_to_golioth();
}
app_work_sensor_read();
k_sleep(K_SECONDS(get_loop_delay_s()));
}
}
There is a task in the current firmware sprint to implement an async version of the firmware status report function that would be used in place of this workaround.
@szczys this was fixed in https://github.com/golioth/reference-design-template/pull/34 right?
Yes, it was this commit: https://github.com/golioth/reference-design-template/commit/85b1f9c06f5e037e5413f40a507eb17774e388ce
When LTE Link is manually controlled the connection is asynchronous. Operations that would normally happen after Golioth first connects are now handled in on_connect. However, the function to report firmware update status is synchronous and causes a deadlock if added to on_connect.
https://github.com/golioth/reference-design-template/blob/9e244dc2b0135d0be76a606003717f2e0f153ff3/src/main.c#L43-L64