Browse Source

mqtt: wildcard

ir
Hendrik Langer 5 years ago
parent
commit
82d038cedc
  1. 7
      src/network/XD0MQTT.cpp

7
src/network/XD0MQTT.cpp

@ -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, "DATA=%.*s\r\n", event->data_len, event->data);
for (const auto &subscription : subscriptions_) {
// literal match
if (strcmp(event->topic, subscription.topic) == 0) {
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;
case MQTT_EVENT_ERROR:

Loading…
Cancel
Save