mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 09:09:10 -04:00
Compare commits
2 Commits
0d404bb9db
...
ae2f27144c
Author | SHA1 | Date | |
---|---|---|---|
|
ae2f27144c | ||
|
f3ff26efb4 |
@ -23,6 +23,9 @@
|
||||
|
||||
static const char *TAG = "mqtt_example";
|
||||
|
||||
// MQTT Test Topics
|
||||
static const char *topic_qos0 = "topic/qos0";
|
||||
static const char *topic_qos1 = "topic/qos1";
|
||||
|
||||
static void log_error_if_nonzero(const char *message, int error_code)
|
||||
{
|
||||
@ -50,16 +53,16 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
||||
switch ((esp_mqtt_event_id_t)event_id) {
|
||||
case MQTT_EVENT_CONNECTED:
|
||||
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
|
||||
msg_id = esp_mqtt_client_publish(client, "/topic/qos1", "data_3", 0, 1, 0);
|
||||
msg_id = esp_mqtt_client_publish(client, topic_qos1, "data_3", 0, 1, 0);
|
||||
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
|
||||
|
||||
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos0", 0);
|
||||
msg_id = esp_mqtt_client_subscribe(client, topic_qos0, 0);
|
||||
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||
|
||||
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos1", 1);
|
||||
msg_id = esp_mqtt_client_subscribe(client, topic_qos1, 1);
|
||||
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||
|
||||
msg_id = esp_mqtt_client_unsubscribe(client, "/topic/qos1");
|
||||
msg_id = esp_mqtt_client_unsubscribe(client, topic_qos1);
|
||||
ESP_LOGI(TAG, "sent unsubscribe successful, msg_id=%d", msg_id);
|
||||
break;
|
||||
case MQTT_EVENT_DISCONNECTED:
|
||||
@ -68,7 +71,7 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
||||
|
||||
case MQTT_EVENT_SUBSCRIBED:
|
||||
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
|
||||
msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0);
|
||||
msg_id = esp_mqtt_client_publish(client, topic_qos0, "data", 0, 0, 0);
|
||||
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
|
||||
break;
|
||||
case MQTT_EVENT_UNSUBSCRIBED:
|
||||
|
Loading…
x
Reference in New Issue
Block a user