2023-12-28 05:46:39 +00:00
|
|
|
#include <IoTComponent.hpp>
|
|
|
|
|
2023-12-28 13:24:23 +00:00
|
|
|
bool IoTComponent::begin(uint8_t card_id, ExpansionCard *card, PubSubClient *mqtt, char *base_topic) {
|
|
|
|
this->card_id = card_id;
|
|
|
|
this->mqtt = mqtt;
|
|
|
|
this->base_topic = base_topic;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-12-28 05:46:39 +00:00
|
|
|
void IoTComponent::setMqttClient(PubSubClient *mqtt) {
|
|
|
|
this->mqtt = mqtt;
|
2023-12-28 07:08:10 +00:00
|
|
|
}
|
|
|
|
|
2023-12-28 10:03:47 +00:00
|
|
|
void IoTComponent::publishRelative(const char *topic, const char *payload) {
|
2023-12-28 07:08:10 +00:00
|
|
|
char absolute_topic[100];
|
2023-12-28 10:03:47 +00:00
|
|
|
sprintf(absolute_topic, "%s/%02d/%s", base_topic, card_id, topic);
|
2023-12-28 07:08:10 +00:00
|
|
|
mqtt->publish(absolute_topic, payload);
|
2023-12-28 07:52:52 +00:00
|
|
|
}
|
|
|
|
|
2023-12-28 10:03:47 +00:00
|
|
|
void IoTComponent::subscribeRelative(const char *topic) {
|
2023-12-28 08:52:08 +00:00
|
|
|
Serial.println("Subscribe relative");
|
|
|
|
char absolute_topic[50];
|
2023-12-28 10:03:47 +00:00
|
|
|
sprintf(absolute_topic, "%s/%02d/%s", base_topic, card_id, topic);
|
2023-12-28 07:52:52 +00:00
|
|
|
mqtt->subscribe(absolute_topic);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IoTComponent::loop() {
|
|
|
|
// Placeholder, Do nothing
|
2023-12-28 05:46:39 +00:00
|
|
|
}
|