Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

603 lines
18 KiB

8 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. /*
  2. MQTT MODULE
  3. Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #if MQTT_SUPPORT
  6. #include <ESP8266WiFi.h>
  7. #include <ESP8266mDNS.h>
  8. #include <ArduinoJson.h>
  9. #include <vector>
  10. #include <Ticker.h>
  11. #if MQTT_USE_ASYNC // Using AsyncMqttClient
  12. #include <AsyncMqttClient.h>
  13. AsyncMqttClient _mqtt;
  14. #else // Using PubSubClient
  15. #include <PubSubClient.h>
  16. PubSubClient _mqtt;
  17. bool _mqtt_connected = false;
  18. WiFiClient _mqtt_client;
  19. #if ASYNC_TCP_SSL_ENABLED
  20. WiFiClientSecure _mqtt_client_secure;
  21. #endif // ASYNC_TCP_SSL_ENABLED
  22. #endif // MQTT_USE_ASYNC
  23. bool _mqtt_enabled = MQTT_ENABLED;
  24. bool _mqtt_use_json = false;
  25. unsigned long _mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN;
  26. unsigned char _mqtt_qos = MQTT_QOS;
  27. bool _mqtt_retain = MQTT_RETAIN;
  28. unsigned char _mqtt_keepalive = MQTT_KEEPALIVE;
  29. String _mqtt_topic;
  30. String _mqtt_setter;
  31. String _mqtt_getter;
  32. bool _mqtt_forward;
  33. char *_mqtt_user = 0;
  34. char *_mqtt_pass = 0;
  35. char *_mqtt_will;
  36. char *_mqtt_clientid;
  37. #if MQTT_SKIP_RETAINED
  38. unsigned long _mqtt_connected_at = 0;
  39. #endif
  40. std::vector<mqtt_callback_f> _mqtt_callbacks;
  41. typedef struct {
  42. char * topic;
  43. char * message;
  44. } mqtt_message_t;
  45. std::vector<mqtt_message_t> _mqtt_queue;
  46. Ticker _mqtt_flush_ticker;
  47. // -----------------------------------------------------------------------------
  48. // Public API
  49. // -----------------------------------------------------------------------------
  50. bool mqttConnected() {
  51. return _mqtt.connected();
  52. }
  53. void mqttDisconnect() {
  54. if (_mqtt.connected()) {
  55. DEBUG_MSG_P(PSTR("[MQTT] Disconnecting\n"));
  56. _mqtt.disconnect();
  57. }
  58. }
  59. bool mqttForward() {
  60. return _mqtt_forward;
  61. }
  62. String mqttSubtopic(char * topic) {
  63. String response;
  64. String t = String(topic);
  65. if (t.startsWith(_mqtt_topic) && t.endsWith(_mqtt_setter)) {
  66. response = t.substring(_mqtt_topic.length(), t.length() - _mqtt_setter.length());
  67. }
  68. return response;
  69. }
  70. void mqttSendRaw(const char * topic, const char * message) {
  71. if (_mqtt.connected()) {
  72. #if MQTT_USE_ASYNC
  73. unsigned int packetId = _mqtt.publish(topic, _mqtt_qos, _mqtt_retain, message);
  74. DEBUG_MSG_P(PSTR("[MQTT] Sending %s => %s (PID %d)\n"), topic, message, packetId);
  75. #else
  76. _mqtt.publish(topic, message, _mqtt_retain);
  77. DEBUG_MSG_P(PSTR("[MQTT] Sending %s => %s\n"), topic, message);
  78. #endif
  79. }
  80. }
  81. String getTopic(const char * topic, bool set) {
  82. String output = _mqtt_topic + String(topic);
  83. if (set) output += _mqtt_setter;
  84. return output;
  85. }
  86. String getTopic(const char * topic, unsigned int index, bool set) {
  87. char buffer[strlen(topic)+5];
  88. snprintf_P(buffer, sizeof(buffer), PSTR("%s/%d"), topic, index);
  89. return getTopic(buffer, set);
  90. }
  91. void _mqttFlush() {
  92. if (_mqtt_queue.size() == 0) return;
  93. DynamicJsonBuffer jsonBuffer;
  94. JsonObject& root = jsonBuffer.createObject();
  95. for (unsigned char i=0; i<_mqtt_queue.size(); i++) {
  96. mqtt_message_t element = _mqtt_queue[i];
  97. root[element.topic] = element.message;
  98. }
  99. #if NTP_SUPPORT
  100. if (ntpConnected()) root[MQTT_TOPIC_TIME] = ntpDateTime();
  101. #endif
  102. root[MQTT_TOPIC_HOSTNAME] = getSetting("hostname");
  103. root[MQTT_TOPIC_IP] = getIP();
  104. String output;
  105. root.printTo(output);
  106. String path = _mqtt_topic + String(MQTT_TOPIC_JSON);
  107. mqttSendRaw(path.c_str(), output.c_str());
  108. for (unsigned char i = 0; i < _mqtt_queue.size(); i++) {
  109. mqtt_message_t element = _mqtt_queue[i];
  110. free(element.topic);
  111. free(element.message);
  112. }
  113. _mqtt_queue.clear();
  114. }
  115. void mqttSend(const char * topic, const char * message, bool force) {
  116. bool useJson = force ? false : _mqtt_use_json;
  117. if (useJson) {
  118. if (_mqtt_queue.size() >= MQTT_QUEUE_MAX_SIZE) _mqttFlush();
  119. mqtt_message_t element;
  120. element.topic = strdup(topic);
  121. element.message = strdup(message);
  122. _mqtt_queue.push_back(element);
  123. _mqtt_flush_ticker.once_ms(MQTT_USE_JSON_DELAY, _mqttFlush);
  124. } else {
  125. String path = _mqtt_topic + String(topic) + _mqtt_getter;
  126. mqttSendRaw(path.c_str(), message);
  127. }
  128. }
  129. void mqttSend(const char * topic, const char * message) {
  130. mqttSend(topic, message, false);
  131. }
  132. void mqttSend(const char * topic, unsigned int index, const char * message, bool force) {
  133. char buffer[strlen(topic)+5];
  134. snprintf_P(buffer, sizeof(buffer), PSTR("%s/%d"), topic, index);
  135. mqttSend(buffer, message, force);
  136. }
  137. void mqttSend(const char * topic, unsigned int index, const char * message) {
  138. mqttSend(topic, index, message, false);
  139. }
  140. void mqttSubscribeRaw(const char * topic) {
  141. if (_mqtt.connected() && (strlen(topic) > 0)) {
  142. #if MQTT_USE_ASYNC
  143. unsigned int packetId = _mqtt.subscribe(topic, _mqtt_qos);
  144. DEBUG_MSG_P(PSTR("[MQTT] Subscribing to %s (PID %d)\n"), topic, packetId);
  145. #else
  146. _mqtt.subscribe(topic, _mqtt_qos);
  147. DEBUG_MSG_P(PSTR("[MQTT] Subscribing to %s\n"), topic);
  148. #endif
  149. }
  150. }
  151. void mqttSubscribe(const char * topic) {
  152. String path = _mqtt_topic + String(topic) + _mqtt_setter;
  153. mqttSubscribeRaw(path.c_str());
  154. }
  155. void mqttUnsubscribeRaw(const char * topic) {
  156. if (_mqtt.connected() && (strlen(topic) > 0)) {
  157. #if MQTT_USE_ASYNC
  158. unsigned int packetId = _mqtt.unsubscribe(topic);
  159. DEBUG_MSG_P(PSTR("[MQTT] Unsubscribing to %s (PID %d)\n"), topic, packetId);
  160. #else
  161. _mqtt.unsubscribe(topic);
  162. DEBUG_MSG_P(PSTR("[MQTT] Unsubscribing to %s\n"), topic);
  163. #endif
  164. }
  165. }
  166. void mqttRegister(mqtt_callback_f callback) {
  167. _mqtt_callbacks.push_back(callback);
  168. }
  169. // -----------------------------------------------------------------------------
  170. // Callbacks
  171. // -----------------------------------------------------------------------------
  172. #if WEB_SUPPORT
  173. void _mqttWebSocketOnSend(JsonObject& root) {
  174. root["mqttVisible"] = 1;
  175. root["mqttStatus"] = mqttConnected();
  176. root["mqttEnabled"] = mqttEnabled();
  177. root["mqttServer"] = getSetting("mqttServer", MQTT_SERVER);
  178. root["mqttPort"] = getSetting("mqttPort", MQTT_PORT);
  179. root["mqttUser"] = getSetting("mqttUser");
  180. root["mqttClientID"] = getSetting("mqttClientID");
  181. root["mqttPassword"] = getSetting("mqttPassword");
  182. root["mqttKeep"] = _mqtt_keepalive;
  183. root["mqttRetain"] = _mqtt_retain;
  184. root["mqttQoS"] = _mqtt_qos;
  185. #if ASYNC_TCP_SSL_ENABLED
  186. root["mqttsslVisible"] = 1;
  187. root["mqttUseSSL"] = getSetting("mqttUseSSL", 0).toInt() == 1;
  188. root["mqttFP"] = getSetting("mqttFP");
  189. #endif
  190. root["mqttTopic"] = getSetting("mqttTopic", MQTT_TOPIC);
  191. root["mqttUseJson"] = getSetting("mqttUseJson", MQTT_USE_JSON).toInt() == 1;
  192. }
  193. #endif
  194. void _mqttCallback(unsigned int type, const char * topic, const char * payload) {
  195. if (type == MQTT_CONNECT_EVENT) {
  196. // Subscribe to internal action topics
  197. mqttSubscribe(MQTT_TOPIC_ACTION);
  198. // Send heartbeat messages
  199. heartbeat();
  200. }
  201. if (type == MQTT_MESSAGE_EVENT) {
  202. // Match topic
  203. String t = mqttSubtopic((char *) topic);
  204. // Actions
  205. if (t.equals(MQTT_TOPIC_ACTION)) {
  206. if (strcmp(payload, MQTT_ACTION_RESET) == 0) {
  207. deferredReset(100, CUSTOM_RESET_MQTT);
  208. }
  209. }
  210. }
  211. }
  212. void _mqttOnConnect() {
  213. DEBUG_MSG_P(PSTR("[MQTT] Connected!\n"));
  214. _mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN;
  215. #if MQTT_SKIP_RETAINED
  216. _mqtt_connected_at = millis();
  217. #endif
  218. // Clean subscriptions
  219. mqttUnsubscribeRaw("#");
  220. // Send connect event to subscribers
  221. for (unsigned char i = 0; i < _mqtt_callbacks.size(); i++) {
  222. (_mqtt_callbacks[i])(MQTT_CONNECT_EVENT, NULL, NULL);
  223. }
  224. }
  225. void _mqttOnDisconnect() {
  226. DEBUG_MSG_P(PSTR("[MQTT] Disconnected!\n"));
  227. // Send disconnect event to subscribers
  228. for (unsigned char i = 0; i < _mqtt_callbacks.size(); i++) {
  229. (_mqtt_callbacks[i])(MQTT_DISCONNECT_EVENT, NULL, NULL);
  230. }
  231. }
  232. void _mqttOnMessage(char* topic, char* payload, unsigned int len) {
  233. if (len == 0) return;
  234. char message[len + 1];
  235. strlcpy(message, (char *) payload, len + 1);
  236. #if MQTT_SKIP_RETAINED
  237. if (millis() - _mqtt_connected_at < MQTT_SKIP_TIME) {
  238. DEBUG_MSG_P(PSTR("[MQTT] Received %s => %s - SKIPPED\n"), topic, message);
  239. return;
  240. }
  241. #endif
  242. DEBUG_MSG_P(PSTR("[MQTT] Received %s => %s\n"), topic, message);
  243. // Send message event to subscribers
  244. for (unsigned char i = 0; i < _mqtt_callbacks.size(); i++) {
  245. (_mqtt_callbacks[i])(MQTT_MESSAGE_EVENT, topic, message);
  246. }
  247. }
  248. void mqttEnabled(bool status) {
  249. _mqtt_enabled = status;
  250. setSetting("mqttEnabled", status ? 1 : 0);
  251. }
  252. bool mqttEnabled() {
  253. return _mqtt_enabled;
  254. }
  255. void mqttConnect() {
  256. // Do not connect if disabled
  257. if (!_mqtt_enabled) return;
  258. // Do not connect if already connected
  259. if (_mqtt.connected()) return;
  260. // Check reconnect interval
  261. static unsigned long last = 0;
  262. if (millis() - last < _mqtt_reconnect_delay) return;
  263. last = millis();
  264. // Increase the reconnect delay
  265. _mqtt_reconnect_delay += MQTT_RECONNECT_DELAY_STEP;
  266. if (_mqtt_reconnect_delay > MQTT_RECONNECT_DELAY_MAX) {
  267. _mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MAX;
  268. }
  269. String h = getSetting("mqttServer", MQTT_SERVER);
  270. #if MDNS_CLIENT_SUPPORT
  271. h = mdnsResolve(h);
  272. #endif
  273. char * host = strdup(h.c_str());
  274. unsigned int port = getSetting("mqttPort", MQTT_PORT).toInt();
  275. if (_mqtt_user) free(_mqtt_user);
  276. if (_mqtt_pass) free(_mqtt_pass);
  277. if (_mqtt_will) free(_mqtt_will);
  278. if (_mqtt_clientid) free(_mqtt_clientid);
  279. _mqtt_user = strdup(getSetting("mqttUser", MQTT_USER).c_str());
  280. _mqtt_pass = strdup(getSetting("mqttPassword", MQTT_PASS).c_str());
  281. _mqtt_will = strdup((_mqtt_topic + MQTT_TOPIC_STATUS).c_str());
  282. _mqtt_clientid = strdup(getSetting("mqttClientID", getIdentifier()).c_str());
  283. DEBUG_MSG_P(PSTR("[MQTT] Connecting to broker at %s:%d\n"), host, port);
  284. #if MQTT_USE_ASYNC
  285. _mqtt.setServer(host, port);
  286. _mqtt.setClientId(_mqtt_clientid);
  287. _mqtt.setKeepAlive(_mqtt_keepalive);
  288. _mqtt.setCleanSession(false);
  289. _mqtt.setWill(_mqtt_will, _mqtt_qos, _mqtt_retain, "0");
  290. if ((strlen(_mqtt_user) > 0) && (strlen(_mqtt_pass) > 0)) {
  291. DEBUG_MSG_P(PSTR("[MQTT] Connecting as user %s\n"), _mqtt_user);
  292. _mqtt.setCredentials(_mqtt_user, _mqtt_pass);
  293. }
  294. #if ASYNC_TCP_SSL_ENABLED
  295. bool secure = getSetting("mqttUseSSL", MQTT_SSL_ENABLED).toInt() == 1;
  296. _mqtt.setSecure(secure);
  297. if (secure) {
  298. DEBUG_MSG_P(PSTR("[MQTT] Using SSL\n"));
  299. unsigned char fp[20] = {0};
  300. if (sslFingerPrintArray(getSetting("mqttFP", MQTT_SSL_FINGERPRINT).c_str(), fp)) {
  301. _mqtt.addServerFingerprint(fp);
  302. } else {
  303. DEBUG_MSG_P(PSTR("[MQTT] Wrong fingerprint\n"));
  304. }
  305. }
  306. #endif // ASYNC_TCP_SSL_ENABLED
  307. DEBUG_MSG_P(PSTR("[MQTT] Client ID: %s\n"), _mqtt_clientid);
  308. DEBUG_MSG_P(PSTR("[MQTT] QoS: %d\n"), _mqtt_qos);
  309. DEBUG_MSG_P(PSTR("[MQTT] Retain flag: %d\n"), _mqtt_retain ? 1 : 0);
  310. DEBUG_MSG_P(PSTR("[MQTT] Will topic: %s\n"), _mqtt_will);
  311. _mqtt.connect();
  312. #else // not MQTT_USE_ASYNC
  313. bool response = true;
  314. #if ASYNC_TCP_SSL_ENABLED
  315. bool secure = getSetting("mqttUseSSL", MQTT_SSL_ENABLED).toInt() == 1;
  316. if (secure) {
  317. DEBUG_MSG_P(PSTR("[MQTT] Using SSL\n"));
  318. if (_mqtt_client_secure.connect(host, port)) {
  319. char fp[60] = {0};
  320. if (sslFingerPrintChar(getSetting("mqttFP", MQTT_SSL_FINGERPRINT).c_str(), fp)) {
  321. if (_mqtt_client_secure.verify(fp, host)) {
  322. _mqtt.setClient(_mqtt_client_secure);
  323. } else {
  324. DEBUG_MSG_P(PSTR("[MQTT] Invalid fingerprint\n"));
  325. response = false;
  326. }
  327. _mqtt_client_secure.stop();
  328. yield();
  329. } else {
  330. DEBUG_MSG_P(PSTR("[MQTT] Wrong fingerprint\n"));
  331. response = false;
  332. }
  333. } else {
  334. DEBUG_MSG_P(PSTR("[MQTT] Client connection failed\n"));
  335. response = false;
  336. }
  337. } else {
  338. _mqtt.setClient(_mqtt_client);
  339. }
  340. #else // not ASYNC_TCP_SSL_ENABLED
  341. _mqtt.setClient(_mqtt_client);
  342. #endif // ASYNC_TCP_SSL_ENABLED
  343. if (response) {
  344. _mqtt.setServer(host, port);
  345. if ((strlen(_mqtt_user) > 0) && (strlen(_mqtt_pass) > 0)) {
  346. DEBUG_MSG_P(PSTR("[MQTT] Connecting as user %s\n"), _mqtt_user);
  347. response = _mqtt.connect(_mqtt_clientid, _mqtt_user, _mqtt_pass, _mqtt_will, _mqtt_qos, _mqtt_retain, "0");
  348. } else {
  349. response = _mqtt.connect(_mqtt_clientid, _mqtt_will, _mqtt_qos, _mqtt_retain, "0");
  350. }
  351. DEBUG_MSG_P(PSTR("[MQTT] Client ID: %s\n"), _mqtt_clientid);
  352. DEBUG_MSG_P(PSTR("[MQTT] QoS: %d\n"), _mqtt_qos);
  353. DEBUG_MSG_P(PSTR("[MQTT] Retain flag: %d\n"), _mqtt_retain ? 1 : 0);
  354. DEBUG_MSG_P(PSTR("[MQTT] Will topic: %s\n"), _mqtt_will);
  355. }
  356. if (response) {
  357. _mqttOnConnect();
  358. } else {
  359. DEBUG_MSG_P(PSTR("[MQTT] Connection failed\n"));
  360. }
  361. #endif // MQTT_USE_ASYNC
  362. free(host);
  363. }
  364. void mqttConfigure() {
  365. // Replace identifier
  366. _mqtt_topic = getSetting("mqttTopic", MQTT_TOPIC);
  367. _mqtt_topic.replace("{identifier}", getSetting("hostname"));
  368. if (!_mqtt_topic.endsWith("/")) _mqtt_topic = _mqtt_topic + "/";
  369. // Getters and setters
  370. _mqtt_setter = getSetting("mqttSetter", MQTT_USE_SETTER);
  371. _mqtt_getter = getSetting("mqttGetter", MQTT_USE_GETTER);
  372. _mqtt_forward = !_mqtt_getter.equals(_mqtt_setter);
  373. // MQTT options
  374. _mqtt_qos = getSetting("mqttQoS", MQTT_QOS).toInt();
  375. _mqtt_retain = getSetting("mqttRetain", MQTT_RETAIN).toInt() == 1;
  376. _mqtt_keepalive = getSetting("mqttKeep", MQTT_KEEPALIVE).toInt();
  377. if (getSetting("mqttClientID").length() == 0) delSetting("mqttClientID");
  378. // Enable
  379. if (getSetting("mqttServer", MQTT_SERVER).length() == 0) {
  380. mqttEnabled(false);
  381. } else {
  382. _mqtt_enabled = getSetting("mqttEnabled", MQTT_ENABLED).toInt() == 1;
  383. }
  384. _mqtt_use_json = (getSetting("mqttUseJson", MQTT_USE_JSON).toInt() == 1);
  385. _mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN;
  386. }
  387. void mqttSetBroker(IPAddress ip, unsigned int port) {
  388. setSetting("mqttServer", ip.toString());
  389. setSetting("mqttPort", port);
  390. mqttEnabled(MQTT_AUTOCONNECT);
  391. }
  392. void mqttSetBrokerIfNone(IPAddress ip, unsigned int port) {
  393. if (!hasSetting("mqttServer")) mqttSetBroker(ip, port);
  394. }
  395. void mqttSetup() {
  396. DEBUG_MSG_P(PSTR("[MQTT] Async %s, SSL %s, Autoconnect %s\n"),
  397. MQTT_USE_ASYNC ? "ENABLED" : "DISABLED",
  398. ASYNC_TCP_SSL_ENABLED ? "ENABLED" : "DISABLED",
  399. MQTT_AUTOCONNECT ? "ENABLED" : "DISABLED"
  400. );
  401. #if MQTT_USE_ASYNC
  402. _mqtt.onConnect([](bool sessionPresent) {
  403. _mqttOnConnect();
  404. });
  405. _mqtt.onDisconnect([](AsyncMqttClientDisconnectReason reason) {
  406. if (reason == AsyncMqttClientDisconnectReason::TCP_DISCONNECTED) {
  407. DEBUG_MSG_P(PSTR("[MQTT] TCP Disconnected\n"));
  408. }
  409. if (reason == AsyncMqttClientDisconnectReason::MQTT_IDENTIFIER_REJECTED) {
  410. DEBUG_MSG_P(PSTR("[MQTT] Identifier Rejected\n"));
  411. }
  412. if (reason == AsyncMqttClientDisconnectReason::MQTT_SERVER_UNAVAILABLE) {
  413. DEBUG_MSG_P(PSTR("[MQTT] Server unavailable\n"));
  414. }
  415. if (reason == AsyncMqttClientDisconnectReason::MQTT_MALFORMED_CREDENTIALS) {
  416. DEBUG_MSG_P(PSTR("[MQTT] Malformed credentials\n"));
  417. }
  418. if (reason == AsyncMqttClientDisconnectReason::MQTT_NOT_AUTHORIZED) {
  419. DEBUG_MSG_P(PSTR("[MQTT] Not authorized\n"));
  420. }
  421. #if ASYNC_TCP_SSL_ENABLED
  422. if (reason == AsyncMqttClientDisconnectReason::TLS_BAD_FINGERPRINT) {
  423. DEBUG_MSG_P(PSTR("[MQTT] Bad fingerprint\n"));
  424. }
  425. #endif
  426. _mqttOnDisconnect();
  427. });
  428. _mqtt.onMessage([](char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
  429. _mqttOnMessage(topic, payload, len);
  430. });
  431. _mqtt.onSubscribe([](uint16_t packetId, uint8_t qos) {
  432. DEBUG_MSG_P(PSTR("[MQTT] Subscribe ACK for PID %d\n"), packetId);
  433. });
  434. _mqtt.onPublish([](uint16_t packetId) {
  435. DEBUG_MSG_P(PSTR("[MQTT] Publish ACK for PID %d\n"), packetId);
  436. });
  437. #else // not MQTT_USE_ASYNC
  438. _mqtt.setCallback([](char* topic, byte* payload, unsigned int length) {
  439. _mqttOnMessage(topic, (char *) payload, length);
  440. });
  441. #endif // MQTT_USE_ASYNC
  442. mqttConfigure();
  443. mqttRegister(_mqttCallback);
  444. #if WEB_SUPPORT
  445. wsOnSendRegister(_mqttWebSocketOnSend);
  446. wsOnAfterParseRegister(mqttConfigure);
  447. #endif
  448. }
  449. void mqttLoop() {
  450. if (WiFi.status() != WL_CONNECTED) return;
  451. #if MQTT_USE_ASYNC
  452. mqttConnect();
  453. #else // not MQTT_USE_ASYNC
  454. if (_mqtt.connected()) {
  455. _mqtt.loop();
  456. } else {
  457. if (_mqtt_connected) {
  458. _mqttOnDisconnect();
  459. _mqtt_connected = false;
  460. }
  461. mqttConnect();
  462. }
  463. #endif
  464. }
  465. #endif // MQTT_SUPPORT