ESPMegaPRO-v3-SDK/ESPMegaPRO-firmware/lib/ESPMegaPRO/IoTComponent.cpp

26 lines
798 B
C++
Raw Normal View History

2023-12-28 05:46:39 +00:00
#include <IoTComponent.hpp>
void IoTComponent::setMqttClient(PubSubClient *mqtt) {
this->mqtt = mqtt;
2023-12-28 07:08:10 +00:00
}
void IoTComponent::publishRelative(const char *topic, const char *payload) {
2023-12-31 16:29:40 +00:00
static char absolute_topic[100];
sprintf(absolute_topic, "%s/%02d/%s", base_topic, card_id, topic);
ESP_LOGD("IoTComponent", "Publishing to %s : %s", absolute_topic, payload);
2023-12-28 07:08:10 +00:00
mqtt->publish(absolute_topic, payload);
2023-12-31 16:29:40 +00:00
mqtt->loop();
delay(50);
2023-12-28 07:52:52 +00:00
}
void IoTComponent::subscribeRelative(const char *topic) {
2023-12-28 08:52:08 +00:00
char absolute_topic[50];
sprintf(absolute_topic, "%s/%02d/%s", base_topic, card_id, topic);
2023-12-31 16:29:40 +00:00
ESP_LOGD("IoTComponent", "Subscribing to %s", absolute_topic);
2023-12-28 07:52:52 +00:00
mqtt->subscribe(absolute_topic);
2023-12-31 16:29:40 +00:00
mqtt->loop();
2023-12-28 07:52:52 +00:00
}
void IoTComponent::loop() {
// Placeholder, Do nothing
2023-12-28 05:46:39 +00:00
}