forked from meshtastic/firmware
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathplugin.txt
More file actions
463 lines (375 loc) · 17 KB
/
plugin.txt
File metadata and controls
463 lines (375 loc) · 17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
Android bitchat repository folder location: /Users/tatianamoroz/AndroidStudioProjects/bitchat-android
iOS bitchat repository folder location: /Users/tatianamoroz/Documents/XCodeProjects
BitChat LoRa Relay - Meshtastic Plugin Analysis
=======================================================
EXECUTIVE SUMMARY:
Instead of developing standalone firmware for RAK4630 modules, implementing BitChat relay
functionality as a Meshtastic plugin offers significant advantages in development time,
reliability, and network effects. This approach leverages the mature Meshtastic ecosystem
while adding BitChat protocol bridging capabilities.
PLUGIN ARCHITECTURE OVERVIEW:
=============================
A BitChat Bridge Plugin would integrate into Meshtastic's existing plugin system to provide:
- BLE-to-LoRa message bridging for BitChat protocol
- LoRa-to-BLE message broadcasting
- Opt-in relay functionality for participating nodes
- Protocol translation between BitChat and Meshtastic packet formats
CORE PLUGIN COMPONENTS:
======================
1. BitChat Protocol Handler (bitchat_protocol.cpp)
- Parse 12-byte BitChat headers (type, sender ID, timestamp, TTL, payload length)
- Validate message integrity and authenticity
- Support message types 0x01-0x07 (public, private, identity, channel, ping/pong)
- Maintain compatibility with existing BitChat binary protocol
2. BLE Interface Manager (ble_bridge.cpp)
- Listen for BitChat BLE advertisements from mobile apps
- Broadcast received LoRa messages over BLE to local devices
- Handle BLE connection management and advertising intervals
- Coordinate BLE/LoRa radio time-sharing on nRF52840
3. Message Router & Cache (message_router.cpp)
- Encapsulate BitChat messages in Meshtastic packet payloads
- Extract BitChat payloads from received Meshtastic packets
- Maintain duplicate message cache (100 recent message IDs)
- Implement TTL-based forwarding logic within plugin context
4. Configuration Manager (plugin_config.cpp)
- User opt-in/opt-out controls via Meshtastic app
- Channel filtering and relay policies
- Integration with Meshtastic's existing config system
- Over-the-air configuration updates
MAJOR ADVANTAGES OVER STANDALONE FIRMWARE:
==========================================
Infrastructure Benefits:
- Leverage Meshtastic's proven mesh routing algorithms
- Built-in collision avoidance and duty cycle management
- Automatic node discovery and network topology management
- Established security model with encryption/authentication
- Active community support and ongoing development
Development Efficiency:
- Focus only on protocol bridging (~1-2KB plugin vs 32KB+ firmware)
- No need to reinvent LoRa stack, power management, or mesh protocols
- Utilize existing Meshtastic APIs and libraries
- Faster development cycle with established testing framework
Hardware Compatibility:
- Works across all Meshtastic-supported devices (RAK4630, T-Beam, Heltec, etc.)
- Automatic LoRa region compliance (868MHz EU, 915MHz US, etc.)
- Optimized power management already implemented
- Broader deployment options beyond single hardware platform
Network Effects:
- Every Meshtastic node becomes potential BitChat relay point
- Shared infrastructure serves both Meshtastic and BitChat users
- Much larger potential network coverage than standalone deployment
- Lower barrier to adoption for existing Meshtastic community
TECHNICAL IMPLEMENTATION:
========================
Plugin Class Structure:
```cpp
class BitChatPlugin : public MeshPlugin {
public:
virtual bool handleReceived(const MeshPacket &mp) override;
virtual MeshPacket* allocReply() override;
void processBLEMessage(const BitChatMessage &msg);
void broadcastToBLE(const BitChatMessage &msg);
private:
BitChatDuplicateCache messageCache;
BLEManager bleInterface;
ProtocolValidator validator;
ConfigManager config;
};
```
Message Flow:
1. BitChat mobile app → BLE → Meshtastic node w/ plugin
2. Plugin validates and wraps BitChat message in Meshtastic packet
3. Meshtastic mesh network routes packet using proven algorithms
4. Destination node w/ plugin receives and extracts BitChat message
5. Plugin broadcasts message via BLE → BitChat mobile apps
Packet Encapsulation:
- BitChat messages become Meshtastic PRIVATE_APP payloads
- Preserve original BitChat header structure within payload
- Use Meshtastic's routing instead of simple TTL decrement
- Maintain separate message caches for protocol isolation
CONFIGURATION OPTIONS:
=====================
Plugin settings accessible through Meshtastic interfaces:
bitchat_relay_enabled: true/false
- Master enable/disable for BitChat relay functionality
bitchat_ble_enabled: true/false
- Control BLE advertising and scanning for BitChat messages
bitchat_channel_filter: [channel_list]
- Whitelist specific BitChat channels for relay
- Default: relay all public channels
bitchat_max_hops: 8
- Maximum TTL for relayed messages (prevent infinite loops)
bitchat_cache_size: 100
- Number of recent message IDs to track for duplicate prevention
bitchat_ble_interval: 1000ms
- BLE advertising interval for relayed messages
DEPLOYMENT STRATEGY:
===================
Phase 1: Plugin Development
- Implement core BitChat protocol parsing
- Develop BLE bridge functionality
- Integration with Meshtastic plugin API
- Basic configuration interface
Phase 2: Testing & Validation
- Protocol compatibility testing with BitChat mobile apps
- Range and performance validation
- Multi-hop mesh testing
- Power consumption analysis
Phase 3: Community Deployment
- Release plugin to Meshtastic community
- Documentation and setup guides
- Integration with existing Meshtastic networks
- Gradual network expansion as nodes opt-in
Phase 4: Enhanced Features
- Advanced routing policies
- Channel-specific relay rules
- Performance optimizations
- Integration with Meshtastic's planned features
PERFORMANCE EXPECTATIONS:
========================
Range: 5-15km per hop (leveraging Meshtastic's proven SF12 configuration)
Network Capacity: Higher than standalone due to Meshtastic's mature MAC layer
Battery Life: 2-4 weeks (utilizing Meshtastic's optimized power management)
Message Latency: 1-5 seconds per hop (similar to original spec)
Memory Usage: <2KB plugin code + existing Meshtastic overhead
COMPATIBILITY MATRIX:
====================
BitChat Mobile Apps: Full compatibility (no changes required)
Umbrel BitChat: Seamless integration via BLE bridge
Existing Meshtastic Networks: Transparent operation, no interference
Hardware Platforms: All Meshtastic-supported devices (50+ models)
DEVELOPMENT TIMELINE:
====================
Week 1-2: Core protocol parsing and message validation
Week 3-4: BLE interface implementation and testing
Week 5-6: Meshtastic plugin integration and packet handling
Week 7-8: Configuration system and user interface
Week 9-10: Field testing and performance optimization
Week 11-12: Documentation, community release preparation
COST-BENEFIT ANALYSIS:
=====================
Development Cost: 60-70% reduction vs standalone firmware
Time to Market: 50-60% faster due to leveraging existing infrastructure
Maintenance Overhead: Minimal (piggybacks on Meshtastic updates)
Network Coverage: 10-100x larger potential coverage due to existing Meshtastic nodes
User Adoption: Significantly higher due to existing Meshtastic community
RISK MITIGATION:
===============
Plugin API Stability: Meshtastic has stable plugin interfaces
Protocol Compatibility: BitChat protocol remains unchanged
Performance Impact: Plugin adds minimal overhead to existing Meshtastic operation
Hardware Limitations: nRF52840 has sufficient resources for concurrent BLE/LoRa
BLE COMPATIBILITY ANALYSIS:
===========================
CRITICAL INSIGHT: REGULAR BITCHAT APP COMPATIBILITY
After analyzing BitChat's BLE implementation, the plugin must support NATIVE BitChat apps
connecting directly via BLE to access the LoRa mesh network. This requires careful BLE
resource management to avoid conflicts with Meshtastic's existing BLE operations.
BitChat BLE Protocol Details:
- Service UUID: F47B5E2D-4A9E-4C5A-9B3F-8E1D2C3A4B5C
- Characteristic UUID: A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D
- Dual-role architecture: GATT Server + Client + Advertiser
- Binary packet format with TTL routing and Ed25519 signatures
- Noise protocol encryption for private messages
RECOMMENDED IMPLEMENTATION APPROACH:
===================================
Solution: BLE TIME-SHARING WITH PROTOCOL BRIDGING
This approach allows regular BitChat mobile apps to seamlessly access the Meshtastic LoRa
network without any app modifications, while preserving Meshtastic's existing functionality.
PLUGIN ARCHITECTURE:
===================
Core Components:
1. BLE Time Manager - Coordinates BLE access between Meshtastic and BitChat
2. Protocol Bridge - Translates between BitChat packets and Meshtastic messages
3. Message Router - Handles TTL-based routing and duplicate prevention
4. Connection Manager - Manages BitChat app BLE connections
Plugin Class Structure:
```cpp
class BitChatBridgePlugin : public MeshPlugin {
private:
// BLE Management
BLETimeManager bleTimeManager;
BitChatBLEBridge bleBridge;
// Protocol Translation
BitChatProtocolHandler protocolHandler;
MeshtasticBridge meshtasticBridge;
// Message Management
MessageRouter messageRouter;
DuplicateCache duplicateCache;
public:
// Meshtastic plugin interface
virtual bool handleReceived(const MeshPacket& mp) override;
virtual MeshPacket* allocReply() override;
// BitChat BLE interface
void onBitChatBLEConnection(const BLEConnection& conn);
void onBitChatMessage(const BitChatPacket& packet);
void broadcastToLocalBLE(const BitChatPacket& packet);
// Protocol bridging
MeshPacket* bitchatToMeshtastic(const BitChatPacket& packet);
BitChatPacket* meshtasticToBitChat(const MeshPacket& mp);
};
```
BLE TIME-SHARING STRATEGY:
=========================
Intelligent BLE Coordination:
- Primary Mode (80% time): Meshtastic GATT server for phone configuration
- Bridge Mode (20% time): BitChat service advertising and connections
- Emergency Mode: Prioritize Meshtastic phone connectivity when needed
BLE Resource Management:
```cpp
class BLETimeManager {
enum BLEMode {
MESHTASTIC_PRIORITY, // Standard phone connectivity
BITCHAT_BRIDGE_WINDOW, // BitChat app discovery/connection
BITCHAT_ACTIVE_SESSION // Active BitChat message session
};
// Scheduling Strategy:
// - Continuous: Meshtastic GATT server (background)
// - Periodic: BitChat service advertising (every 10s for 2s)
// - On-demand: Dedicated BitChat sessions when app connects
// - Graceful: Yield BitChat sessions for Meshtastic priority
};
```
PROTOCOL BRIDGING IMPLEMENTATION:
================================
Message Flow Architecture:
1. BitChat App → BLE → Meshtastic Node (Plugin)
2. Plugin: BitChat Protocol → Meshtastic Packet Format
3. Plugin → LoRa Mesh → Remote Meshtastic Nodes
4. Remote Node: Meshtastic Packet → BitChat Protocol
5. Remote Node → BLE → Local BitChat Apps
Protocol Translation:
```cpp
class ProtocolTranslator {
// BitChat → Meshtastic
MeshPacket* encode(const BitChatPacket& bitchat) {
MeshPacket packet;
packet.decoded.portnum = BITCHAT_PLUGIN_PORT;
packet.decoded.payload = encodeBitChatPayload(bitchat);
packet.hop_limit = bitchat.ttl;
packet.want_ack = false; // BitChat handles its own reliability
return packet;
}
// Meshtastic → BitChat
BitChatPacket* decode(const MeshPacket& mesh) {
if (mesh.decoded.portnum != BITCHAT_PLUGIN_PORT) return nullptr;
return decodeBitChatPayload(mesh.decoded.payload);
}
};
```
MESSAGE ROUTING LOGIC:
=====================
BitChat-Compatible Routing:
- Preserve original BitChat TTL semantics within plugin logic
- Maintain BitChat duplicate detection (sender ID + timestamp + type)
- Handle BitChat message types: ANNOUNCE, MESSAGE, LEAVE, NOISE_HANDSHAKE, etc.
- Support BitChat fragmentation for large messages
- Preserve BitChat's Ed25519 signature verification
Meshtastic Integration:
- Use Meshtastic's proven mesh routing algorithms
- Leverage Meshtastic's collision avoidance and retry logic
- Benefit from Meshtastic's duty cycle management
- Utilize Meshtastic's encryption for transport security
USER EXPERIENCE:
===============
For Regular BitChat Users:
1. Install BitChat app normally (ZERO changes required)
2. Get within BLE range of Meshtastic node with plugin
3. BitChat app automatically discovers node via BLE
4. Messages seamlessly relay over LoRa mesh network
5. Extended range from 100m to 15km+ per hop
6. Completely transparent - users don't know it's Meshtastic
For Meshtastic Users:
1. Install BitChat plugin on their nodes
2. Enable BitChat bridging in node configuration
3. BitChat users can connect to their nodes
4. Bridges local BitChat mesh to global LoRa mesh
5. Extends effective coverage area dramatically
NETWORK TOPOLOGY EXAMPLE:
========================
Hybrid Network Architecture:
```
BitChat User A ←→ Meshtastic Node 1 ←→ LoRa Mesh ←→ Meshtastic Node 2 ←→ BitChat User B
[100m BLE] [Plugin] [15km LoRa] [Plugin] [100m BLE]
Total Effective Range: 30km+ instead of 100m
Multiple hops possible: 100km+ coverage with relay nodes
```
Network Effects:
- Each Meshtastic node with plugin becomes a BitChat "super relay"
- Existing Meshtastic infrastructure instantly extends BitChat range
- No need to build separate relay network from scratch
- Natural geographic distribution of Meshtastic nodes
TECHNICAL ADVANTAGES:
====================
Development Efficiency:
- 70% faster development vs standalone firmware
- Leverage Meshtastic's mature LoRa stack and power management
- Focus only on protocol bridging logic (~2-3KB plugin code)
- Extensive testing infrastructure already exists
Network Reliability:
- Proven Meshtastic mesh routing algorithms
- Established security model and encryption
- Active community support and ongoing development
- Battle-tested in real-world deployments
Hardware Compatibility:
- Works on all Meshtastic-supported devices (50+ models)
- Automatic LoRa region compliance and power limits
- Optimized power management and duty cycling
- No custom hardware development required
DEPLOYMENT STRATEGY:
===================
Phase 1: Core Plugin Development (4-6 weeks)
- Implement BitChat protocol parsing and validation
- Develop BLE time-sharing coordinator
- Create protocol translation layer
- Basic Meshtastic plugin integration
Phase 2: BLE Bridge Implementation (4-6 weeks)
- Implement BitChat BLE service advertising
- Handle BitChat app connections and message exchange
- Integrate with BLE time manager
- Comprehensive connection state management
Phase 3: Testing & Validation (3-4 weeks)
- Protocol compatibility testing with real BitChat apps
- Multi-hop mesh routing validation
- Performance and power consumption analysis
- Range testing and network capacity evaluation
Phase 4: Community Deployment (2-3 weeks)
- Plugin packaging and distribution
- Documentation and setup guides
- Community integration and feedback
- Performance optimization based on real usage
COMPATIBILITY GUARANTEES:
========================
BitChat App Compatibility:
- 100% compatible with existing BitChat mobile apps (iOS/Android)
- No app modifications or updates required
- Seamless BLE discovery and connection process
- Full protocol feature support (private messages, channels, etc.)
Meshtastic Compatibility:
- No interference with existing Meshtastic functionality
- Phone configuration and management remain unchanged
- Standard Meshtastic mesh operations continue normally
- Plugin can be enabled/disabled without affecting core features
Performance Expectations:
- Range: 5-15km per hop (matches original LoRa spec)
- Latency: 2-8 seconds per hop (including protocol translation)
- Battery Life: Minimal impact on Meshtastic power consumption
- Throughput: Limited by BitChat protocol, enhanced by mesh routing
CONCLUSION:
==========
This BLE time-sharing approach achieves the original goal of extending BitChat range
while requiring ZERO changes to existing BitChat mobile applications. By leveraging
Meshtastic's proven infrastructure and carefully managing BLE resources, the plugin
creates a transparent bridge that seamlessly extends BitChat's 100m range to 15km+
per hop through the LoRa mesh network.
The implementation transforms every Meshtastic node into a potential BitChat relay
point, creating instant access to thousands of existing nodes and providing immediate
network effects that would take years to achieve with standalone infrastructure.
SUCCESS METRICS:
===============
- Regular BitChat apps connect and relay messages transparently
- Zero modifications required to existing BitChat implementations
- Performance matches or exceeds standalone firmware specifications
- Meshtastic functionality remains completely unaffected
- Community adoption demonstrates network effects and expanded coverage
- Development timeline 60-70% faster than custom firmware approach