examples: fix format errors, remove -Wno-format

Logging in series of examples has misuse of "%d" instead of type-appropriate format specifiers.
Fix by changing "%d" to PRIxx macros corresponding to type.
Remove -Wno-format compile flag in those examples that are affected.
This commit is contained in:
Bogdan Kolendovskyy
2022-12-15 16:15:39 +01:00
parent 6f0bea38cd
commit d7b8b36082
24 changed files with 48 additions and 49 deletions

View File

@@ -6,8 +6,6 @@ idf_component_register(SRCS "iperf.c"
REQUIRES lwip REQUIRES lwip
PRIV_REQUIRES esp_timer) PRIV_REQUIRES esp_timer)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
if(CONFIG_SOC_WIFI_HE_SUPPORT) if(CONFIG_SOC_WIFI_HE_SUPPORT)
idf_component_optional_requires(PRIVATE esp_wifi console) idf_component_optional_requires(PRIVATE esp_wifi console)
endif() endif()

View File

@@ -1,7 +1,7 @@
/* Iperf Example - iperf implementation /* Iperf Example - iperf implementation
This example code is in the Public Domain (or CC0 licensed, at your option.) This example code is in the Public Domain (or CC0 licensed, at your option.)
/
Unless required by applicable law or agreed to in writing, this Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. CONDITIONS OF ANY KIND, either express or implied.
@@ -11,6 +11,7 @@
#include <string.h> #include <string.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_check.h" #include "esp_check.h"
@@ -86,14 +87,14 @@ static void iperf_report_task(void *arg)
while (!s_iperf_ctrl.finish) { while (!s_iperf_ctrl.finish) {
vTaskDelay(delay_interval); vTaskDelay(delay_interval);
actual_bandwidth = (s_iperf_ctrl.actual_len / coefficient[format] * 8) / interval; actual_bandwidth = (s_iperf_ctrl.actual_len / coefficient[format] * 8) / interval;
printf("%4d-%4d sec %.2f %cbits/sec\n", cur, cur + interval, printf("%4" PRIi32 "-%4" PRIi32 " sec %.2f %cbits/sec\n", cur, cur + interval,
actual_bandwidth, unit[format]); actual_bandwidth, unit[format]);
cur += interval; cur += interval;
average = ((average * (k - 1) / k) + (actual_bandwidth / k)); average = ((average * (k - 1) / k) + (actual_bandwidth / k));
k++; k++;
s_iperf_ctrl.actual_len = 0; s_iperf_ctrl.actual_len = 0;
if (cur >= time) { if (cur >= time) {
printf("%4d-%4d sec %.2f %cbits/sec\n", 0, time, printf("%4d-%4" PRIu32 " sec %.2f %cbits/sec\n", 0, time,
average, unit[format]); average, unit[format]);
break; break;
} }
@@ -395,7 +396,7 @@ static esp_err_t IRAM_ATTR iperf_run_udp_server(void)
err = bind(listen_socket, (struct sockaddr *)&listen_addr6, sizeof(struct sockaddr_in6)); err = bind(listen_socket, (struct sockaddr *)&listen_addr6, sizeof(struct sockaddr_in6));
ESP_GOTO_ON_FALSE((err == 0), ESP_FAIL, exit, TAG, "Socket unable to bind: errno %d", errno); ESP_GOTO_ON_FALSE((err == 0), ESP_FAIL, exit, TAG, "Socket unable to bind: errno %d", errno);
ESP_LOGI(TAG, "Socket bound, port %d", listen_addr6.sin6_port); ESP_LOGI(TAG, "Socket bound, port %" PRIu16, listen_addr6.sin6_port);
memcpy(&listen_addr, &listen_addr6, sizeof(listen_addr6)); memcpy(&listen_addr, &listen_addr6, sizeof(listen_addr6));
} else if (s_iperf_ctrl.cfg.type == IPERF_IP_TYPE_IPV4) { } else if (s_iperf_ctrl.cfg.type == IPERF_IP_TYPE_IPV4) {
@@ -452,7 +453,7 @@ static esp_err_t iperf_run_udp_client(void)
client_socket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IPV6); client_socket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IPV6);
ESP_GOTO_ON_FALSE((client_socket >= 0), ESP_FAIL, exit, TAG, "Unable to create socket: errno %d", errno); ESP_GOTO_ON_FALSE((client_socket >= 0), ESP_FAIL, exit, TAG, "Unable to create socket: errno %d", errno);
ESP_LOGI(TAG, "Socket created, sending to %s:%d", s_iperf_ctrl.cfg.destination_ip6, s_iperf_ctrl.cfg.dport); ESP_LOGI(TAG, "Socket created, sending to %s:%" PRIu16, s_iperf_ctrl.cfg.destination_ip6, s_iperf_ctrl.cfg.dport);
setsockopt(client_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); setsockopt(client_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
memcpy(&dest_addr, &dest_addr6, sizeof(dest_addr6)); memcpy(&dest_addr, &dest_addr6, sizeof(dest_addr6));
@@ -463,7 +464,12 @@ static esp_err_t iperf_run_udp_client(void)
client_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); client_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
ESP_GOTO_ON_FALSE((client_socket >= 0), ESP_FAIL, exit, TAG, "Unable to create socket: errno %d", errno); ESP_GOTO_ON_FALSE((client_socket >= 0), ESP_FAIL, exit, TAG, "Unable to create socket: errno %d", errno);
ESP_LOGI(TAG, "Socket created, sending to %d:%d", s_iperf_ctrl.cfg.destination_ip4, s_iperf_ctrl.cfg.dport); ESP_LOGI(TAG, "Socket created, sending to %d.%d.%d.%d:%" PRIu16,
(uint16_t) s_iperf_ctrl.cfg.destination_ip4 & 0xFF,
(uint16_t) (s_iperf_ctrl.cfg.destination_ip4 >> 8) & 0xFF,
(uint16_t) (s_iperf_ctrl.cfg.destination_ip4 >> 16) & 0xFF,
(uint16_t) (s_iperf_ctrl.cfg.destination_ip4 >> 24) & 0xFF,
s_iperf_ctrl.cfg.dport);
setsockopt(client_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); setsockopt(client_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
memcpy(&dest_addr, &dest_addr4, sizeof(dest_addr4)); memcpy(&dest_addr, &dest_addr4, sizeof(dest_addr4));

View File

@@ -1,4 +1,3 @@
idf_component_register(SRCS "cmd_ethernet.c" idf_component_register(SRCS "cmd_ethernet.c"
"ethernet_example_main.c" "ethernet_example_main.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@@ -8,6 +8,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h" #include "freertos/event_groups.h"
#include "sys/socket.h" // for INADDR_ANY #include "sys/socket.h" // for INADDR_ANY
@@ -175,11 +176,14 @@ static int eth_cmd_iperf(int argc, char **argv)
} }
} }
printf("mode=%s-%s sip=%d.%d.%d.%d:%d, dip=%d.%d.%d.%d:%d, interval=%d, time=%d\r\n", printf("mode=%s-%s sip=" IPSTR ":%" PRIu16 ", dip=%" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32 ":%" PRIu16 ", interval=%" PRIu32 ", time=%" PRIu32 "\r\n",
cfg.flag & IPERF_FLAG_TCP ? "tcp" : "udp", cfg.flag & IPERF_FLAG_TCP ? "tcp" : "udp",
cfg.flag & IPERF_FLAG_SERVER ? "server" : "client", cfg.flag & IPERF_FLAG_SERVER ? "server" : "client",
cfg.source_ip4 & 0xFF, (cfg.source_ip4 >> 8) & 0xFF, (cfg.source_ip4 >> 16) & 0xFF, (uint16_t) cfg.source_ip4 & 0xFF,
(cfg.source_ip4 >> 24) & 0xFF, cfg.sport, (uint16_t) (cfg.source_ip4 >> 8) & 0xFF,
(uint16_t) (cfg.source_ip4 >> 16) & 0xFF,
(uint16_t) (cfg.source_ip4 >> 24) & 0xFF,
cfg.sport,
cfg.destination_ip4 & 0xFF, (cfg.destination_ip4 >> 8) & 0xFF, cfg.destination_ip4 & 0xFF, (cfg.destination_ip4 >> 8) & 0xFF,
(cfg.destination_ip4 >> 16) & 0xFF, (cfg.destination_ip4 >> 24) & 0xFF, cfg.dport, (cfg.destination_ip4 >> 16) & 0xFF, (cfg.destination_ip4 >> 24) & 0xFF, cfg.dport,
cfg.interval, cfg.time); cfg.interval, cfg.time);

View File

@@ -2,4 +2,3 @@ idf_component_register(SRCS "simple_sniffer_example_main.c"
"cmd_sniffer.c" "cmd_sniffer.c"
"cmd_pcap.c" "cmd_pcap.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@@ -430,7 +430,7 @@ static int do_sniffer_cmd(int argc, char **argv)
snf_rt.packets_to_sniff = -1; snf_rt.packets_to_sniff = -1;
if (sniffer_args.number->count) { if (sniffer_args.number->count) {
snf_rt.packets_to_sniff = sniffer_args.number->ival[0]; snf_rt.packets_to_sniff = sniffer_args.number->ival[0];
ESP_LOGI(SNIFFER_TAG, "%d packages will be captured", snf_rt.packets_to_sniff); ESP_LOGI(SNIFFER_TAG, "%" PRIi32 " packages will be captured", snf_rt.packets_to_sniff);
} }
/* start sniffer */ /* start sniffer */

