allow absolute callback inside base topic

This commit is contained in:
Siwat Sirichai 2024-03-23 13:12:12 +07:00
parent 919c28a9c7
commit dcc9092026
1 changed files with 60 additions and 54 deletions

View File

@ -42,12 +42,12 @@ void ESPMegaIoT::mqttCallback(char *topic, byte *payload, unsigned int length)
memcpy(payload_buffer, payload, length); memcpy(payload_buffer, payload, length);
payload_buffer[length] = '\0'; payload_buffer[length] = '\0';
// If the topic is not appended with the base topic, call only the absolute callbacks // If the topic is not appended with the base topic, call only the absolute callbacks
for (const auto &callback : mqtt_callbacks)
{
callback.second(topic, payload_buffer);
}
if (strncmp(topic, this->mqtt_config.base_topic, base_topic_length) != 0) if (strncmp(topic, this->mqtt_config.base_topic, base_topic_length) != 0)
{ {
for (const auto &callback : mqtt_callbacks)
{
callback.second(topic, payload_buffer);
}
return; return;
} }
// Remove the base topic from the topic // Remove the base topic from the topic
@ -409,7 +409,7 @@ void ESPMegaIoT::mqttSubscribe()
{ {
if (components[i] != NULL) if (components[i] != NULL)
{ {
ESP_LOGD("ESPMegaIoT","Subscribing component %d", i); ESP_LOGD("ESPMegaIoT", "Subscribing component %d", i);
components[i]->subscribe(); components[i]->subscribe();
mqtt.loop(); mqtt.loop();
} }
@ -733,7 +733,7 @@ MqttConfig *ESPMegaIoT::getMqttConfig()
*/ */
bool ESPMegaIoT::mqttConnected() bool ESPMegaIoT::mqttConnected()
{ {
//return mqtt_connected; // return mqtt_connected;
return mqtt.connected(); return mqtt.connected();
} }
@ -766,7 +766,8 @@ void ESPMegaIoT::bindFRAM(FRAM *fram)
* *
* @return The Wifi IP address * @return The Wifi IP address
*/ */
IPAddress ESPMegaIoT::getWifiIp() { IPAddress ESPMegaIoT::getWifiIp()
{
return WiFi.localIP(); return WiFi.localIP();
} }
@ -775,7 +776,8 @@ IPAddress ESPMegaIoT::getWifiIp() {
* *
* @return The Ethernet IP Address * @return The Ethernet IP Address
*/ */
IPAddress ESPMegaIoT::getETHIp() { IPAddress ESPMegaIoT::getETHIp()
{
return ETH.localIP(); return ETH.localIP();
} }
@ -784,7 +786,8 @@ IPAddress ESPMegaIoT::getETHIp() {
* *
* @return The IP address of the currently active network interface * @return The IP address of the currently active network interface
*/ */
IPAddress ESPMegaIoT::getIp() { IPAddress ESPMegaIoT::getIp()
{
if (network_config.useWifi) if (network_config.useWifi)
return this->getWifiIp(); return this->getWifiIp();
else else
@ -796,7 +799,8 @@ IPAddress ESPMegaIoT::getIp() {
* *
* @return The MAC Address of the Ethernet interface * @return The MAC Address of the Ethernet interface
*/ */
String ESPMegaIoT::getETHMac() { String ESPMegaIoT::getETHMac()
{
return ETH.macAddress(); return ETH.macAddress();
} }
@ -805,7 +809,8 @@ String ESPMegaIoT::getETHMac() {
* *
* @return The MAC Address of the Wifi interface * @return The MAC Address of the Wifi interface
*/ */
String ESPMegaIoT::getWifiMac() { String ESPMegaIoT::getWifiMac()
{
return WiFi.macAddress(); return WiFi.macAddress();
} }
@ -814,7 +819,8 @@ String ESPMegaIoT::getWifiMac() {
* *
* @return The MAC Address of the currently active network interface * @return The MAC Address of the currently active network interface
*/ */
String ESPMegaIoT::getMac() { String ESPMegaIoT::getMac()
{
if (network_config.useWifi) if (network_config.useWifi)
return this->getWifiMac(); return this->getWifiMac();
else else