diff --git a/MqttManager/MqttManager.cpp b/MqttManager/MqttManager.cpp index 6289d4c..696e492 100644 --- a/MqttManager/MqttManager.cpp +++ b/MqttManager/MqttManager.cpp @@ -36,6 +36,7 @@ void MqttManager::setup(String mqttServer, String mqttPort, String mqttUsername, m_mqttClient.onMessage(onMqttMessage); m_mqttClient.setCleanSession(true); + m_mqttClient.setKeepAlive(30); m_mqttClient.setCredentials(m_mqttUsername.c_str(), m_mqttPassword.c_str()); m_mqttClient.setServer(server, m_mqttPort); diff --git a/MqttManager/MqttManager.h.autosave b/MqttManager/MqttManager.h.autosave deleted file mode 100644 index d23ab78..0000000 --- a/MqttManager/MqttManager.h.autosave +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef MQTTMANAGER_H -#define MQTTMANAGER_H - -#include -#include - -#undef min -#undef max - -#include - -#include "SimpleTimer.h" -#include "MqttDiscoveryComponent.h" - -#include -#include -#include - - -class MqttManager -{ -private: - String m_mqttServer; - uint16_t m_mqttPort; - String m_mqttUsername; - String m_mqttPassword; - - String m_deviceName; - String m_deviceIP; - String m_deviceMac; - String m_hardware; - String m_firmware; - String m_firmwareVersion; - - String m_deviceDataTopic; - - MqttDiscoveryComponent* m_deviceNameSensor; - MqttDiscoveryComponent* m_deviceIpSensor; - MqttDiscoveryComponent* m_deviceMacSensor; - MqttDiscoveryComponent* m_deviceHardwareSensor; - MqttDiscoveryComponent* m_deviceFirmwareSensor; - MqttDiscoveryComponent* m_deviceFirmwareVersionSensor; - - std::map m_statusTopics; - std::vector m_subscribeTopics; - std::vector m_discoveryComponents; - - AsyncMqttClient m_mqttClient; - - bool m_connected; - bool m_mqttDiscoveryEnabled{false}; - - SimpleTimer m_deviceStatusInfoTimer; - SimpleTimer m_checkConnectivityTimer; - unsigned long m_checkConnectivityTimeOnline; - unsigned long m_checkConnectivityTimeOffline; - - void setDeviceMac(); - void publishDeviceStatusInfo(); - void publishDiscoveryInfo(); - void refreshStatusTopics(); - void checkConnectivity(); - -public: - MqttManager(); - - void setup(String mqttServer, String mqttPort, String mqttUsername, String mqttPassword, bool mqttDiscoveryEnabled = false); - - void setDeviceData(String deviceName, String hardware, String deviceIP, String firmware, String firmwareVersion); - void setCallback(void (*callback)(String , String)); - void setLastWillMQTT(String topic, const char* payload); - - void setDeviceStatusInfoTime(unsigned long deviceStatusInfoTime); - - void enableDiscovery(bool enable); - void addDiscoveryComponent(MqttDiscoveryComponent* component); - - void addSubscribeTopic(String subscribeTopic); - void clearSubscribeTopics(); - - void addStatusTopic(String statusTopic); - void clearStatusTopics(); - - void startConnection(); - void stopConnection(); - - void publishMQTT(String topic, String payload); - void publishMQTT(String topic, float payload); - - bool connected(); - - void loop(); -}; - -#endif