@alteriom/painlessmesh 1.8.10 → 1.8.11

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.
@@ -806,10 +806,11 @@ class Mesh : public painlessmesh::Mesh<Connection> {
806
806
 
807
807
  // Also send bridge status when new nodes connect so they can discover the bridge immediately
808
808
  // Send directly to the new node to ensure delivery, independent of time sync
809
- this->newConnectionCallbacks.push_back([this](uint32_t nodeId) {
810
- Log(CONNECTION, "New node %u connected, sending bridge status directly\n", nodeId);
809
+ // Using changedConnectionCallbacks instead of newConnectionCallbacks ensures routing is ready
810
+ this->changedConnectionCallbacks.push_back([this](uint32_t nodeId) {
811
+ Log(CONNECTION, "Node %u connection changed, sending bridge status directly\n", nodeId);
811
812
 
812
- // Small delay to ensure connection is ready, then send directly to the new node
813
+ // Small delay to ensure connection is fully stable, then send directly to the new node
813
814
  // This avoids issues with time sync blocking broadcast messages
814
815
  this->addTask(500, TASK_ONCE, [this, nodeId]() {
815
816
  // Create bridge status message
@@ -837,7 +838,7 @@ class Mesh : public painlessmesh::Mesh<Connection> {
837
838
  Log(CONNECTION, "Sending bridge status directly to node %u (Internet: %s)\n",
838
839
  nodeId, hasInternet ? "YES" : "NO");
839
840
 
840
- // Send directly to the new node, bypassing broadcast routing
841
+ // Send directly to the new node using routing table (which is now ready)
841
842
  this->sendSingle(nodeId, msg);
842
843
  });
843
844
  });
@@ -5,7 +5,7 @@
5
5
  * @file painlessMesh.h
6
6
  * @brief Main header file for Alteriom painlessMesh library
7
7
  *
8
- * @version 1.8.10
8
+ * @version 1.8.11
9
9
  * @date 2025-11-18
10
10
  *
11
11
  * painlessMesh is a user-friendly library for creating mesh networks with
@@ -1,4 +1,4 @@
1
- #ifndef _PAINLESS_MESH_BUFFER_HPP_
1
+ #ifndef _PAINLESS_MESH_BUFFER_HPP_
2
2
  #define _PAINLESS_MESH_BUFFER_HPP_
3
3
 
4
4
  #include <list>
@@ -37,7 +37,7 @@ class ReceiveBuffer {
37
37
  do {
38
38
  auto len = strnlen(data_ptr, length);
39
39
  do {
40
- auto read_len = std::min(len, buf.length);
40
+ auto read_len = (std::min)(len, buf.length);
41
41
  memcpy(buf.buffer, data_ptr, read_len);
42
42
  buf.buffer[read_len] = '\0';
43
43
  auto newBuffer = T(buf.buffer);
@@ -179,7 +179,7 @@ class SentBuffer {
179
179
  else
180
180
  // String.toCharArray automatically turns the last character into
181
181
  // a \0, we need the extra space to deal with that annoyance
182
- return std::min(buffer_length - 1, msg->length() + 1);
182
+ return (std::min)(buffer_length - 1, msg->length() + 1);
183
183
  }
184
184
 
185
185
  /**
@@ -1,4 +1,4 @@
1
- #ifndef _PAINLESS_MESH_MESH_HPP_
1
+ #ifndef _PAINLESS_MESH_MESH_HPP_
2
2
  #define _PAINLESS_MESH_MESH_HPP_
3
3
 
4
4
  #include <vector>
@@ -428,7 +428,7 @@ class Mesh : public ntp::MeshTime, public plugin::PackageHandler<T> {
428
428
  /** Set a callback routine for any messages that are addressed to this node.
429
429
  *
430
430
  * Every time this node receives a message, this callback routine will the
431
- * called. “from” is the id of the original sender of the message, and “msg”
431
+ * called. “from” is the id of the original sender of the message, and “msg”
432
432
  * is a string that contains the message. The message can be anything. A
433
433
  * JSON, some other text string, or binary data.
434
434
  *
@@ -1861,7 +1861,7 @@ class Mesh : public ntp::MeshTime, public plugin::PackageHandler<T> {
1861
1861
  * // === painlessMesh Diagnostics ===
1862
1862
  * // Mode: Regular Node
1863
1863
  * // Mesh: ProductionMesh (25 nodes)
1864
- * // Bridge: 123456789 (RSSI: -42 dBm, Internet: ✓)
1864
+ * // Bridge: 123456789 (RSSI: -42 dBm, Internet: ✓)
1865
1865
  * // Queue: 3 messages (2 CRITICAL, 1 NORMAL)
1866
1866
  * // Uptime: 02:15:33
1867
1867
  * // Last Election: 00:45:12 ago (Winner: 123456789)
@@ -1889,7 +1889,7 @@ class Mesh : public ntp::MeshTime, public plugin::PackageHandler<T> {
1889
1889
  if (primaryBridge != nullptr) {
1890
1890
  report += "Bridge: " + TSTRING(std::to_string(primaryBridge->nodeId).c_str());
1891
1891
  report += " (RSSI: " + TSTRING(std::to_string(primaryBridge->routerRSSI).c_str()) + " dBm";
1892
- report += ", Internet: " + TSTRING(primaryBridge->internetConnected ? "✓" : "✗") + ")\n";
1892
+ report += ", Internet: " + TSTRING(primaryBridge->internetConnected ? "✓" : "✗") + ")\n";
1893
1893
  } else {
1894
1894
  report += "Bridge: None available\n";
1895
1895
  }
@@ -1960,6 +1960,7 @@ class Mesh : public ntp::MeshTime, public plugin::PackageHandler<T> {
1960
1960
  isExternalScheduler = true;
1961
1961
  }
1962
1962
 
1963
+ public: // Windows MSVC: router functions need access
1963
1964
  void startTimeSync(std::shared_ptr<T> conn) {
1964
1965
  using namespace logger;
1965
1966
  Log(S_TIME, "startTimeSync(): from %u with %u\n", this->nodeId,
@@ -2033,6 +2034,7 @@ class Mesh : public ntp::MeshTime, public plugin::PackageHandler<T> {
2033
2034
  [](const std::shared_ptr<T> &conn) { return !conn->connected(); });
2034
2035
  }
2035
2036
 
2037
+ public: // Windows MSVC: TCP lambdas need access to droppedConnectionCallbacks
2036
2038
  // Callback functions
2037
2039
  callback::List<uint32_t> newConnectionCallbacks;
2038
2040
  callback::List<uint32_t, bool> droppedConnectionCallbacks;
@@ -2056,6 +2058,8 @@ class Mesh : public ntp::MeshTime, public plugin::PackageHandler<T> {
2056
2058
 
2057
2059
  Scheduler *mScheduler;
2058
2060
 
2061
+ public: // Windows MSVC: lambdas in friend functions need public access
2062
+
2059
2063
  /**
2060
2064
  * Wrapper function for ESP32 semaphore function
2061
2065
  *
@@ -143,8 +143,8 @@ public:
143
143
  // Check for state change
144
144
  checkStateChange();
145
145
 
146
- Log(logger::GENERAL, "MessageQueue: Enqueued message #%u (priority=%d, size=%u/%u)\n",
147
- msgId, priority, messages.size(), maxQueueSize);
146
+ Log(logger::GENERAL, "MessageQueue: Enqueued message #%u (priority=%d, size=%zu/%zu)\n",
147
+ msgId, priority, messages.size(), (size_t)maxQueueSize);
148
148
 
149
149
  return msgId;
150
150
  }
@@ -167,7 +167,7 @@ public:
167
167
  updatePriorityStats();
168
168
  checkStateChange();
169
169
 
170
- Log(logger::GENERAL, "MessageQueue: Removed message #%u (size=%u)\n",
170
+ Log(logger::GENERAL, "MessageQueue: Removed message #%u (size=%zu)\n",
171
171
  messageId, messages.size());
172
172
  return true;
173
173
  }
@@ -1,4 +1,4 @@
1
- #ifndef _PAINLESS_MESH_NTP_HPP_
1
+ #ifndef _PAINLESS_MESH_NTP_HPP_
2
2
  #define _PAINLESS_MESH_NTP_HPP_
3
3
 
4
4
  #ifndef TIME_SYNC_INTERVAL
@@ -42,7 +42,7 @@ class MeshTime {
42
42
  */
43
43
  uint32_t getNodeTime() { return micros() + timeOffset; }
44
44
 
45
- protected:
45
+ public: // Windows MSVC: friend functions need access to timeOffset
46
46
  uint32_t timeOffset = 0;
47
47
  };
48
48
 
@@ -1,4 +1,4 @@
1
- #ifndef _PAINLESS_MESH_ROUTER_HPP_
1
+ #ifndef _PAINLESS_MESH_ROUTER_HPP_
2
2
  #define _PAINLESS_MESH_ROUTER_HPP_
3
3
 
4
4
  #include <algorithm>
@@ -235,14 +235,14 @@ void routePackage(layout::Layout<T> layout, std::shared_ptr<T> connection,
235
235
  // Base capacity: message length + overhead for JSON structure
236
236
  // Each nesting level adds overhead for pointers and metadata
237
237
  size_t calculatedCapacity = pkg.length() +
238
- JSON_OBJECT_SIZE(10) * std::max(nestingDepth, size_t(1)) +
238
+ JSON_OBJECT_SIZE(10) * (std::max)(nestingDepth, size_t(1)) +
239
239
  512; // Additional buffer for strings and padding
240
240
  #endif
241
241
 
242
242
  // Cap at 8KB for safety on ESP8266 (which has ~80KB total heap)
243
243
  // Messages larger than this should be rejected
244
244
  constexpr size_t MAX_MESSAGE_CAPACITY = 8192;
245
- size_t capacity = std::min(calculatedCapacity, MAX_MESSAGE_CAPACITY);
245
+ size_t capacity = (std::min)(calculatedCapacity, MAX_MESSAGE_CAPACITY);
246
246
 
247
247
  auto variant = std::make_shared<protocol::Variant>(pkg, capacity);
248
248
 
@@ -330,7 +330,7 @@ void handleNodeSync(T& mesh, protocol::NodeTree newTree,
330
330
  [&mesh, nodeId]() { mesh.changedConnectionCallbacks.execute(nodeId); });
331
331
  } else {
332
332
  conn->nodeSyncTask.delay();
333
- mesh.stability += std::min(1000 - mesh.stability, (size_t)25);
333
+ mesh.stability += (std::min)(1000 - mesh.stability, (size_t)25);
334
334
  }
335
335
  }
336
336