From 6a1bbfcfa3ffd878832d3c29ff22945a1ac872e2 Mon Sep 17 00:00:00 2001 From: Jakob Krantz Date: Sun, 27 Oct 2024 22:33:07 +0100 Subject: [PATCH 1/3] BLE HTTP: Fix bug pending request not cleared after HTTP timeout. --- app/src/ble/ble_http.c | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/ble/ble_http.c b/app/src/ble/ble_http.c index 0b498762..8d16b1f5 100644 --- a/app/src/ble/ble_http.c +++ b/app/src/ble/ble_http.c @@ -29,6 +29,7 @@ K_WORK_DELAYABLE_DEFINE(ble_http_timeout_work, ble_http_timeout_handler); static void ble_http_timeout_handler(struct k_work *work) { LOG_WRN("HTTP Timeout"); + request_pending = false; ble_http_cb(BLE_HTTP_STATUS_TIMEOUT, NULL); } From ac05339eb272df56b094d3dceadc30097837fb11 Mon Sep 17 00:00:00 2001 From: Jakob Krantz Date: Sun, 27 Oct 2024 23:13:58 +0100 Subject: [PATCH 2/3] BT: Use ACL flow control, not having this caused running out of ACL buffers. Must enable this when BLE Controller is running on another core. This fixes various issues with currupt and lost BLE packets. --- app/prj.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/prj.conf b/app/prj.conf index bd089bc3..4e666e87 100644 --- a/app/prj.conf +++ b/app/prj.conf @@ -111,7 +111,7 @@ CONFIG_NVS=y # Bluetooth CONFIG_BT=y CONFIG_BT_HCI=y -CONFIG_BT_HCI_ACL_FLOW_CONTROL=n +CONFIG_BT_HCI_ACL_FLOW_CONTROL=y CONFIG_BT_CTLR=n # Enable chaining of multiple CTEs in periodic advertising CONFIG_BT_DEBUG_LOG=n From d7e294b368dd4d7df53f78934e0fa539857ff3ce Mon Sep 17 00:00:00 2001 From: Jakob Krantz Date: Sun, 27 Oct 2024 23:14:31 +0100 Subject: [PATCH 3/3] Weather App: Show errors if weather failed to fetch. --- app/src/applications/weather/weather_app.c | 13 +++++++--- app/src/applications/weather/weather_ui.c | 29 +++++++++++++++------- app/src/applications/weather/weather_ui.h | 2 ++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/app/src/applications/weather/weather_app.c b/app/src/applications/weather/weather_app.c index 40e16c1a..1525f520 100644 --- a/app/src/applications/weather/weather_app.c +++ b/app/src/applications/weather/weather_app.c @@ -90,6 +90,7 @@ static void http_rsp_cb(ble_http_status_code_t status, char *response) ble_comm_request_gps_status(false); } else { LOG_ERR("HTTP request failed\n"); + weather_ui_set_error(status == BLE_HTTP_STATUS_TIMEOUT ? "Timeout" : "Failed"); } } @@ -97,8 +98,11 @@ static void fetch_weather_data(double lat, double lon) { char weather_url[512]; snprintf(weather_url, sizeof(weather_url), HTTP_REQUEST_URL_FMT, lat, lon, WEATHER_UI_NUM_FORECASTS); - zsw_ble_http_get(weather_url, http_rsp_cb); - // TODO Handle if HTTP requests are not enabled or supported on phone. + int ret = zsw_ble_http_get(weather_url, http_rsp_cb); + if (ret != 0 && ret != -EBUSY) { + LOG_ERR("Failed to send HTTP request: %d", ret); + weather_ui_set_error("Failed fetching weather"); + } } static void on_zbus_ble_data_callback(const struct zbus_channel *chan) @@ -118,17 +122,18 @@ static void on_zbus_ble_data_callback(const struct zbus_channel *chan) static void weather_app_start(lv_obj_t *root, lv_group_t *group) { + weather_ui_show(root); if (last_update_gps_time == 0 || k_uptime_delta(&last_update_gps_time) > MAX_GPS_AGED_TIME_MS) { LOG_DBG("GPS data is too old, request GPS\n"); int res = ble_comm_request_gps_status(true); if (res != 0) { - LOG_ERR("Failed to request GPS data\n"); + LOG_ERR("Failed to request GPS data"); + weather_ui_set_error("Failed to get GPS data"); } // TODO Show GPS fetching in progress in app } else { fetch_weather_data(last_lat, last_lon); } - weather_ui_show(root); zsw_timeval_t time; zsw_clock_get_time(&time); diff --git a/app/src/applications/weather/weather_ui.c b/app/src/applications/weather/weather_ui.c index 6af51852..1b2dd74c 100644 --- a/app/src/applications/weather/weather_ui.c +++ b/app/src/applications/weather/weather_ui.c @@ -15,7 +15,7 @@ static lv_obj_t *root_page = NULL; static lv_obj_t *ui_bg_img; static lv_obj_t *ui_root_container; -static lv_obj_t *ui_location; +static lv_obj_t *ui_status_label; static lv_obj_t *ui_forecast_widget; static lv_obj_t *ui_time; static lv_obj_t *ui_today_container; @@ -75,14 +75,14 @@ void weather_ui_show(lv_obj_t *root) lv_obj_clear_flag(ui_root_container, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); lv_obj_add_flag(ui_root_container, LV_OBJ_FLAG_HIDDEN); - ui_location = lv_label_create(ui_root_container); - lv_obj_set_width(ui_location, LV_SIZE_CONTENT); - lv_obj_set_height(ui_location, LV_SIZE_CONTENT); - lv_obj_set_x(ui_location, 0); - lv_obj_set_y(ui_location, 25); - lv_obj_set_align(ui_location, LV_ALIGN_TOP_MID); - lv_label_set_text(ui_location, ""); - lv_obj_set_style_text_font(ui_location, &lv_font_montserrat_18, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_status_label = lv_label_create(root_page); + lv_obj_set_width(ui_status_label, LV_SIZE_CONTENT); + lv_obj_set_height(ui_status_label, LV_SIZE_CONTENT); + lv_obj_set_x(ui_status_label, 0); + lv_obj_set_y(ui_status_label, 25); + lv_obj_set_align(ui_status_label, LV_ALIGN_TOP_MID); + lv_label_set_text(ui_status_label, ""); + lv_obj_set_style_text_font(ui_status_label, &lv_font_montserrat_18, LV_PART_MAIN | LV_STATE_DEFAULT); ui_forecast_widget = lv_obj_create(ui_root_container); lv_obj_remove_style_all(ui_forecast_widget); @@ -233,6 +233,17 @@ void weather_ui_set_weather_data(weather_ui_current_weather_data_t current_weath } } +void weather_ui_set_error(char *error) +{ + if (root_page == NULL) { + return; + } + + lv_obj_add_flag(ui_loading_spinner, LV_OBJ_FLAG_HIDDEN); + + lv_label_set_text(ui_status_label, error); +} + void weather_ui_set_time(int hour, int min, int second) { lv_label_set_text_fmt(ui_time, "%02d:%02d", hour, min); diff --git a/app/src/applications/weather/weather_ui.h b/app/src/applications/weather/weather_ui.h index 3a6d2dc8..0d1ad61c 100644 --- a/app/src/applications/weather/weather_ui.h +++ b/app/src/applications/weather/weather_ui.h @@ -41,3 +41,5 @@ void weather_ui_set_weather_data(weather_ui_current_weather_data_t current_weath int num_forecasts); void weather_ui_set_time(int hour, int min, int second); + +void weather_ui_set_error(char *error);