Skip to content

Commit 5a45558

Browse files
author
Martin Crossley
committed
Improve comments in mqtt_client example
1 parent 3281a3e commit 5a45558

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pico_w/wifi/mqtt/mqtt_client.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection
243243
if (!state->connect_done) {
244244
panic("Failed to connect to mqtt server");
245245
}
246+
// note that the main() loop will soon terminate because mqtt_client_is_connected()
247+
// will return false.
246248
}
247249
else {
248250
panic("Unexpected status");
@@ -368,7 +370,13 @@ int main(void) {
368370
panic("dns request failed");
369371
}
370372

373+
// We are not in a callback but we can get away with calling mqtt_client_is_connected()
374+
// because it's a read-only operation
371375
while (!state.connect_done || mqtt_client_is_connected(state.mqtt_client_inst)) {
376+
// As supplied the example configures cyw43_arch for thread_safe_background operation
377+
// by linking `ico_cyw43_arch_lwip_threadsafe_background` in CMakeLists.txt, so the
378+
// following two lines are unnecessary (but do no harm). However you will need them
379+
// if you reconfigure the build to use cyw43_arch in polling mode.
372380
cyw43_arch_poll();
373381
cyw43_arch_wait_for_work_until(make_timeout_time_ms(10000));
374382
}

0 commit comments

Comments
 (0)