Skip to content

Conversation

@mikeysklar
Copy link
Contributor

@mikeysklar mikeysklar commented Nov 24, 2025

This approach stabilizes long-running MQTT connections on AirLift boards and prevents the “No socket available” disconnect condition that users are encountering.

  • Manual KeepAlive interval control
  • A scheduled MQTT PING loop
  • Connection retry logic

related links:

tested on:

┌──────────────────────────────┬────────────────────────────────────┐
│Component/Library             │Version/Path                        │
├──────────────────────────────┼────────────────────────────────────┤
│Board/Platform                │Adafruit SAMD (Feather M4)          │
│Arduino IDE                   │2.3.6                               │
│Board Core                    │adafruit:samd 1.7.16                │
│Adafruit Zero DMA Library     │1.1.3                               │
│Adafruit-WiFiNINA             │1.6.0 (Airlift fork)                │
│Adafruit MQTT Library         │2.6.1                               │
│nina-fw Firmware              │KeepAlive issue present             │
└──────────────────────────────┴────────────────────────────────────┘

credit to Bruce Conrad from above forum thread for code that demonstrates keepalive issue and workaround being used here.

This approach stabilizes long-running MQTT connections on AirLift boards and prevents the “No socket available” disconnect condition that users are encountering.
@mikeysklar
Copy link
Contributor Author

@tyeth - I've tested this example code and it works. I'll work on updating the nina-fw to avoid the issue entirely, but many users will not be updating the Airlift Firmware so this work around will be helpful.

@brentru brentru self-requested a review November 24, 2025 14:14
Copy link
Member

@brentru brentru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikeysklar Overall, this is great. Proper SPI configuration for AirLift and a lot of print() statements for diagnostics will help people using AMQTT with airlift.

I have some feedback, also could you update the library version within library.properties so we can release this after approved?

Comment on lines 68 to 75
/*************************** Function Prototypes ***********************/
void initWiFi();
void MQTT_connect();
void MQTT_ping();
void printCurrentNet();
void printWiFiData();
void printMacAddress(byte mac[]);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but more commonly these functions would be implemented before setup() and loop(), not prototypes.

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
Copy link
Member

@brentru brentru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikeysklar Approved and merging in

@brentru brentru merged commit 473e760 into adafruit:master Nov 24, 2025
1 check passed
@mikeysklar mikeysklar deleted the mqtt-keep-alive branch November 24, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants