2022-07-15 18:05:58 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2022-04-18 15:19:26 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2022-07-19 21:53:04 +02:00
|
|
|
#include "NetworkSettings.h"
|
2022-04-21 23:15:45 +02:00
|
|
|
#include <Arduino.h>
|
2022-04-18 15:19:26 +02:00
|
|
|
#include <AsyncMqttClient.h>
|
2022-04-21 23:15:45 +02:00
|
|
|
#include <Ticker.h>
|
2022-04-18 15:19:26 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
class MqttSettingsClass {
|
|
|
|
|
public:
|
|
|
|
|
MqttSettingsClass();
|
|
|
|
|
void init();
|
2022-04-21 23:15:45 +02:00
|
|
|
void performReconnect();
|
|
|
|
|
bool getConnected();
|
|
|
|
|
void publish(String subtopic, String payload);
|
2022-07-18 22:28:03 +02:00
|
|
|
void publishHass(String subtopic, String payload);
|
2022-04-18 15:19:26 +02:00
|
|
|
|
2022-07-18 19:08:38 +02:00
|
|
|
String getPrefix();
|
|
|
|
|
|
2022-04-18 15:19:26 +02:00
|
|
|
private:
|
2022-07-19 21:53:04 +02:00
|
|
|
void NetworkEvent(network_event event);
|
2022-04-21 23:15:45 +02:00
|
|
|
|
|
|
|
|
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
|
|
|
|
|
void onMqttConnect(bool sessionPresent);
|
|
|
|
|
|
|
|
|
|
void performConnect();
|
|
|
|
|
void performDisconnect();
|
|
|
|
|
|
|
|
|
|
AsyncMqttClient mqttClient;
|
|
|
|
|
String clientId;
|
|
|
|
|
String willTopic;
|
|
|
|
|
Ticker mqttReconnectTimer;
|
2022-04-18 15:19:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern MqttSettingsClass MqttSettings;
|