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);
payload_buffer[length] = '\0';
// If the topic is not appended with the base topic, call only the absolute callbacks
if (strncmp(topic, this->mqtt_config.base_topic, base_topic_length) != 0)
{
for (const auto &callback : mqtt_callbacks)
{
callback.second(topic, payload_buffer);
}
if (strncmp(topic, this->mqtt_config.base_topic, base_topic_length) != 0)
{
return;
}
// Remove the base topic from the topic
@ -766,7 +766,8 @@ void ESPMegaIoT::bindFRAM(FRAM *fram)
*
* @return The Wifi IP address
*/
IPAddress ESPMegaIoT::getWifiIp() {
IPAddress ESPMegaIoT::getWifiIp()
{
return WiFi.localIP();
}
@ -775,7 +776,8 @@ IPAddress ESPMegaIoT::getWifiIp() {
*
* @return The Ethernet IP Address
*/
IPAddress ESPMegaIoT::getETHIp() {
IPAddress ESPMegaIoT::getETHIp()
{
return ETH.localIP();
}
@ -784,7 +786,8 @@ IPAddress ESPMegaIoT::getETHIp() {
*
* @return The IP address of the currently active network interface
*/
IPAddress ESPMegaIoT::getIp() {
IPAddress ESPMegaIoT::getIp()
{
if (network_config.useWifi)
return this->getWifiIp();
else
@ -796,7 +799,8 @@ IPAddress ESPMegaIoT::getIp() {
*
* @return The MAC Address of the Ethernet interface
*/
String ESPMegaIoT::getETHMac() {
String ESPMegaIoT::getETHMac()
{
return ETH.macAddress();
}
@ -805,7 +809,8 @@ String ESPMegaIoT::getETHMac() {
*
* @return The MAC Address of the Wifi interface
*/
String ESPMegaIoT::getWifiMac() {
String ESPMegaIoT::getWifiMac()
{
return WiFi.macAddress();
}
@ -814,7 +819,8 @@ String ESPMegaIoT::getWifiMac() {
*
* @return The MAC Address of the currently active network interface
*/
String ESPMegaIoT::getMac() {
String ESPMegaIoT::getMac()
{
if (network_config.useWifi)
return this->getWifiMac();
else