View File

@@ -1,3 +1,2 @@
idf_component_register(SRCS "echo_example_main.c" idf_component_register(SRCS "echo_example_main.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@@ -31,7 +31,7 @@ static void cmd_ping_on_ping_success(esp_ping_handle_t hdl, void *args)
esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr)); esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr));
esp_ping_get_profile(hdl, ESP_PING_PROF_SIZE, &recv_len, sizeof(recv_len)); esp_ping_get_profile(hdl, ESP_PING_PROF_SIZE, &recv_len, sizeof(recv_len));
esp_ping_get_profile(hdl, ESP_PING_PROF_TIMEGAP, &elapsed_time, sizeof(elapsed_time)); esp_ping_get_profile(hdl, ESP_PING_PROF_TIMEGAP, &elapsed_time, sizeof(elapsed_time));
printf("%d bytes from %s icmp_seq=%d ttl=%d time=%d ms\n", printf("%" PRIu32 " bytes from %s icmp_seq=%" PRIu16 " ttl=%" PRIu16 " time=%" PRIu32 " ms\n",
recv_len, ipaddr_ntoa((ip_addr_t*)&target_addr), seqno, ttl, elapsed_time); recv_len, ipaddr_ntoa((ip_addr_t*)&target_addr), seqno, ttl, elapsed_time);
} }
@@ -60,7 +60,7 @@ static void cmd_ping_on_ping_end(esp_ping_handle_t hdl, void *args)
} else { } else {
printf("\n--- %s ping statistics ---\n", inet6_ntoa(*ip_2_ip6(&target_addr))); printf("\n--- %s ping statistics ---\n", inet6_ntoa(*ip_2_ip6(&target_addr)));
} }
printf("%d packets transmitted, %d received, %d%% packet loss, time %dms\n", printf("%" PRIu32 " packets transmitted, %" PRIu32 " received, %" PRIu32 "%% packet loss, time %" PRIu32 "ms\n",
transmitted, received, loss, total_time_ms); transmitted, received, loss, total_time_ms);
// delete the ping sessions, so that we clean up all resources and can create a new ping session // delete the ping sessions, so that we clean up all resources and can create a new ping session
// we don't have to call delete function in the callback, instead we can call delete function from other tasks // we don't have to call delete function in the callback, instead we can call delete function from other tasks

View File

@@ -1,3 +1,2 @@
idf_component_register(SRCS "app_main.c" idf_component_register(SRCS "app_main.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@@ -62,7 +62,7 @@ static void send_binary(esp_mqtt_client_handle_t client)
*/ */
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{ {
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id); ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32, base, event_id);
esp_mqtt_event_handle_t event = event_data; esp_mqtt_event_handle_t event = event_data;
esp_mqtt_client_handle_t client = event->client; esp_mqtt_client_handle_t client = event->client;
int msg_id; int msg_id;
@@ -130,7 +130,7 @@ static void mqtt_app_start(void)
}, },
}; };
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
/* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */ /* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
@@ -140,7 +140,7 @@ static void mqtt_app_start(void)
void app_main(void) void app_main(void)
{ {
ESP_LOGI(TAG, "[APP] Startup.."); ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version()); ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);

View File

@@ -1,3 +1,3 @@
idf_component_register(SRCS "app_main.c" idf_component_register(SRCS "app_main.c"
INCLUDE_DIRS ".") INCLUDE_DIRS "."
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") REQUIRED_IDF_TARGETS esp32s2 esp32c3 esp32s3)

View File

@@ -47,7 +47,7 @@ extern const uint8_t server_cert_pem_end[] asm("_binary_mosquitto_org_crt_end");
*/ */
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{ {
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id); ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32, base, event_id);
esp_mqtt_event_handle_t event = event_data; esp_mqtt_event_handle_t event = event_data;
esp_mqtt_client_handle_t client = event->client; esp_mqtt_client_handle_t client = event->client;
int msg_id; int msg_id;
@@ -124,7 +124,7 @@ static void mqtt_app_start(void)
}, },
}; };
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
esp_mqtt_client_start(client); esp_mqtt_client_start(client);
@@ -133,7 +133,7 @@ static void mqtt_app_start(void)
void app_main(void) void app_main(void)
{ {
ESP_LOGI(TAG, "[APP] Startup.."); ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version()); ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);

