Skip to content

Commit

Permalink
If MQTT service is in IDLE state (means no broker is configured, ther…
Browse files Browse the repository at this point in the history
…efore MQTT disabled), MQTT topic handler registration/unregistration/notification are disabled.
  • Loading branch information
BlueAndi committed Jan 6, 2025
1 parent fee7c35 commit d21c419
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/MqttApiTopicHandler/src/MqttApiTopicHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ void MqttApiTopicHandler::stop()

void MqttApiTopicHandler::registerTopic(const String& deviceId, const String& entityId, const String& topic, JsonObjectConst& extra, GetTopicFunc getTopicFunc, SetTopicFunc setTopicFunc, UploadReqFunc uploadReqFunc)
{
if ((false == deviceId.isEmpty()) &&
MqttService& mqttService = MqttService::getInstance();

/* MQTT service shall be enabled and
* a device id and topic name shall be given.
*/
if ((MqttService::STATE_IDLE != mqttService.getState()) &&
(false == deviceId.isEmpty()) &&
(false == topic.isEmpty()))
{
String mqttTopicBase = getMqttBaseTopic(deviceId, entityId, topic);
Expand Down Expand Up @@ -150,7 +156,13 @@ void MqttApiTopicHandler::registerTopic(const String& deviceId, const String& en

void MqttApiTopicHandler::unregisterTopic(const String& deviceId, const String& entityId, const String& topic, bool purge)
{
if ((false == deviceId.isEmpty()) &&
MqttService& mqttService = MqttService::getInstance();

/* MQTT service shall be enabled and
* a device id and topic name shall be given.
*/
if ((MqttService::STATE_IDLE != mqttService.getState()) &&
(false == deviceId.isEmpty()) &&
(false == topic.isEmpty()))
{
String mqttTopicBase = getMqttBaseTopic(deviceId, entityId, topic);
Expand Down Expand Up @@ -265,7 +277,13 @@ void MqttApiTopicHandler::process()

void MqttApiTopicHandler::notify(const String& deviceId, const String& entityId, const String& topic)
{
if ((false == deviceId.isEmpty()) &&
MqttService& mqttService = MqttService::getInstance();

/* MQTT service shall be enabled and
* a device id and topic name shall be given.
*/
if ((MqttService::STATE_IDLE != mqttService.getState()) &&
(false == deviceId.isEmpty()) &&
(false == topic.isEmpty()))
{
ListOfTopicStates::iterator topicStateIt = m_listOfTopicStates.begin();
Expand Down

0 comments on commit d21c419

Please sign in to comment.