You've already forked Adafruit_MQTT_Library
mirror of
https://github.com/adafruit/Adafruit_MQTT_Library.git
synced 2025-12-19 20:02:29 +03:00
feedback fixes
Thx @brentru . Changes have been made and tested. - rev library 2.6.1 -> 2.6.2 - move setup() / loop() to bottom - drop prototypes - -10 safety margin added as #define
This commit is contained in:
@@ -42,10 +42,23 @@
|
|||||||
#define ESP32_GPIO0 -1
|
#define ESP32_GPIO0 -1
|
||||||
|
|
||||||
/*************************** Timing / Params ***************************/
|
/*************************** Timing / Params ***************************/
|
||||||
|
// MQTT KeepAlive interval (seconds). The client must send at least one
|
||||||
|
// packet (e.g., PINGREQ) within this interval or the MQTT server will
|
||||||
|
// disconnect the session.
|
||||||
#define AIRLIFT_KEEPALIVE 30
|
#define AIRLIFT_KEEPALIVE 30
|
||||||
|
|
||||||
|
// Safety margin (seconds) to subtract before sending a manual PING.
|
||||||
|
// AirLift/NINA-FW firmware does not reliably handle automatic MQTT
|
||||||
|
// KeepAlive packets, and real-world testing shows a 10 second margin
|
||||||
|
// prevents premature disconnects (“No socket available”).
|
||||||
|
#define KEEPALIVE_SAFETY_MARGIN 10
|
||||||
|
|
||||||
#define MAX_MQTT_RETRIES 5
|
#define MAX_MQTT_RETRIES 5
|
||||||
#define SUBSCRIBE_WAIT_MS 1500
|
#define SUBSCRIBE_WAIT_MS 1500
|
||||||
#define PING_PERIOD_MS ((AIRLIFT_KEEPALIVE - 10) * 1000)
|
|
||||||
|
// Time (milliseconds) between manual MQTT PING operations.
|
||||||
|
#define PING_PERIOD_MS \
|
||||||
|
((AIRLIFT_KEEPALIVE - KEEPALIVE_SAFETY_MARGIN) * 1000)
|
||||||
|
|
||||||
/*************************** MQTT Objects ******************************/
|
/*************************** MQTT Objects ******************************/
|
||||||
WiFiClient client;
|
WiFiClient client;
|
||||||
@@ -65,43 +78,6 @@ Adafruit_MQTT_Subscribe time_subscription =
|
|||||||
unsigned long ping_clk = 0;
|
unsigned long ping_clk = 0;
|
||||||
long ping_cnt = 0;
|
long ping_cnt = 0;
|
||||||
|
|
||||||
/*************************** Function Prototypes ***********************/
|
|
||||||
void initWiFi();
|
|
||||||
void MQTT_connect();
|
|
||||||
void MQTT_ping();
|
|
||||||
void printCurrentNet();
|
|
||||||
void printWiFiData();
|
|
||||||
void printMacAddress(byte mac[]);
|
|
||||||
|
|
||||||
/*************************** Setup *************************************/
|
|
||||||
void setup() {
|
|
||||||
Serial.begin(115200);
|
|
||||||
while (!Serial) delay(10);
|
|
||||||
|
|
||||||
Serial.println("MQTT AirLift Subscribe + KeepAlive Example");
|
|
||||||
|
|
||||||
initWiFi();
|
|
||||||
|
|
||||||
mqtt.setKeepAliveInterval(AIRLIFT_KEEPALIVE);
|
|
||||||
mqtt.subscribe(&time_subscription);
|
|
||||||
|
|
||||||
MQTT_connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************** Main Loop *********************************/
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
MQTT_ping();
|
|
||||||
|
|
||||||
Adafruit_MQTT_Subscribe *subscription =
|
|
||||||
mqtt.readSubscription(SUBSCRIBE_WAIT_MS);
|
|
||||||
|
|
||||||
if (subscription == &time_subscription) {
|
|
||||||
Serial.print("TIME FEED: ");
|
|
||||||
Serial.println((char *)time_subscription.lastread);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************** MQTT Connect ******************************/
|
/*************************** MQTT Connect ******************************/
|
||||||
void MQTT_connect() {
|
void MQTT_connect() {
|
||||||
|
|
||||||
@@ -241,3 +217,32 @@ void printMacAddress(byte mac[]) {
|
|||||||
}
|
}
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*************************** Setup *************************************/
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) delay(10);
|
||||||
|
|
||||||
|
Serial.println("MQTT AirLift Subscribe + KeepAlive Example");
|
||||||
|
|
||||||
|
initWiFi();
|
||||||
|
|
||||||
|
mqtt.setKeepAliveInterval(AIRLIFT_KEEPALIVE);
|
||||||
|
mqtt.subscribe(&time_subscription);
|
||||||
|
|
||||||
|
MQTT_connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************** Main Loop *********************************/
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
MQTT_ping();
|
||||||
|
|
||||||
|
Adafruit_MQTT_Subscribe *subscription =
|
||||||
|
mqtt.readSubscription(SUBSCRIBE_WAIT_MS);
|
||||||
|
|
||||||
|
if (subscription == &time_subscription) {
|
||||||
|
Serial.print("TIME FEED: ");
|
||||||
|
Serial.println((char *)time_subscription.lastread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name=Adafruit MQTT Library
|
name=Adafruit MQTT Library
|
||||||
version=2.6.1
|
version=2.6.2
|
||||||
author=Adafruit
|
author=Adafruit
|
||||||
maintainer=Adafruit <info@adafruit.com>
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
sentence=MQTT library that supports the FONA, ESP8266, ESP32, Yun, and generic Arduino Client hardware.
|
sentence=MQTT library that supports the FONA, ESP8266, ESP32, Yun, and generic Arduino Client hardware.
|
||||||
|
|||||||
Reference in New Issue
Block a user