2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
44#include <iot/mqtt/Topic.h>
45#include <iot/mqtt/packets/Connack.h>
47#ifndef DOXYGEN_SHOULD_SKIP_THIS
51#include <log/Logger.h>
53#include <nlohmann/json.hpp>
54#include <utils/system/signal.h>
58namespace mqtt::mqttintegrator::
lib {
61 const nlohmann::json& connectionJson,
63 const std::string& sessionStoreFileName)
64 : iot::
mqtt::client::Mqtt(connectionName,
65 connectionJson[
"client_id"],
66 connectionJson[
"keep_alive"],
70 VLOG(1) <<
"Client Id: " << clientId;
71 VLOG(1) <<
" Keep Alive: " << keepAlive;
72 VLOG(1) <<
" Clean Session: " << connectionJson[
"clean_session"];
73 VLOG(1) <<
" Will Topic: " << connectionJson[
"will_topic"];
74 VLOG(1) <<
" Will Message: " << connectionJson[
"will_message"];
75 VLOG(1) <<
" Will QoS: " <<
static_cast<uint16_t>(connectionJson[
"will_qos"]);
76 VLOG(1) <<
" Will Retain " << connectionJson[
"will_retain"];
77 VLOG(1) <<
" Username: " << connectionJson[
"username"];
78 VLOG(1) <<
" Password: " << connectionJson[
"password"];
82 VLOG(1) <<
"MQTT: Initiating Session";
94 VLOG(1) <<
"MQTT: On Exit due to '" << strsignal(signum) <<
"' (SIG" << utils::system::sigabbrev_np(signum) <<
" = " << signum
99 return Super::onSignal(signum);
103 if (connack.getReturnCode() == 0 && !connack.getSessionPresent()) {
104 sendPublish(
"snode.c/_cfg_/connection",
connectionJson.dump(), 0,
true);
108 for (
const iot::
mqtt::Topic& topic : topicList) {
109 VLOG(1) <<
"MQTT: Subscribe Topic: " << topic.getName() <<
", qoS: " <<
static_cast<uint16_t>(topic.getQoS());
112 sendSubscribe(topicList);
120 void Mqtt::
publishMapping(
const std::string& topic,
const std::string& message, uint8_t qoS,
bool retain) {
121 sendPublish(topic, message, qoS, retain);
void publishMappings(const iot::mqtt::packets::Publish &publish)
MqttMapper(const nlohmann::json &mappingJson)
std::list< iot::mqtt::Topic > extractSubscriptions()
void publishMapping(const std::string &topic, const std::string &message, uint8_t qoS, bool retain) final
void onPublish(const iot::mqtt::packets::Publish &publish) final
void onConnack(const iot::mqtt::packets::Connack &connack) final
const nlohmann::json & connectionJson
Mqtt(const std::string &connectionName, const nlohmann::json &connectionJson, const nlohmann::json &mappingJson, const std::string &sessionStoreFileName)
bool onSignal(int signum) final
iot::mqtt::client::Mqtt Super