diff options
author | xengineering <me@xengineering.eu> | 2025-04-17 17:22:21 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2025-04-17 17:22:21 +0200 |
commit | 9a89b48c261c1793d07abdad63c04fcff40035be (patch) | |
tree | 0577d5099ace93f025192089777d096fe48e0770 /fw | |
parent | 686e372d42002a189a1e9b73e387e3414a97fc97 (diff) | |
download | iot-contact-9a89b48c261c1793d07abdad63c04fcff40035be.tar iot-contact-9a89b48c261c1793d07abdad63c04fcff40035be.tar.zst iot-contact-9a89b48c261c1793d07abdad63c04fcff40035be.zip |
WIP: fw: app: Fix empty HTTP response
This was caused by a body_len set to 0 because of changed semantics in
the return value of settings_to_json().
Diffstat (limited to 'fw')
-rw-r--r-- | fw/app/src/http.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/fw/app/src/http.c b/fw/app/src/http.c index eb3d695..1c24490 100644 --- a/fw/app/src/http.c +++ b/fw/app/src/http.c @@ -5,6 +5,7 @@ */ +#include <errno.h> #include <stdint.h> #include <zephyr/init.h> @@ -101,16 +102,24 @@ static int settings_handler( ) { static char buffer[100]; - int ret = settings_to_json(buffer, sizeof(buffer)); + int ret = settings_to_json(buffer, sizeof(buffer) - 1); if (ret < 0) { LOG_ERR("Could not serialize payload for settings request"); return ret; } - LOG_INF("Encoded: '%s'", buffer); + size_t len = strnlen(buffer, sizeof(buffer)); + if (len + 2 > sizeof(buffer)) { + LOG_ERR("Settings JSON requires %d octets but buffer has only %d", + len + 2, sizeof(buffer)); + return -ENOMEM; + } + + buffer[len] = '\n'; + buffer[len + 1] = '\0'; response_ctx->body = (const uint8_t *)buffer; - response_ctx->body_len = ret; + response_ctx->body_len = len + 1; response_ctx->final_chunk = true; response_ctx->status = HTTP_200_OK; |