Skip to content
Sarthak90210Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

# Universal LoRa serial bridge for the Heltec WiFi LoRa 32 V3 A transparent, protocol-agnostic serial-over-LoRa bridge. Both boards run the **same firmware**; neither is permanently the air side or the ground side. Built on the Meshtastic firmware tree (GPL-3.0). See [ARCHITECTURE.md](ARCHITECTURE.md) for the engineering design and the reasoning behind each decision. > **Status: compiles cleanly, never run on hardware.** The host tests pass, 6,166 checks. Every throughput figure below is calculated rather than measured. Do not fly this until the test plan at the end has been run. ## What it does ``` Device --USB or UART--> Heltec A --LoRa--> Heltec B --USB or UART--> Device ``` Bytes in one side come out the other side unchanged. Every value `0x00` through `0xFF` survives, nulls included. The firmware never parses, translates, or reframes the payload. MAVLink, NMEA, MSP, JSON, ASCII and arbitrary binary all work the same way, because none of them are special-cased. ## Hardware Heltec WiFi LoRa 32 V3, **wideband 863 to 928 MHz variant**. Default operating frequency **915 MHz**; both boards must match. ### Pinout | Function | GPIO | |---|---| | USB payload (UART0, via onboard CP2102) | RX 44, TX 43 | | External payload UART (UART1) | **RX 4, TX 5** | | PRG button (selects Master) | 0 | | SX1262 | CS 8, SCK 9, MOSI 10, MISO 11, RST 12, BUSY 13, DIO1 14 | | OLED | SDA 17, SCL 18, RST 21 | GPIO4 and GPIO5 were checked against the board variant header and the V3.2 schematic: they carry only ADC and touch aliases, and do not collide with the radio, display, secondary I2C (41/42), USB, or boot strapping. ### Pixhawk wiring ``` Pixhawk TELEM1 Heltec V3 TX ──────────────────────> GPIO4 (UART1 RX) RX <────────────────────── GPIO5 (UART1 TX) GND ─────────────────────── GND ``` **TX and RX cross. Ground must be common.** Pixhawk 6X V2 and CUAV X7/B TELEM ports use **3.3 V logic** and connect directly. The 5 V pin on those connectors is a **power rail, not a logic level**. Do not confuse the two. A genuine 5 V TTL UART needs a bidirectional level shifter; the ESP32-S3 is not 5 V tolerant. Do not power the Heltec from the TELEM 5 V pin until you have checked that port's current limit against the board's draw with Wi-Fi active. ## Build PlatformIO's ESP-IDF builder rejects whitespace in the project, framework, and build paths, and resolves junctions back to their real paths. The firmware therefore lives at `D:\lorafw` (a junction named `firmware` in this workspace points to it) and the package/build stores are at space-free locations. `build.ps1` sets all of that up: ```bash ./build.ps1 ``` Or manually: ```bash export PLATFORMIO_CORE_DIR="D:/lorafw/.pio-core" export PLATFORMIO_PACKAGES_DIR="D:/lorapkgs" export PLATFORMIO_BUILD_DIR="D:/lorabuild" platformio run -d D:/lorafw -e heltec-v3-bridge ``` Build verified: **SUCCESS**, no warnings from any bridge source file. A clean build takes about four minutes; incremental rebuilds about ninety seconds. | | | |---|---| | RAM | 34.7%, 113,604 of 327,680 bytes | | Flash | 53.2%, 1,778,975 of 3,342,336 bytes | Artifacts land in `D:/lorabuild/heltec-v3-bridge/`: | File | Use | |---|---| | `firmware-heltec-v3-bridge-2.8.1.bin` | application only, for a board already running this firmware | | `firmware-heltec-v3-bridge-2.8.1.factory.bin` | bootloader + partitions + app, for a first flash or after a wipe | ## Flash Both boards get the identical image. That is the whole point of the design. ```bash ./build.ps1 -Upload -Port COM5 ``` Replace `COM5` with each board's port, and run it once per board. This handles the bootloader and partition table for you. If a board does not enter the bootloader on its own, hold **PRG**, tap **RST**, release **PRG**, then start the upload. For a first flash with `esptool` directly, use the `.factory.bin` at offset `0x0`. ## First-time setup 1. Flash both boards. 2. Decide which board is the **ground station**. Hold its **PRG button for 2 seconds**. It becomes Master, enables Wi-Fi, and reboots. The other board stays Remote with Wi-Fi off. 3. Connect to the Wi-Fi access point the Master advertises. Its SSID (`LoRa-Bridge-XXXX`) and passphrase are shown on the OLED, which rotates to that page every few seconds. 4. Open **`http://192.168.4.1/bridge`**. Plain HTTP, not HTTPS (see `ARCHITECTURE.md` for why); the bare address redirects to `/bridge`. 5. In the **Nodes** table, press **Connect** on the other board. 6. Set the preset, interface and baud rates, then **Apply**. The change is applied to both radios as one transaction, and the page reports each step. The role, peer, interface and baud settings all persist in NVS across reboots, so this is a one-time setup per board. ### How the Master is chosen After the first setup the boards elect a Master themselves. Whichever one is carrying USB traffic takes the role, and if both are, the one that has held it longer keeps it. The board that loses drops Wi-Fi and reboots once. The PRG button remains a manual override, and you need it on a board that has never seen traffic, because there is a hardware limit underneath all of this. The V3's USB-C port goes to a CP2102, not to the ESP32-S3's native USB peripheral. The CP2102 gives the MCU no host-present signal at all: its `SUSPEND` pins are unconnected, and `DTR`/`RTS` only drive the auto-reset transistors. So the firmware cannot tell a plugged-in but silent host from no cable at all, and election has to run on observed traffic instead of cable presence. ## Throughput, and why it matters before you connect a flight controller The RF configuration is baked into the bridge build as `USERPREFS_*` defines (region `US`, preset `SHORT_TURBO`, frequency pinned to 915.0 MHz). This is **required, not cosmetic**: a Meshtastic board with `region = UNSET` has transmit disabled outright, so a fresh board would never send anything. `US` is chosen because it is the region with a 100% duty cycle and the only preset list containing `SHORT_TURBO`, the fastest mode this radio offers. Operating frequency and power remain your responsibility. Three presets are selectable from the dashboard, and changing one propagates to both radios as a single coordinated transaction (see below). Raw air rates are calculated; real payload throughput is well below them once framing and acknowledgements are paid. | Preset | BW | SF | Raw air rate | Realistic payload, one way | |---|---:|---:|---:|---:| | Long Range | 250 kHz | 11 | 1,074 bps | 60 to 90 B/s | | Balanced | 250 kHz | 9 | 3,516 bps | 220 to 300 B/s | | **High Speed** (default) | 500 kHz | 7 | 21,875 bps | **1.2 to 1.6 KB/s** | All figures calculated, none measured. Roughly halve the payload figure per direction when both directions are busy. A 57600 baud UART offers **5,760 B/s**. A 115200 baud UART offers **11,520 B/s**. Both are far more than this link can carry. **Setting the UART to 57600 does not give you 57600 bps over LoRa.** For MAVLink you must reduce the flight controller's stream rates (`SR*` parameters, or a trimmed MAVLink2 stream set) to fit inside roughly 1.2 KB/s. The firmware cannot do this for you, because it does not parse the payload. When you exceed capacity it shows `RF CONGESTION` and counts the dropped bytes rather than hiding the problem. ## Congestion and the transparency caveat The bridge does not parse the payload, so it cannot know where an application message starts or ends. Two consequences: - When the send queue fills, **new bytes are rejected** and counted. Old bytes are never discarded, because dropping from the middle of a stream would silently corrupt a message and hide a stale backlog. - When a frame exceeds its retry or age limit it is **abandoned** so that newer telemetry is not blocked behind it. That punches a hole in the byte stream. **Byte-for-byte fidelity holds only while no frame is abandoned and no buffer overflows.** The dashboard reports both conditions (`Stream gaps`, `Dropped in / out`). No design can simultaneously guarantee finite memory, bounded latency, and exact delivery against a producer that permanently outruns the channel. On reconnect after an outage, the stale backlog is **discarded** rather than replayed. Obsolete telemetry must never delay live telemetry. ## Dashboard At `/bridge` on the Master. Refreshes over `fetch` polling (1 s for status, 5 s for the node list) with no full page reloads. Shows link state, node IDs, RSSI/SNR (instant and smoothed), link quality, RTT, throughput (instant and average), queue occupancy and high-water marks, ARQ window usage, and the full counter set: TX/RX packets and bytes, acknowledgements, retransmissions, abandoned frames, duplicates, rejected frames, stream gaps, and dropped bytes in each direction. **Link quality** is a defined figure rather than an invented one. It is the delivery ratio (frames acknowledged out of frames offered, including retransmissions and abandonments) weighted 70%, plus an SNR term mapped from -20 dB to +10 dB weighted 30%. With no traffic it reports 0, not an optimistic 100. ## Test plan Nothing below has been run yet. | # | Test | Pass criterion | |---|---|---| | 1 | Text | Type in a terminal on A, identical text appears on B | | 2 | Binary | Send all 256 byte values; compare byte-for-byte | | 3 | Large data | Send several MB; compare SHA-256 both ends | | 4 | Bidirectional | Saturate both directions at once; no corruption | | 5 | MAVLink | Pixhawk TELEM → A, B → USB → Mission Planner; then commands back | | 6 | Role reversal | Physically swap the boards; everything still works, no reflash | | 7 | Master select | PRG on one board: Wi-Fi on there, off on the other | | 8 | Peer persistence | Pair, power-cycle both, confirm automatic reconnect | | 9 | RF loss | Block the link; no crash, counters correct, reconnects | | 10 | Congestion | Feed faster than RF capacity; congestion warning, accurate drop counts, no corruption of what does arrive | | 11 | Reliability | Introduce deliberate loss; check retransmissions, RTT, recovery | Tests 1 to 4 only need the two boards and two PCs. Run those first. ### Test 2 and 3 helper ```bash # sender python -c "import sys,serial; p=serial.Serial('COM5',115200); p.write(bytes(range(256))*4096)" # receiver python -c "import serial,hashlib; p=serial.Serial('COM6',115200); d=p.read(256*4096); print(len(d), hashlib.sha256(d).hexdigest())" ``` Compare the receiver's hash against `hashlib.sha256(bytes(range(256))*4096).hexdigest()`. ## Known limitations 1. **Not hardware-tested.** Every performance number is calculated. 2. **No relay.** Two nodes, point-to-point. The frame format reserves addressing and hop limits for later, but multi-hop is neither implemented nor claimed. 3. **One interface at a time.** USB and the external UART cannot both carry payload simultaneously. Auto mode picks whichever is carrying traffic; bytes on the other port are counted and discarded. Merging two independent byte streams would corrupt both. 4. **Relay across a third node is not implemented** and must not be assumed to work. 5. **Exactly-once delivery across reboots is not guaranteed.** A reboot starts a new transport epoch and the peer resynchronises, discarding in-flight data. 6. **Pairing is not cryptographically authenticated.** Channel PSK encryption and session IDs stop casual interference, not a determined attacker with the channel key. ## Licence Derived from Meshtastic firmware, **GPL-3.0**. Any distributed binary must carry the corresponding source. # heltech

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors