Skip to content

Commit

Permalink
Some MQTT updates
Browse files Browse the repository at this point in the history
Change /pong to /uptime
Display a message if MQTT_SERVER is not defined
Put picow_ in the name like the other examples
Add details to the readme!
  • Loading branch information
peterharperuk committed Feb 5, 2025
1 parent 3593551 commit 39cf06e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ App|Description
[picow_httpd](pico_w/wifi/httpd) | Runs a LWIP HTTP server test app
[picow_http_client](pico_w/wifi/http_client) | Demonstrates how to make http and https requests
[picow_http_client_verify](pico_w/wifi/http_client) | Demonstrates how to make a https request with server authentication
[picow_mqtt_client](pico_w/wifi/mqtt) | Demonstrates how to implement an MQTT client application

#### FreeRTOS examples

Expand Down
3 changes: 2 additions & 1 deletion pico_w/wifi/mqtt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (DEFINED ENV{MQTT_SERVER} AND (NOT MQTT_SERVER))
message("Using MQTT_SERVER from environment ('${MQTT_SERVER}')")
endif()
if (NOT MQTT_SERVER)
message("Skipping MQTT example as MQTT_SERVER is not defined")
return()
endif()
# Define the name of an MQTT broker/server to enable this example
Expand All @@ -32,7 +33,7 @@ if (NOT MQTT_CERT_INC)
set(MQTT_CERT_INC mqtt_client.inc)
endif()

set(TARGET_NAME mqtt_client)
set(TARGET_NAME picow_mqtt_client)
add_executable(${TARGET_NAME}
mqtt_client.c
)
Expand Down
2 changes: 1 addition & 1 deletion pico_w/wifi/mqtt/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t f
} else if (strcmp(basic_topic, "/ping") == 0) {
char buf[11];
snprintf(buf, sizeof(buf), "%u", to_ms_since_boot(get_absolute_time()) / 1000);
mqtt_publish(state->mqtt_client_inst, full_topic(state, "/pong"), buf, strlen(buf), MQTT_PUBLISH_QOS, MQTT_PUBLISH_RETAIN, pub_request_cb, state);
mqtt_publish(state->mqtt_client_inst, full_topic(state, "/uptime"), buf, strlen(buf), MQTT_PUBLISH_QOS, MQTT_PUBLISH_RETAIN, pub_request_cb, state);
} else if (strcmp(basic_topic, "/exit") == 0) {
state->stop_client = true; // stop the client when ALL subscriptions are stopped
sub_unsub_topics(state, false); // unsubscribe
Expand Down

0 comments on commit 39cf06e

Please sign in to comment.