mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Упрощаем работу с хуком получения MQTT
This commit is contained in:
@@ -51,7 +51,7 @@ class IoTItem {
|
||||
|
||||
// хуки для системных событий
|
||||
virtual void onRegEvent(IoTItem* item);
|
||||
virtual void onMqttRecive(char* topic, uint8_t* payload, size_t length);
|
||||
virtual void onMqttRecive(String& topic, String& msg);
|
||||
|
||||
//методы для графиков
|
||||
virtual void publishValue();
|
||||
|
||||
@@ -117,11 +117,6 @@ void mqttSubscribe() {
|
||||
}
|
||||
|
||||
void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
||||
// распространяем принятое сообщение через хуки
|
||||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||
(*it)->onMqttRecive(topic, payload, length);
|
||||
}
|
||||
|
||||
String topicStr = String(topic);
|
||||
// SerialPrint("i", "=>MQTT", topicStr);
|
||||
String payloadStr;
|
||||
@@ -130,9 +125,10 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
||||
payloadStr += (char)payload[i];
|
||||
}
|
||||
|
||||
// SerialPrint("i", "=>MQTT", payloadStr);
|
||||
|
||||
// SerialPrint("i", F("=>MQTT"), "Msg from iotmanager: " + topicStr);
|
||||
// распространяем принятое сообщение через хуки
|
||||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||
(*it)->onMqttRecive(topicStr, payloadStr);
|
||||
}
|
||||
|
||||
if (payloadStr.startsWith("HELLO")) {
|
||||
SerialPrint("i", F("MQTT"), F("Full update"));
|
||||
|
||||
@@ -175,7 +175,7 @@ void IoTItem::checkIntFromNet() {
|
||||
|
||||
void IoTItem::onRegEvent(IoTItem* item) {}
|
||||
|
||||
void IoTItem::onMqttRecive(char* topic, uint8_t* payload, size_t length) {}
|
||||
void IoTItem::onMqttRecive(String& topic, String& msg) {}
|
||||
|
||||
void IoTItem::publishValue() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user