From 1e7638c63d7a1ba5e07b683c85c9266d9e3e1929 Mon Sep 17 00:00:00 2001 From: RobinVdB8 Date: Sun, 26 Nov 2023 17:05:05 +0100 Subject: [PATCH] Solved reviews --- project/Core/Inc/mqtt_application.h | 2 ++ project/Core/Src/mqtt_application.c | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/project/Core/Inc/mqtt_application.h b/project/Core/Inc/mqtt_application.h index 59bbcbe..ae9452d 100644 --- a/project/Core/Inc/mqtt_application.h +++ b/project/Core/Inc/mqtt_application.h @@ -7,6 +7,8 @@ #ifndef INC_MQTTA_H_ #define INC_MQTTA_H_ +#include + /** * @brief Initialize MQTT application * diff --git a/project/Core/Src/mqtt_application.c b/project/Core/Src/mqtt_application.c index b92219e..6692046 100644 --- a/project/Core/Src/mqtt_application.c +++ b/project/Core/Src/mqtt_application.c @@ -130,7 +130,7 @@ static void mqtt_incoming_publish_cb(void* arg, const char* topic, uint32_t tot_ /** * @brief Handles incoming publish data - * Handles the recieved data from a publish to a subscribed topic + * Handles the received data from a publish to a subscribed topic * * @param[in] arg * @param[in] data The incoming data @@ -160,13 +160,15 @@ static void mqtt_incoming_data_cb(void* arg, const uint8_t* data, uint16_t len, LOG_INFO(TAG, "incoming data on input/setImage: %s.", data_buffer); lcd_clear_images(); lcd_set_bg_color_layer0(bgcolor); - if (data_buffer[len - 3] == 'b') { - lcd_draw_img_from_fs((const char*)data_buffer, xpos, ypos); - } - if (data_buffer[len - 3] == 'g') { - gif = lcd_draw_gif_from_fs((const char*)data_buffer, xpos, ypos); - if (gif == NULL) { - LOG_INFO(TAG, "GIF could not be drawn"); + if (strlen(data_buffer) >= 3) { + if (data_buffer[len - 3] == 'b') { + lcd_draw_img_from_fs((const char*)data_buffer, xpos, ypos); + } + if (data_buffer[len - 3] == 'g') { + gif = lcd_draw_gif_from_fs((const char*)data_buffer, xpos, ypos); + if (gif == NULL) { + LOG_INFO(TAG, "GIF could not be drawn"); + } } } break; @@ -210,7 +212,7 @@ static void mqtt_connection_cb(mqtt_client_t* client, void* arg, mqtt_connection if (status != MQTT_CONNECT_ACCEPTED) { LOG_INFO(TAG, "mqtt_connection_cb: Disconnected, reason: %d", status); - while (connection_attempt_counter < ATTEMPT_RECONNECT_AMOUNT) { + if (connection_attempt_counter < ATTEMPT_RECONNECT_AMOUNT) { connection_attempt_counter++; // Try to reconnect mosquitto_connect(client); @@ -409,6 +411,4 @@ static void create_publish_string(char* file_type, char* payload_buffer, size_t } strncat(payload_buffer, "\0", buffer_size - strlen(payload_buffer) - 1); LOG_DEBUG(TAG, "String: %s", payload_buffer); - - return; }