|
@ -60,9 +60,16 @@ esp_err_t XD0MQTT::mqtt_event_handler_cb(esp_mqtt_event_handle_t event) |
|
|
ESP_LOGI(TAG, "TOPIC=%.*s\r\n", event->topic_len, event->topic); |
|
|
ESP_LOGI(TAG, "TOPIC=%.*s\r\n", event->topic_len, event->topic); |
|
|
ESP_LOGI(TAG, "DATA=%.*s\r\n", event->data_len, event->data); |
|
|
ESP_LOGI(TAG, "DATA=%.*s\r\n", event->data_len, event->data); |
|
|
for (const auto &subscription : subscriptions_) { |
|
|
for (const auto &subscription : subscriptions_) { |
|
|
|
|
|
// literal match
|
|
|
if (strcmp(event->topic, subscription.topic) == 0) { |
|
|
if (strcmp(event->topic, subscription.topic) == 0) { |
|
|
subscription.cb(event->topic, event->data); |
|
|
subscription.cb(event->topic, event->data); |
|
|
|
|
|
// '#' wildcard
|
|
|
|
|
|
} else if (subscription.topic[strlen(subscription.topic)-1] == '#'){ |
|
|
|
|
|
if (strncmp(event->topic, subscription.topic, strlen(subscription.topic)-1) == 0) { |
|
|
|
|
|
subscription.cb(event->topic, event->data); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
// ToDo: '+' wildcard
|
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case MQTT_EVENT_ERROR: |
|
|
case MQTT_EVENT_ERROR: |
|
|