diff options
author | xengineering <me@xengineering.eu> | 2025-03-27 21:19:30 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2025-03-30 18:51:33 +0200 |
commit | b2afe2a52d421a6f9ce87d6b20c0230f93ecbdc4 (patch) | |
tree | 8a6f219e1a1d08a4088824a68e28615fe44a4966 | |
parent | b188fdb33ac91cad157550723f6e747a065c76db (diff) | |
download | iot-contact-b2afe2a52d421a6f9ce87d6b20c0230f93ecbdc4.tar iot-contact-b2afe2a52d421a6f9ce87d6b20c0230f93ecbdc4.tar.zst iot-contact-b2afe2a52d421a6f9ce87d6b20c0230f93ecbdc4.zip |
fw: app: update: Add source file and HTTP 204 handler
This adds the HTTP PUT /update handler which just returns HTTP 204 No
Content.
This is the minimal first step towards a working /update handler.
-rw-r--r-- | fw/app/CMakeLists.txt | 7 | ||||
-rw-r--r-- | fw/app/Kconfig | 5 | ||||
-rw-r--r-- | fw/app/boards/nucleo_f767zi.conf | 2 | ||||
-rw-r--r-- | fw/app/src/update.c | 42 |
4 files changed, 56 insertions, 0 deletions
diff --git a/fw/app/CMakeLists.txt b/fw/app/CMakeLists.txt index 47f75f6..1a9d1cf 100644 --- a/fw/app/CMakeLists.txt +++ b/fw/app/CMakeLists.txt @@ -21,6 +21,13 @@ target_sources(app "${CMAKE_CURRENT_SOURCE_DIR}/src/heart.c" ) +target_sources_ifdef( + CONFIG_IOT_CONTACT_REMOTE_UPDATE + app + PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/src/update.c" +) + zephyr_linker_sources(SECTIONS sections-rom.ld) zephyr_linker_section(NAME http_resource_desc_http_service KVMA RAM_REGION GROUP RODATA_REGION diff --git a/fw/app/Kconfig b/fw/app/Kconfig new file mode 100644 index 0000000..5393e05 --- /dev/null +++ b/fw/app/Kconfig @@ -0,0 +1,5 @@ +config IOT_CONTACT_REMOTE_UPDATE + bool "Enable the remote update system" + default n + +source "Kconfig.zephyr" diff --git a/fw/app/boards/nucleo_f767zi.conf b/fw/app/boards/nucleo_f767zi.conf index 8170e29..7f92421 100644 --- a/fw/app/boards/nucleo_f767zi.conf +++ b/fw/app/boards/nucleo_f767zi.conf @@ -2,6 +2,8 @@ # v. 2.0. If a copy of the MPL was not distributed with this file, You can # obtain one at https://mozilla.org/MPL/2.0/. +CONFIG_IOT_CONTACT_REMOTE_UPDATE=y + CONFIG_BOOTLOADER_MCUBOOT=y CONFIG_FLASH=y diff --git a/fw/app/src/update.c b/fw/app/src/update.c new file mode 100644 index 0000000..13471d2 --- /dev/null +++ b/fw/app/src/update.c @@ -0,0 +1,42 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at https://mozilla.org/MPL/2.0/. + */ + + +#include <zephyr/logging/log.h> +#include <zephyr/net/http/server.h> +#include <zephyr/net/http/service.h> + +LOG_MODULE_REGISTER(update); + + +static int update_handler( + struct http_client_ctx *client, + enum http_data_status status, + const struct http_request_ctx *request_ctx, + struct http_response_ctx *response_ctx, + void *user_data +) { + LOG_DBG("Handling update request"); + + response_ctx->body = NULL; + response_ctx->body_len = 0; + response_ctx->final_chunk = true; + response_ctx->status = HTTP_204_NO_CONTENT; + + LOG_DBG("Update request handled"); + return 0; +} + +static struct http_resource_detail_dynamic update_resource_detail = { + .common = { + .type = HTTP_RESOURCE_TYPE_DYNAMIC, + .bitmask_of_supported_http_methods = BIT(HTTP_GET), + }, + .cb = update_handler, + .user_data = NULL, +}; + +HTTP_RESOURCE_DEFINE(update_resource, http_service, "/update", &update_resource_detail); |