mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2025-12-11 17:30:37 +01:00
Remove not required parameters from MqttSubscribeParser
index and total are only required to handle different payload fragments. This is not done here. In a further step, the correct fragment handling will be implemented outside this library.
This commit is contained in:
@@ -64,7 +64,7 @@ private:
|
|||||||
{ "reset_rf_stats", Topic::ResetRfStats },
|
{ "reset_rf_stats", Topic::ResetRfStats },
|
||||||
};
|
};
|
||||||
|
|
||||||
void onMqttMessage(Topic t, const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, const size_t len, const size_t index, const size_t total);
|
void onMqttMessage(Topic t, const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, const size_t len);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MqttHandleInverterClass MqttHandleInverter;
|
extern MqttHandleInverterClass MqttHandleInverter;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public:
|
|||||||
void publish(const String& subtopic, const String& payload);
|
void publish(const String& subtopic, const String& payload);
|
||||||
void publishGeneric(const String& topic, const String& payload, const bool retain, const uint8_t qos = 0);
|
void publishGeneric(const String& topic, const String& payload, const bool retain, const uint8_t qos = 0);
|
||||||
|
|
||||||
void subscribe(const String& topic, const uint8_t qos, const espMqttClientTypes::OnMessageCallback& cb);
|
void subscribe(const String& topic, const uint8_t qos, const OnMessageCallback& cb);
|
||||||
void unsubscribe(const String& topic);
|
void unsubscribe(const String& topic);
|
||||||
|
|
||||||
String getPrefix() const;
|
String getPrefix() const;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2022 Thomas Basler and others
|
* Copyright (C) 2022-2025 Thomas Basler and others
|
||||||
*/
|
*/
|
||||||
#include "MqttSubscribeParser.h"
|
#include "MqttSubscribeParser.h"
|
||||||
|
|
||||||
void MqttSubscribeParser::register_callback(const std::string& topic, uint8_t qos, const espMqttClientTypes::OnMessageCallback& cb)
|
void MqttSubscribeParser::register_callback(const std::string& topic, uint8_t qos, const OnMessageCallback& cb)
|
||||||
{
|
{
|
||||||
cb_filter_t cbf;
|
cb_filter_t cbf;
|
||||||
cbf.topic = topic;
|
cbf.topic = topic;
|
||||||
@@ -24,13 +24,13 @@ void MqttSubscribeParser::unregister_callback(const std::string& topic)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttSubscribeParser::handle_message(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total)
|
void MqttSubscribeParser::handle_message(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
for (const auto& cb : _callbacks) {
|
for (const auto& cb : _callbacks) {
|
||||||
if (mosquitto_topic_matches_sub(cb.topic.c_str(), topic, &result) == MOSQ_ERR_SUCCESS) {
|
if (mosquitto_topic_matches_sub(cb.topic.c_str(), topic, &result) == MOSQ_ERR_SUCCESS) {
|
||||||
if (result) {
|
if (result) {
|
||||||
cb.cb(properties, topic, payload, len, index, total);
|
cb.cb(properties, topic, payload, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,17 +6,19 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
typedef std::function<void(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len)> OnMessageCallback;
|
||||||
|
|
||||||
struct cb_filter_t {
|
struct cb_filter_t {
|
||||||
std::string topic;
|
std::string topic;
|
||||||
uint8_t qos;
|
uint8_t qos;
|
||||||
espMqttClientTypes::OnMessageCallback cb;
|
OnMessageCallback cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MqttSubscribeParser {
|
class MqttSubscribeParser {
|
||||||
public:
|
public:
|
||||||
void register_callback(const std::string& topic, uint8_t qos, const espMqttClientTypes::OnMessageCallback& cb);
|
void register_callback(const std::string& topic, uint8_t qos, const OnMessageCallback& cb);
|
||||||
void unregister_callback(const std::string& topic);
|
void unregister_callback(const std::string& topic);
|
||||||
void handle_message(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);
|
void handle_message(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len);
|
||||||
std::vector<cb_filter_t> get_callbacks();
|
std::vector<cb_filter_t> get_callbacks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2022-2024 Thomas Basler and others
|
* Copyright (C) 2022-2025 Thomas Basler and others
|
||||||
*/
|
*/
|
||||||
#include "MqttHandleInverter.h"
|
#include "MqttHandleInverter.h"
|
||||||
#include "MessageOutput.h"
|
#include "MessageOutput.h"
|
||||||
@@ -148,7 +148,7 @@ String MqttHandleInverterClass::getTopic(std::shared_ptr<InverterAbstract> inv,
|
|||||||
return inv->serialString() + "/" + chanNum + "/" + chanName;
|
return inv->serialString() + "/" + chanNum + "/" + chanName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttHandleInverterClass::onMqttMessage(Topic t, const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, const size_t len, const size_t index, const size_t total)
|
void MqttHandleInverterClass::onMqttMessage(Topic t, const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, const size_t len)
|
||||||
{
|
{
|
||||||
const CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
@@ -252,8 +252,7 @@ void MqttHandleInverterClass::subscribeTopics()
|
|||||||
MqttSettings.subscribe(fullTopic.c_str(), 0,
|
MqttSettings.subscribe(fullTopic.c_str(), 0,
|
||||||
std::bind(&MqttHandleInverterClass::onMqttMessage, this, t,
|
std::bind(&MqttHandleInverterClass::onMqttMessage, this, t,
|
||||||
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_1, std::placeholders::_2,
|
||||||
std::placeholders::_3, std::placeholders::_4,
|
std::placeholders::_3, std::placeholders::_4));
|
||||||
std::placeholders::_5, std::placeholders::_6));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto const& s : _subscriptions) {
|
for (auto const& s : _subscriptions) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2022 Thomas Basler and others
|
* Copyright (C) 2022-2025 Thomas Basler and others
|
||||||
*/
|
*/
|
||||||
#include "MqttSettings.h"
|
#include "MqttSettings.h"
|
||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
@@ -40,7 +40,7 @@ void MqttSettingsClass::onMqttConnect(const bool sessionPresent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttSettingsClass::subscribe(const String& topic, const uint8_t qos, const espMqttClientTypes::OnMessageCallback& cb)
|
void MqttSettingsClass::subscribe(const String& topic, const uint8_t qos, const OnMessageCallback& cb)
|
||||||
{
|
{
|
||||||
_mqttSubscribeParser.register_callback(topic.c_str(), qos, cb);
|
_mqttSubscribeParser.register_callback(topic.c_str(), qos, cb);
|
||||||
std::lock_guard<std::mutex> lock(_clientLock);
|
std::lock_guard<std::mutex> lock(_clientLock);
|
||||||
@@ -93,7 +93,7 @@ void MqttSettingsClass::onMqttMessage(const espMqttClientTypes::MessagePropertie
|
|||||||
{
|
{
|
||||||
MessageOutput.printf("Received MQTT message on topic: %s\r\n", topic);
|
MessageOutput.printf("Received MQTT message on topic: %s\r\n", topic);
|
||||||
|
|
||||||
_mqttSubscribeParser.handle_message(properties, topic, payload, len, index, total);
|
_mqttSubscribeParser.handle_message(properties, topic, payload, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttSettingsClass::performConnect()
|
void MqttSettingsClass::performConnect()
|
||||||
|
|||||||
Reference in New Issue
Block a user