@alteriom/painlessmesh 1.9.6 → 1.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,8 +5,8 @@
5
5
  * @file painlessMesh.h
6
6
  * @brief Main header file for Alteriom painlessMesh library
7
7
  *
8
- * @version 1.8.13
9
- * @date 2025-11-20
8
+ * @version 1.9.7
9
+ * @date 2025-12-13
10
10
  *
11
11
  * painlessMesh is a user-friendly library for creating mesh networks with
12
12
  * ESP8266 and ESP32 devices. This Alteriom fork includes additional packages
@@ -233,10 +233,19 @@ void ICACHE_FLASH_ATTR StationScan::connectToAP() {
233
233
  Log(CONNECTION,
234
234
  "connectToAP(): Restarting AP from channel %d to channel %d\n",
235
235
  oldChannel, detectedChannel);
236
- WiFi.softAPdisconnect(false);
237
- delay(100);
236
+
237
+ // Disconnect AP and allow WiFi stack to fully reset
238
+ // Using true parameter ensures DHCP server is properly stopped
239
+ WiFi.softAPdisconnect(true);
240
+ delay(200); // Increased delay to ensure complete WiFi stack reset
241
+
238
242
  // Call apInit via friend class access (StationScan is friend of wifi::Mesh)
239
243
  mesh->apInit(mesh->getNodeId());
244
+
245
+ // Additional stabilization delay after AP restart
246
+ // This ensures DHCP server is fully initialized before clients connect
247
+ delay(100);
248
+
240
249
  Log(CONNECTION, "connectToAP(): AP restarted on channel %d\n", detectedChannel);
241
250
  }
242
251
  // Reset counter only when mesh is found on a new channel
@@ -3134,7 +3134,11 @@ class Mesh : public ntp::MeshTime, public plugin::PackageHandler<T> {
3134
3134
  using namespace logger;
3135
3135
  Log(CONNECTION, "eraseClosedConnections():\n");
3136
3136
  this->subs.remove_if(
3137
- [](const std::shared_ptr<T> &conn) { return !conn->connected(); });
3137
+ [](const std::shared_ptr<T> &conn) {
3138
+ // Null check for safety - should never happen but prevents crashes
3139
+ if (!conn) return true;
3140
+ return !conn->connected();
3141
+ });
3138
3142
  }
3139
3143
 
3140
3144
  public: // Windows MSVC: TCP lambdas need access to droppedConnectionCallbacks
@@ -142,7 +142,11 @@ void connect(AsyncClient &client, IPAddress ip, uint16_t port, M &mesh,
142
142
  TCP_CONNECT_MAX_RETRIES + 1);
143
143
  delete client;
144
144
  #endif
145
- mesh.droppedConnectionCallbacks.execute(0, true);
145
+ // Defer callback execution to avoid crashes in error handler context
146
+ // Execute callbacks after semaphore is released and error handler completes
147
+ mesh.addTask([&mesh]() {
148
+ mesh.droppedConnectionCallbacks.execute(0, true);
149
+ });
146
150
  mesh.semaphoreGive();
147
151
  }
148
152
  });