View File

@@ -1,3 +1,2 @@
idf_component_register(SRCS "app_main.c" idf_component_register(SRCS "app_main.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@@ -57,7 +57,7 @@ static void log_error_if_nonzero(const char *message, int error_code)
*/ */
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{ {
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id); ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32, base, event_id);
esp_mqtt_event_handle_t event = event_data; esp_mqtt_event_handle_t event = event_data;
esp_mqtt_client_handle_t client = event->client; esp_mqtt_client_handle_t client = event->client;
int msg_id; int msg_id;
@@ -122,7 +122,7 @@ static void mqtt_app_start(void)
} }
}; };
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
/* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */ /* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
@@ -132,7 +132,7 @@ static void mqtt_app_start(void)
void app_main(void) void app_main(void)
{ {
ESP_LOGI(TAG, "[APP] Startup.."); ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version()); ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);

View File

@@ -1,3 +1,2 @@
idf_component_register(SRCS "app_main.c" idf_component_register(SRCS "app_main.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@@ -64,7 +64,7 @@ static const psk_hint_key_t psk_hint_key = {
*/ */
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{ {
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id); ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32 "", base, event_id);
esp_mqtt_event_handle_t event = event_data; esp_mqtt_event_handle_t event = event_data;
esp_mqtt_client_handle_t client = event->client; esp_mqtt_client_handle_t client = event->client;
int msg_id; int msg_id;
@@ -117,7 +117,7 @@ static void mqtt_app_start(void)
.broker.verification.psk_hint_key = &psk_hint_key, .broker.verification.psk_hint_key = &psk_hint_key,
}; };
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
/* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */ /* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
@@ -127,7 +127,7 @@ static void mqtt_app_start(void)
void app_main(void) void app_main(void)
{ {
ESP_LOGI(TAG, "[APP] Startup.."); ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version()); ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);

View File

@@ -1,3 +1,2 @@
idf_component_register(SRCS "app_main.c" idf_component_register(SRCS "app_main.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@@ -52,7 +52,7 @@ static void log_error_if_nonzero(const char *message, int error_code)
*/ */
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{ {
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id); ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32 "", base, event_id);
esp_mqtt_event_handle_t event = event_data; esp_mqtt_event_handle_t event = event_data;
esp_mqtt_client_handle_t client = event->client; esp_mqtt_client_handle_t client = event->client;
int msg_id; int msg_id;
@@ -146,7 +146,7 @@ static void mqtt_app_start(void)
void app_main(void) void app_main(void)
{ {
ESP_LOGI(TAG, "[APP] Startup.."); ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version()); ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);

View File

@@ -1,3 +1,2 @@
idf_component_register(SRCS "app_main.c" idf_component_register(SRCS "app_main.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@@ -50,7 +50,7 @@ static void log_error_if_nonzero(const char *message, int error_code)
*/ */
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{ {
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id); ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32, base, event_id);
esp_mqtt_event_handle_t event = event_data; esp_mqtt_event_handle_t event = event_data;
esp_mqtt_client_handle_t client = event->client; esp_mqtt_client_handle_t client = event->client;
int msg_id; int msg_id;
@@ -119,7 +119,7 @@ static void mqtt_app_start(void)
void app_main(void) void app_main(void)
{ {
ESP_LOGI(TAG, "[APP] Startup.."); ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version()); ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);

View File

@@ -1,3 +1,2 @@
idf_component_register(SRCS "app_main.c" idf_component_register(SRCS "app_main.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@@ -89,7 +89,7 @@ static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{ {
/* The argument passed to esp_mqtt_client_register_event can de accessed as handler_args*/ /* The argument passed to esp_mqtt_client_register_event can de accessed as handler_args*/
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id); ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32, base, event_id);
mqtt_event_handler_cb(event_data); mqtt_event_handler_cb(event_data);
} }
@@ -100,7 +100,7 @@ static void mqtt_app_start(void)
.broker.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start, .broker.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start,
}; };
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
/* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */ /* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
@@ -111,7 +111,7 @@ static void mqtt_app_start(void)
void app_main(void) void app_main(void)
{ {
ESP_LOGI(TAG, "[APP] Startup.."); ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version()); ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);

View File

@@ -1,3 +1,2 @@
idf_component_register(SRCS "app_main.c" idf_component_register(SRCS "app_main.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -99,12 +99,12 @@ static void print_user_property(mqtt5_user_property_handle_t user_property)
*/ */
static void mqtt5_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) static void mqtt5_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{ {
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id); ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32, base, event_id);
esp_mqtt_event_handle_t event = event_data; esp_mqtt_event_handle_t event = event_data;
esp_mqtt_client_handle_t client = event->client; esp_mqtt_client_handle_t client = event->client;
int msg_id; int msg_id;
ESP_LOGD(TAG, "free heap size is %d, maxminu %d", esp_get_free_heap_size(), esp_get_minimum_free_heap_size()); ESP_LOGD(TAG, "free heap size is %" PRIu32 ", minimum %" PRIu32, esp_get_free_heap_size(), esp_get_minimum_free_heap_size());
switch ((esp_mqtt_event_id_t)event_id) { switch ((esp_mqtt_event_id_t)event_id) {
case MQTT_EVENT_CONNECTED: case MQTT_EVENT_CONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED"); ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
@@ -263,8 +263,9 @@ static void mqtt5_app_start(void)
void app_main(void) void app_main(void)
{ {
ESP_LOGI(TAG, "[APP] Startup.."); ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version()); ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);