@alteriom/painlessmesh 1.9.19 → 1.10.0

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +168 -0
  2. package/README.md +102 -63
  3. package/RELEASE_GUIDE.md +147 -8
  4. package/examples/alteriom/README.md +4 -4
  5. package/examples/alteriom/alteriom_custom_package_template.hpp +320 -0
  6. package/examples/alteriom/alteriom_sensor_package.hpp +1 -1
  7. package/examples/alteriom/mppt_example/alteriom_mppt_example.ino +208 -0
  8. package/examples/bridge_failover/bridge_failover.ino +17 -0
  9. package/examples/sendToInternet/CMakeLists.txt +54 -0
  10. package/examples/sendToInternet/PC_NODE_README.md +517 -0
  11. package/examples/sendToInternet/README.md +39 -1
  12. package/examples/sendToInternet/build.sh +153 -0
  13. package/examples/sendToInternet/mock_server_test.ino +361 -0
  14. package/examples/sendToInternet/pc_mesh_node.cpp +361 -0
  15. package/examples/tcpRetryConfig/README.md +110 -0
  16. package/examples/tcpRetryConfig/platformio.ini +26 -0
  17. package/examples/tcpRetryConfig/tcpRetryConfig.ino +154 -0
  18. package/keywords.txt +3 -0
  19. package/library.json +4 -1
  20. package/library.properties +1 -1
  21. package/package.json +3 -3
  22. package/src/AlteriomPainlessMesh.h +6 -14
  23. package/src/arduino/wifi.hpp +352 -114
  24. package/src/connection.cpp +10 -0
  25. package/src/painlessMesh.h +2 -15
  26. package/src/painlessTaskOptions.h +9 -0
  27. package/src/painlessmesh/buffer.hpp +4 -1
  28. package/src/painlessmesh/configuration.hpp +13 -2
  29. package/src/painlessmesh/connection.hpp +36 -21
  30. package/src/painlessmesh/gateway.hpp +0 -1061
  31. package/src/painlessmesh/mesh.hpp +102 -107
  32. package/src/painlessmesh/message_queue.hpp +25 -15
  33. package/src/painlessmesh/metrics.hpp +2 -262
  34. package/src/painlessmesh/plugin.hpp +27 -5
  35. package/src/painlessmesh/tcp.hpp +158 -29
  36. package/src/painlessmesh/validation.hpp +0 -143
  37. package/docs/README.md +0 -132
  38. package/docs/alteriom/overview.md +0 -531
  39. package/docs/api/core-api.md +0 -607
  40. package/docs/api/shared-gateway.md +0 -1207
  41. package/docs/architecture/mesh-architecture.md +0 -399
  42. package/docs/architecture/plugin-system.md +0 -517
  43. package/docs/getting-started/arduino-manual-install.md +0 -313
  44. package/docs/getting-started/first-mesh.md +0 -410
  45. package/docs/getting-started/installation.md +0 -275
  46. package/docs/getting-started/quickstart.md +0 -158
  47. package/docs/troubleshooting/common-issues.md +0 -679
  48. package/docs/troubleshooting/debugging.md +0 -455
  49. package/docs/troubleshooting/external-device-connection.md +0 -283
  50. package/docs/troubleshooting/faq.md +0 -574
  51. package/docs/tutorials/basic-examples.md +0 -718
@@ -0,0 +1,517 @@
1
+ # PC Mesh Node - Testing sendToInternet() from Regular Node Through Bridge
2
+
3
+ ## Overview
4
+
5
+ This example provides a **PC-based mesh node** that can join a painlessMesh network with ESP32/ESP8266 devices and test the `sendToInternet()` functionality as a **regular node** (not a bridge).
6
+
7
+ ### The Problem This Solves
8
+
9
+ Previous examples (`mock_server_test.ino`) tested the bridge making HTTP requests directly, but did **NOT** test the complete flow:
10
+
11
+ ```
12
+ Regular Node → Mesh Network → Bridge → Internet → Bridge → Mesh Network → Regular Node
13
+ ```
14
+
15
+ The **PC Mesh Node** solution allows you to:
16
+ - ✅ Test from a **regular mesh node** that routes Internet requests through a bridge
17
+ - ✅ Verify routing **through the bridge** works correctly
18
+ - ✅ Debug issues on a PC with full development tools
19
+ - ✅ Run on **Windows, Linux, or macOS**
20
+ - ✅ No need for multiple ESP32/ESP8266 devices for testing
21
+
22
+ ## Architecture
23
+
24
+ ```
25
+ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
26
+ │ PC Mesh Node │ │ ESP32 Bridge │ │ Mock HTTP │
27
+ │ (Regular Node) │◄────────►│ (Has WiFi) │◄────────►│ Server │
28
+ │ WiFi/Ethernet │ Mesh │ Router Access │ HTTP │ localhost:8080 │
29
+ └──────────────────┘ └──────────────────┘ └──────────────────┘
30
+ │ │ │
31
+ │ sendToInternet() │ │
32
+ │─────────────────────────────►│ │
33
+ │ │ HTTP GET/POST │
34
+ │ │─────────────────────────────►│
35
+ │ │ │
36
+ │ │◄─────────────────────────────│
37
+ │ │ HTTP 200 OK │
38
+ │◄─────────────────────────────│ │
39
+ │ Callback with result │ │
40
+ ```
41
+
42
+ ### Connection Method Differences
43
+
44
+ **ESP Mesh Nodes** join the mesh network wirelessly:
45
+ - Use `mesh.init(MESH_PREFIX, MESH_PASSWORD, &scheduler, MESH_PORT)`
46
+ - MESH_PREFIX is the WiFi SSID of the mesh network
47
+ - ESP WiFi hardware creates/joins the wireless mesh
48
+ - Example: `mesh.init("FishFarmMesh", "securepass", &scheduler, 5555)`
49
+
50
+ **PC Mesh Node** joins via TCP/IP connection:
51
+ - Cannot use WiFi mesh (no ESP WiFi hardware)
52
+ - Connects via standard TCP to bridge's IP:port (e.g., 192.168.1.100:5555)
53
+ - Once connected, painlessMesh protocol runs over TCP
54
+ - Same mesh protocol, different transport layer
55
+
56
+ Both methods result in a functioning mesh node that can send/receive mesh messages and use `sendToInternet()`.
57
+
58
+ ## Prerequisites
59
+
60
+ ### Software Requirements
61
+
62
+ #### Linux (Ubuntu/Debian)
63
+ ```bash
64
+ sudo apt-get update
65
+ sudo apt-get install -y cmake g++ libboost-dev libboost-system-dev
66
+ ```
67
+
68
+ #### macOS
69
+ ```bash
70
+ brew install cmake boost
71
+ ```
72
+
73
+ #### Windows
74
+ 1. Install [Visual Studio](https://visualstudio.microsoft.com/) with C++ support
75
+ 2. Install [CMake](https://cmake.org/download/)
76
+ 3. Install [Boost](https://www.boost.org/) or use vcpkg:
77
+ ```powershell
78
+ vcpkg install boost-asio boost-system
79
+ ```
80
+
81
+ ### Hardware Requirements
82
+
83
+ - **Bridge Node**: One ESP32 or ESP8266 with:
84
+ - Router credentials configured
85
+ - Running `sendToInternet.ino` with `IS_BRIDGE_NODE = true`
86
+ - Connected to the same network as your PC
87
+
88
+ ### Mock HTTP Server
89
+
90
+ For testing, start the mock HTTP server:
91
+
92
+ ```bash
93
+ cd ../../test/mock-http-server
94
+ python3 server.py
95
+ ```
96
+
97
+ The server will run on `http://localhost:8080` by default.
98
+
99
+ ## Building
100
+
101
+ ### Quick Build (Using make)
102
+
103
+ ```bash
104
+ cd examples/sendToInternet
105
+
106
+ # Initialize dependencies (if not already done)
107
+ cd ../../test
108
+ git clone https://github.com/bblanchon/ArduinoJson.git
109
+ git clone https://github.com/arkhipenko/TaskScheduler
110
+ cd ../examples/sendToInternet
111
+
112
+ # Build
113
+ cmake .
114
+ make
115
+
116
+ # Run
117
+ ./pc_mesh_node <bridge_ip> <mesh_port>
118
+ ```
119
+
120
+ ### Using CMake
121
+
122
+ ```bash
123
+ mkdir build
124
+ cd build
125
+ cmake ..
126
+ make
127
+ ./pc_mesh_node 192.168.1.100 5555
128
+ ```
129
+
130
+ ### Manual Build (without CMake)
131
+
132
+ ```bash
133
+ g++ -std=c++14 -o pc_mesh_node pc_mesh_node.cpp \
134
+ -I../../src -I../../test/include -I../../test/ArduinoJson/src \
135
+ -I../../test/TaskScheduler/src -I../../test/boost \
136
+ ../../test/catch/fake_serial.cpp ../../src/scheduler.cpp \
137
+ -lboost_system -pthread
138
+ ```
139
+
140
+ ## Usage
141
+
142
+ ### Basic Usage
143
+
144
+ ```bash
145
+ ./pc_mesh_node <bridge_ip> <mesh_port>
146
+ ```
147
+
148
+ **Example:**
149
+ ```bash
150
+ ./pc_mesh_node 192.168.1.100 5555
151
+ ```
152
+
153
+ **Parameters:**
154
+ - `bridge_ip`: IP address of the ESP bridge on your LAN (not WiFi credentials)
155
+ - `mesh_port`: TCP port the bridge is listening on (typically 5555)
156
+
157
+ **Note:** Unlike ESP nodes that use WiFi credentials (MESH_PREFIX/MESH_PASSWORD), the PC node connects via TCP/IP to the bridge's IP address. The bridge must be configured with:
158
+ ```cpp
159
+ // On ESP bridge
160
+ mesh.init(MESH_PREFIX, MESH_PASSWORD, &scheduler, MESH_PORT);
161
+ // Creates mesh network and opens TCP port MESH_PORT (5555)
162
+ ```
163
+
164
+ The PC node then connects to that TCP port to join the mesh.
165
+ ```
166
+
167
+ ### Advanced Usage
168
+
169
+ Specify custom mock server location:
170
+
171
+ ```bash
172
+ ./pc_mesh_node <bridge_ip> <mesh_port> <mock_server_ip> <mock_server_port>
173
+ ```
174
+
175
+ **Example:**
176
+ ```bash
177
+ ./pc_mesh_node 192.168.1.100 5555 192.168.1.50 8080
178
+ ```
179
+
180
+ ## Complete Testing Workflow
181
+
182
+ ### Step 1: Start Mock HTTP Server
183
+
184
+ ```bash
185
+ cd test/mock-http-server
186
+ python3 server.py
187
+
188
+ # Server output:
189
+ # Mock HTTP Server starting on 0.0.0.0:8080
190
+ # Server ready to accept connections
191
+ ```
192
+
193
+ ### Step 2: Configure and Upload Bridge Node
194
+
195
+ On your ESP32/ESP8266, upload `sendToInternet.ino` with:
196
+
197
+ ```cpp
198
+ #define IS_BRIDGE_NODE true // This is the bridge
199
+ #define MESH_PREFIX "TestMesh"
200
+ #define MESH_PASSWORD "testpass123"
201
+ #define MESH_PORT 5555
202
+
203
+ #define ROUTER_SSID "YourWiFiSSID" // Your router
204
+ #define ROUTER_PASSWORD "YourWiFiPassword"
205
+ ```
206
+
207
+ Wait for the bridge to connect and note its IP address from serial output.
208
+
209
+ ### Step 3: Find Your PC's IP Address
210
+
211
+ **Linux/macOS:**
212
+ ```bash
213
+ ifconfig | grep inet
214
+ # Or
215
+ ip addr show
216
+ ```
217
+
218
+ **Windows:**
219
+ ```powershell
220
+ ipconfig
221
+ ```
222
+
223
+ ### Step 4: Run PC Mesh Node
224
+
225
+ ```bash
226
+ # If bridge IP is 192.168.1.100 and you're running mock server on same PC
227
+ ./pc_mesh_node 192.168.1.100 5555
228
+
229
+ # If mock server is on a different machine (e.g., 192.168.1.50)
230
+ ./pc_mesh_node 192.168.1.100 5555 192.168.1.50 8080
231
+ ```
232
+
233
+ ### Expected Output
234
+
235
+ ```
236
+ ============================================================
237
+ painlessMesh - PC Mesh Node Example
238
+ Testing sendToInternet() Through Bridge
239
+ ============================================================
240
+
241
+ Configuration:
242
+ Bridge: 192.168.1.100:5555
243
+ Mock Server: http://127.0.0.1:8080
244
+
245
+ ✓ PC Mesh Node initialized with ID: 1234567
246
+ ✓ sendToInternet() API enabled
247
+ Connecting to bridge at 192.168.1.100:5555...
248
+ ✓ Connected to bridge!
249
+
250
+ Waiting for mesh to establish...
251
+ 🔄 Starting update loop (running for 10 seconds)...
252
+ ✓ Update loop completed after 10 seconds
253
+
254
+ ============================================================
255
+ Starting Automated Test Suite
256
+ ============================================================
257
+
258
+ Waiting 5 seconds for mesh to stabilize...
259
+
260
+ [Test 1/5] HTTP 200 Success
261
+
262
+ 📡 Testing sendToInternet()...
263
+ URL: http://127.0.0.1:8080/status/200
264
+ ✓ Bridge with Internet found
265
+ ✓ Request queued with message ID: 2766733313
266
+ Waiting for response from bridge...
267
+
268
+ 📥 Response received:
269
+ Success: ✓ YES
270
+ HTTP Status: 200
271
+ 🎉 TEST PASSED: Request successful!
272
+
273
+ [Test 2/5] HTTP 404 Not Found
274
+ ...
275
+ ```
276
+
277
+ ## What Gets Tested
278
+
279
+ The automated test suite validates:
280
+
281
+ ### Test 1: HTTP 200 Success
282
+ - ✅ Request successfully routed through bridge
283
+ - ✅ HTTP 200 status code received
284
+ - ✅ Callback invoked with success=true
285
+
286
+ ### Test 2: HTTP 404 Not Found
287
+ - ✅ Error handling works correctly
288
+ - ✅ HTTP 404 status code received
289
+ - ✅ Callback invoked with success=false
290
+
291
+ ### Test 3: HTTP 500 Server Error
292
+ - ✅ Server error handling
293
+ - ✅ HTTP 500 status code received
294
+ - ✅ Proper error reporting
295
+
296
+ ### Test 4: WhatsApp API Simulation
297
+ - ✅ Complex URL with query parameters
298
+ - ✅ URL encoding handled correctly
299
+ - ✅ Simulates real-world API call
300
+
301
+ ### Test 5: JSON Payload Echo
302
+ - ✅ POST request with JSON payload
303
+ - ✅ Data correctly transmitted through bridge
304
+ - ✅ Response received and processed
305
+
306
+ ## Troubleshooting
307
+
308
+ ### "Failed to connect to bridge"
309
+
310
+ **Possible causes:**
311
+ 1. Bridge IP address is incorrect
312
+ 2. Bridge is not running or not on the network
313
+ 3. Firewall blocking connections
314
+ 4. Wrong mesh port
315
+
316
+ **Solutions:**
317
+ ```bash
318
+ # Verify bridge is reachable
319
+ ping 192.168.1.100
320
+
321
+ # Check firewall (Linux)
322
+ sudo iptables -L
323
+
324
+ # Check if port is open (Linux/macOS)
325
+ nc -zv 192.168.1.100 5555
326
+
327
+ # Windows
328
+ Test-NetConnection -ComputerName 192.168.1.100 -Port 5555
329
+ ```
330
+
331
+ ### "No Internet connection available through bridge"
332
+
333
+ **Possible causes:**
334
+ 1. Bridge lost WiFi connection
335
+ 2. Bridge hasn't initialized yet
336
+ 3. sendToInternet API not enabled on bridge
337
+
338
+ **Solutions:**
339
+ - Check bridge serial output
340
+ - Verify bridge shows "Is Bridge: YES"
341
+ - Wait 30-60 seconds after bridge startup
342
+ - Ensure `mesh.enableSendToInternet()` is called on bridge
343
+
344
+ ### "Connection timeout after 30 seconds"
345
+
346
+ **Possible causes:**
347
+ 1. Network connectivity issues
348
+ 2. Mesh network not forming
349
+ 3. Wrong mesh credentials
350
+
351
+ **Solutions:**
352
+ - Verify MESH_PREFIX and MESH_PASSWORD match
353
+ - Check both devices are on same network
354
+ - Try restarting both bridge and PC node
355
+
356
+ ### Build Errors
357
+
358
+ #### "Boost not found"
359
+
360
+ ```bash
361
+ # Ubuntu/Debian
362
+ sudo apt-get install libboost-dev libboost-system-dev
363
+
364
+ # macOS
365
+ brew install boost
366
+
367
+ # Windows
368
+ # Use vcpkg or download from boost.org
369
+ ```
370
+
371
+ #### "ArduinoJson not found"
372
+
373
+ ```bash
374
+ cd ../../test
375
+ git clone https://github.com/bblanchon/ArduinoJson.git
376
+ ```
377
+
378
+ #### "TaskScheduler not found"
379
+
380
+ ```bash
381
+ cd ../../test
382
+ git clone https://github.com/arkhipenko/TaskScheduler
383
+ ```
384
+
385
+ ## Testing on Different Platforms
386
+
387
+ ### Linux
388
+
389
+ Should work out of the box with the dependencies installed:
390
+
391
+ ```bash
392
+ cmake . && make
393
+ ./pc_mesh_node 192.168.1.100 5555
394
+ ```
395
+
396
+ ### macOS
397
+
398
+ Same as Linux. Use Homebrew for dependencies:
399
+
400
+ ```bash
401
+ brew install cmake boost
402
+ cmake . && make
403
+ ./pc_mesh_node 192.168.1.100 5555
404
+ ```
405
+
406
+ ### Windows
407
+
408
+ #### Using Visual Studio
409
+ 1. Open `CMakeLists.txt` in Visual Studio
410
+ 2. Build → Build All
411
+ 3. Run from PowerShell:
412
+ ```powershell
413
+ .\pc_mesh_node.exe 192.168.1.100 5555
414
+ ```
415
+
416
+ #### Using MinGW
417
+ ```bash
418
+ cmake -G "MinGW Makefiles" .
419
+ mingw32-make
420
+ pc_mesh_node.exe 192.168.1.100 5555
421
+ ```
422
+
423
+ #### Using WSL (Windows Subsystem for Linux)
424
+ ```bash
425
+ # In WSL terminal
426
+ sudo apt-get install cmake g++ libboost-dev libboost-system-dev
427
+ cmake . && make
428
+ ./pc_mesh_node 192.168.1.100 5555
429
+ ```
430
+
431
+ ## Advanced Configuration
432
+
433
+ ### Custom Mock Server Endpoints
434
+
435
+ Edit `pc_mesh_node.cpp` to test custom endpoints:
436
+
437
+ ```cpp
438
+ // Test a custom endpoint
439
+ node.testSendToInternet("http://192.168.1.50:8080/custom-endpoint",
440
+ "{\"custom\":\"payload\"}");
441
+ ```
442
+
443
+ ### Logging Levels
444
+
445
+ Adjust logging in `pc_mesh_node.cpp`:
446
+
447
+ ```cpp
448
+ // More verbose logging
449
+ Log.setLogLevel(painlessmesh::logger::ERROR |
450
+ painlessmesh::logger::STARTUP |
451
+ painlessmesh::logger::CONNECTION |
452
+ painlessmesh::logger::COMMUNICATION |
453
+ painlessmesh::logger::GENERAL);
454
+
455
+ // Minimal logging (errors only)
456
+ Log.setLogLevel(painlessmesh::logger::ERROR);
457
+ ```
458
+
459
+ ### Custom Node ID
460
+
461
+ By default, the node ID is random. To use a fixed ID:
462
+
463
+ ```cpp
464
+ uint32_t nodeId = 9999999; // Fixed node ID
465
+ PCMeshNode node(&scheduler, nodeId, io_service);
466
+ ```
467
+
468
+ ## Integration with CI/CD
469
+
470
+ This PC mesh node can be integrated into automated testing:
471
+
472
+ ```bash
473
+ #!/bin/bash
474
+ # Start mock server
475
+ python3 test/mock-http-server/server.py &
476
+ SERVER_PID=$!
477
+
478
+ # Build PC node
479
+ cd examples/sendToInternet
480
+ cmake . && make
481
+
482
+ # Run test (assuming bridge is running at known IP)
483
+ ./pc_mesh_node 192.168.1.100 5555 127.0.0.1 8080
484
+
485
+ # Cleanup
486
+ kill $SERVER_PID
487
+ ```
488
+
489
+ ## Comparison with ESP Node Testing
490
+
491
+ | Feature | ESP32 Node | PC Mesh Node |
492
+ |---------|-----------|--------------|
493
+ | **Build Time** | 1-2 minutes | 5-10 seconds |
494
+ | **Upload Time** | 30-60 seconds | N/A (instant) |
495
+ | **Debugging** | Serial only | GDB, IDEs, etc. |
496
+ | **Logging** | Serial monitor | stdout, files |
497
+ | **Iteration Speed** | Slow | Fast |
498
+ | **Cost** | ~$5-10 per device | Free |
499
+ | **Setup** | Physical wiring | Just software |
500
+ | **Portability** | Fixed location | Run anywhere |
501
+
502
+ ## Related Documentation
503
+
504
+ - [sendToInternet Example](sendToInternet.ino) - ESP32/ESP8266 example
505
+ - [Mock HTTP Server](../../test/mock-http-server/README.md) - Testing endpoint
506
+ - [Bridge Documentation](../../BRIDGE_TO_INTERNET.md) - Bridge setup guide
507
+ - [Testing Guide](../../test/mock-http-server/TESTING_GUIDE.md) - Complete testing workflow
508
+
509
+ ## Credits
510
+
511
+ - **Issue Reporter**: @woodlist (Issue #337)
512
+ - **Implementation**: GitHub Copilot with painlessMesh team
513
+ - **Date**: December 26, 2024
514
+
515
+ ## License
516
+
517
+ Part of the painlessMesh project. See main repository LICENSE.
@@ -194,11 +194,49 @@ The callback provides `httpStatus` to indicate the result:
194
194
 
195
195
  ## Files
196
196
 
197
- - `sendToInternet.ino` - Main example sketch
197
+ - `sendToInternet.ino` - Main example sketch for ESP32/ESP8266
198
+ - `mock_server_test.ino` - Bridge testing with mock HTTP server
199
+ - `pc_mesh_node.cpp` - **NEW:** PC-based mesh node for testing regular node → bridge flow
198
200
  - `README.md` - This documentation
201
+ - `PC_NODE_README.md` - **NEW:** Documentation for PC mesh node testing
202
+
203
+ ## Testing from Regular Nodes
204
+
205
+ ### PC Mesh Node Emulator (NEW!)
206
+
207
+ Want to test `sendToInternet()` from a **regular mesh node** (not a bridge) without needing multiple ESP devices?
208
+
209
+ The **PC Mesh Node** allows you to:
210
+ - ✅ Run a mesh node on Windows/Linux/macOS
211
+ - ✅ Test the complete flow: PC Node → Bridge → Internet
212
+ - ✅ Debug with full PC development tools
213
+ - ✅ Fast iteration (no upload times!)
214
+
215
+ **Quick Start:**
216
+ ```bash
217
+ cd examples/sendToInternet
218
+
219
+ # Build
220
+ cmake . && make
221
+
222
+ # Run (connect to your ESP bridge)
223
+ ./pc_mesh_node 192.168.1.100 5555
224
+ ```
225
+
226
+ **Full Documentation:** [PC_NODE_README.md](PC_NODE_README.md)
227
+
228
+ **What It Tests:**
229
+ - Regular mesh node sending HTTP requests through bridge
230
+ - Request routing through mesh network
231
+ - Response callback handling
232
+ - Multiple HTTP status codes (200, 404, 500, etc.)
233
+ - JSON payload transmission
234
+
235
+ **Addresses Issue #337:** This solution provides the "bridge emulator" or mesh node emulator requested by @woodlist for testing node-to-internet traffic through the bridge.
199
236
 
200
237
  ## Related Examples
201
238
 
202
239
  - [sharedGateway](../sharedGateway/) - All nodes with direct Internet access
203
240
  - [bridge_failover](../bridge_failover/) - Automatic gateway failover
204
241
  - [mqttBridge](../mqttBridge/) - MQTT integration
242
+ - [Mock HTTP Server](../../test/mock-http-server/) - Local testing endpoint
@@ -0,0 +1,153 @@
1
+ #!/bin/bash
2
+ #
3
+ # Build and Setup Script for PC Mesh Node
4
+ #
5
+ # This script helps set up dependencies and build the PC mesh node emulator
6
+ # for testing sendToInternet() from regular nodes through a bridge.
7
+ #
8
+
9
+ set -e
10
+
11
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
+ cd "$SCRIPT_DIR"
13
+
14
+ echo "=========================================="
15
+ echo "PC Mesh Node - Build & Setup"
16
+ echo "=========================================="
17
+ echo ""
18
+
19
+ # Check if we're in the right directory
20
+ if [ ! -f "pc_mesh_node.cpp" ]; then
21
+ echo "Error: pc_mesh_node.cpp not found!"
22
+ echo "Please run this script from the examples/sendToInternet directory"
23
+ exit 1
24
+ fi
25
+
26
+ # Function to check if a command exists
27
+ command_exists() {
28
+ command -v "$1" >/dev/null 2>&1
29
+ }
30
+
31
+ # Check for required tools
32
+ echo "Checking required tools..."
33
+
34
+ if ! command_exists cmake; then
35
+ echo "❌ CMake not found!"
36
+ echo " Install: sudo apt-get install cmake (Linux)"
37
+ echo " brew install cmake (macOS)"
38
+ exit 1
39
+ fi
40
+ echo "✓ CMake found"
41
+
42
+ if ! command_exists g++; then
43
+ echo "❌ g++ not found!"
44
+ echo " Install: sudo apt-get install g++ (Linux)"
45
+ echo " brew install gcc (macOS)"
46
+ exit 1
47
+ fi
48
+ echo "✓ g++ found"
49
+
50
+ # Check for Boost
51
+ echo ""
52
+ echo "Checking Boost libraries..."
53
+
54
+ # Cross-platform Boost detection
55
+ if command -v pkg-config >/dev/null 2>&1; then
56
+ if pkg-config --exists boost 2>/dev/null; then
57
+ echo "✓ Boost found (via pkg-config)"
58
+ else
59
+ echo "⚠️ Boost not detected via pkg-config"
60
+ fi
61
+ elif [ -d "/usr/include/boost" ] || [ -d "/usr/local/include/boost" ] || [ -d "/opt/homebrew/include/boost" ]; then
62
+ echo "✓ Boost headers found"
63
+ else
64
+ echo "⚠️ Boost not found in standard locations"
65
+ fi
66
+
67
+ echo " If build fails, install Boost:"
68
+ echo " - Linux: sudo apt-get install libboost-dev libboost-system-dev"
69
+ echo " - macOS: brew install boost"
70
+ echo " - Windows: See https://www.boost.org/"
71
+
72
+ # Check for test dependencies
73
+ echo ""
74
+ echo "Checking test dependencies..."
75
+
76
+ if [ ! -d "../../test/ArduinoJson/src" ]; then
77
+ echo "⚠️ ArduinoJson not found"
78
+ echo " Cloning ArduinoJson..."
79
+ cd ../../test
80
+ if [ -d "ArduinoJson" ]; then
81
+ rm -rf ArduinoJson
82
+ fi
83
+ git clone https://github.com/bblanchon/ArduinoJson.git
84
+ cd "$SCRIPT_DIR"
85
+ else
86
+ echo "✓ ArduinoJson found"
87
+ fi
88
+
89
+ if [ ! -d "../../test/TaskScheduler/src" ]; then
90
+ echo "⚠️ TaskScheduler not found"
91
+ echo " Cloning TaskScheduler..."
92
+ cd ../../test
93
+ if [ -d "TaskScheduler" ]; then
94
+ rm -rf TaskScheduler
95
+ fi
96
+ git clone https://github.com/arkhipenko/TaskScheduler
97
+ cd "$SCRIPT_DIR"
98
+ else
99
+ echo "✓ TaskScheduler found"
100
+ fi
101
+
102
+ # Clean previous build
103
+ echo ""
104
+ echo "Cleaning previous build..."
105
+ rm -rf CMakeFiles CMakeCache.txt cmake_install.cmake Makefile pc_mesh_node
106
+ echo "✓ Clean complete"
107
+
108
+ # Configure with CMake
109
+ echo ""
110
+ echo "Configuring with CMake..."
111
+ if cmake . 2>&1 | grep -q "Configuring done"; then
112
+ echo "✓ Configuration successful"
113
+ else
114
+ echo "❌ Configuration failed!"
115
+ echo " Check the error messages above"
116
+ exit 1
117
+ fi
118
+
119
+ # Build
120
+ echo ""
121
+ echo "Building..."
122
+ if make 2>&1; then
123
+ echo ""
124
+ echo "=========================================="
125
+ echo "✓ Build successful!"
126
+ echo "=========================================="
127
+ echo ""
128
+ echo "Executable: ./pc_mesh_node"
129
+ echo ""
130
+ echo "Usage:"
131
+ echo " ./pc_mesh_node <bridge_ip> <mesh_port>"
132
+ echo ""
133
+ echo "Example:"
134
+ echo " ./pc_mesh_node 192.168.1.100 5555"
135
+ echo ""
136
+ echo "Next steps:"
137
+ echo " 1. Start mock HTTP server:"
138
+ echo " cd ../../test/mock-http-server && python3 server.py"
139
+ echo ""
140
+ echo " 2. Configure and upload bridge to ESP32/ESP8266"
141
+ echo " (see sendToInternet.ino with IS_BRIDGE_NODE=true)"
142
+ echo ""
143
+ echo " 3. Run PC mesh node:"
144
+ echo " ./pc_mesh_node <bridge_ip> 5555"
145
+ echo ""
146
+ echo "For detailed instructions, see PC_NODE_README.md"
147
+ echo "=========================================="
148
+ else
149
+ echo ""
150
+ echo "❌ Build failed!"
151
+ echo " Check the error messages above"
152
+ exit 1
153
+ fi