23
23
24
24
static const char * TAG = "mqtt_example" ;
25
25
26
+ // MQTT Test Topics
27
+ static const char * topic_qos0 = "topic/qos0" ;
28
+ static const char * topic_qos1 = "topic/qos1" ;
26
29
27
30
static void log_error_if_nonzero (const char * message , int error_code )
28
31
{
@@ -50,16 +53,16 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
50
53
switch ((esp_mqtt_event_id_t )event_id ) {
51
54
case MQTT_EVENT_CONNECTED :
52
55
ESP_LOGI (TAG , "MQTT_EVENT_CONNECTED" );
53
- msg_id = esp_mqtt_client_publish (client , "/topic/qos1" , "data_3" , 0 , 1 , 0 );
56
+ msg_id = esp_mqtt_client_publish (client , topic_qos1 , "data_3" , 0 , 1 , 0 );
54
57
ESP_LOGI (TAG , "sent publish successful, msg_id=%d" , msg_id );
55
58
56
- msg_id = esp_mqtt_client_subscribe (client , "/topic/qos0" , 0 );
59
+ msg_id = esp_mqtt_client_subscribe (client , topic_qos0 , 0 );
57
60
ESP_LOGI (TAG , "sent subscribe successful, msg_id=%d" , msg_id );
58
61
59
- msg_id = esp_mqtt_client_subscribe (client , "/topic/qos1" , 1 );
62
+ msg_id = esp_mqtt_client_subscribe (client , topic_qos1 , 1 );
60
63
ESP_LOGI (TAG , "sent subscribe successful, msg_id=%d" , msg_id );
61
64
62
- msg_id = esp_mqtt_client_unsubscribe (client , "/topic/qos1" );
65
+ msg_id = esp_mqtt_client_unsubscribe (client , topic_qos1 );
63
66
ESP_LOGI (TAG , "sent unsubscribe successful, msg_id=%d" , msg_id );
64
67
break ;
65
68
case MQTT_EVENT_DISCONNECTED :
@@ -68,7 +71,7 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
68
71
69
72
case MQTT_EVENT_SUBSCRIBED :
70
73
ESP_LOGI (TAG , "MQTT_EVENT_SUBSCRIBED, msg_id=%d" , event -> msg_id );
71
- msg_id = esp_mqtt_client_publish (client , "/topic/qos0" , "data" , 0 , 0 , 0 );
74
+ msg_id = esp_mqtt_client_publish (client , topic_qos0 , "data" , 0 , 0 , 0 );
72
75
ESP_LOGI (TAG , "sent publish successful, msg_id=%d" , msg_id );
73
76
break ;
74
77
case MQTT_EVENT_UNSUBSCRIBED :
0 commit comments