mirror of
https://github.com/richonguzman/LoRa_APRS_iGate.git
synced 2026-11-17 19:32:21 +01:00
Compare commits
112
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9db47174f6 | ||
|
|
8fb5135746 | ||
|
|
23f042c83d | ||
|
|
2b6012a0ca | ||
|
|
a79c78d0e3 | ||
|
|
ba3069480b | ||
|
|
e1313dbd7e | ||
|
|
3efa333df4 | ||
|
|
aab05be49f | ||
|
|
f2f0d1725e | ||
|
|
ef7d38e940 | ||
|
|
ac3ff04f46 | ||
|
|
51537e24a8 | ||
|
|
9c1181e7c6 | ||
|
|
1591d9f7fe | ||
|
|
1747922036 | ||
|
|
37afd9a659 | ||
|
|
f9439704f7 | ||
|
|
e2ebd09eec | ||
|
|
9314bf10ba | ||
|
|
a045599df1 | ||
|
|
9930603e99 | ||
|
|
470dbe1907 | ||
|
|
07d21515f5 | ||
|
|
37d73133b3 | ||
|
|
9157d44976 | ||
|
|
1d98b5ae2a | ||
|
|
ad6c813e39 | ||
|
|
dc2e988b57 | ||
|
|
0eaf538cbd | ||
|
|
9a8bbc2a99 | ||
|
|
c0d67acffd | ||
|
|
075ed0e6b4 | ||
|
|
8ded0e96df | ||
|
|
d13227c519 | ||
|
|
8c39abfce9 | ||
|
|
2d2152cdd9 | ||
|
|
b9de2a54b7 | ||
|
|
6280846afb | ||
|
|
662b2e2a2e | ||
|
|
9556eabd80 | ||
|
|
d75c88fc91 | ||
|
|
1257e5d9e0 | ||
|
|
bfeb0f13eb | ||
|
|
9bddbdf20a | ||
|
|
e6f8953da2 | ||
|
|
1876016509 | ||
|
|
2e2921bac0 | ||
|
|
37224200b4 | ||
|
|
504d89c8cc | ||
|
|
023f76e8e3 | ||
|
|
c2f23cd8f0 | ||
|
|
bcaef66d5d | ||
|
|
50be6da1cb | ||
|
|
2d3d287e56 | ||
|
|
a8a13a45ee | ||
|
|
8ab104acb7 | ||
|
|
d6f056cf9c | ||
|
|
8b3a59ed90 | ||
|
|
55979696a0 | ||
|
|
1429dc910d | ||
|
|
c91907523e | ||
|
|
82f9881db4 | ||
|
|
f5d98fa83d | ||
|
|
a4af59c793 | ||
|
|
16e878f8ba | ||
|
|
1904e2ea5b | ||
|
|
59a99e2295 | ||
|
|
07f113f6d1 | ||
|
|
cbde35ae27 | ||
|
|
f7d7502a8f | ||
|
|
3a2241883b | ||
|
|
76d0909639 | ||
|
|
5ef40ce62f | ||
|
|
47807dc8ce | ||
|
|
e83b32534d | ||
|
|
45d0c3c5ed | ||
|
|
67b1f9480a | ||
|
|
5d0bb25251 | ||
|
|
3041c649ca | ||
|
|
190ff6a8f2 | ||
|
|
997e70b462 | ||
|
|
e0268516f1 | ||
|
|
a86cb897b9 | ||
|
|
4e9ce85fd9 | ||
|
|
7b39a0f0ef | ||
|
|
e1177fa521 | ||
|
|
f811ea20b9 | ||
|
|
b29370ef0d | ||
|
|
c5e65e74c1 | ||
|
|
ab6a60d97b | ||
|
|
3cbcff921b | ||
|
|
b36fc813b7 | ||
|
|
76cf3ad89a | ||
|
|
851d178bac | ||
|
|
8dde08c501 | ||
|
|
0292c89246 | ||
|
|
feb9aa711d | ||
|
|
e33e163aa6 | ||
|
|
28088b4035 | ||
|
|
c7742ea793 | ||
|
|
80da843af2 | ||
|
|
a464f909a8 | ||
|
|
76cc11555c | ||
|
|
fe3d001c56 | ||
|
|
ffcd998ed7 | ||
|
|
fda6589fb8 | ||
|
|
7a57e9f667 | ||
|
|
4083f20664 | ||
|
|
3de37e312c | ||
|
|
dbd30c9b18 | ||
|
|
98b041e406 |
No files matched your search
@@ -71,6 +71,8 @@ jobs:
|
||||
chip: esp32s3
|
||||
- name: ttgo_t_beam_s3_SUPREME_v3
|
||||
chip: esp32s3
|
||||
- name: ttgo-t-beam-1W
|
||||
chip: esp32s3
|
||||
- name: ESP32_DIY_LoRa_A7670_SX1278
|
||||
chip: esp32
|
||||
- name: ESP32_DIY_LoRa_A7670_915_SX1276
|
||||
@@ -211,3 +213,60 @@ jobs:
|
||||
files: ${{ matrix.target.name }}.zip
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
build-rp2350:
|
||||
# RP2350 boards (src/rp2350/, maintained by @cvaldess): one zip per board with
|
||||
# firmware.uf2 for the first install (BOOTSEL USB drive) and ota_update.bin
|
||||
# for the web OTA. If one does not build, the release goes on without its zip
|
||||
# and this run stays green with a warning.
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write # upload the zips to the release
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
target:
|
||||
- name: pico2_w5500_e22
|
||||
- name: wiznet_5500_evb_pico2_e22p
|
||||
- name: wiznet_5100s_evb_pico2_e22p
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- uses: actions/setup-python@v7
|
||||
with:
|
||||
python-version: "3.13"
|
||||
|
||||
- name: Install PlatformIO Core
|
||||
run: pip install --upgrade platformio
|
||||
|
||||
- name: Build target
|
||||
id: build
|
||||
continue-on-error: true
|
||||
run: pio run -e ${{ matrix.target.name }}
|
||||
|
||||
- name: Report
|
||||
if: steps.build.outcome == 'failure'
|
||||
run: echo "::warning title=RP2350::${{ matrix.target.name }} did not build, so this release has no zip for it. The RP2350 boards (src/rp2350/) are maintained by @cvaldess."
|
||||
|
||||
- name: Move Files
|
||||
if: steps.build.outcome == 'success'
|
||||
run: |
|
||||
mkdir -p installer/firmware
|
||||
cp .pio/build/${{ matrix.target.name }}/firmware.bin installer/ota_update.bin
|
||||
cp .pio/build/${{ matrix.target.name }}/firmware.uf2 installer/firmware/
|
||||
|
||||
- name: Install Zip
|
||||
if: steps.build.outcome == 'success'
|
||||
run: sudo apt-get install zip
|
||||
|
||||
- name: Archive Files
|
||||
if: steps.build.outcome == 'success'
|
||||
run: zip -r ${{ matrix.target.name }}.zip installer/
|
||||
|
||||
- name: Upload Release Asset
|
||||
if: steps.build.outcome == 'success'
|
||||
uses: softprops/action-gh-release@v3
|
||||
with:
|
||||
files: ${{ matrix.target.name }}.zip
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -28,4 +28,34 @@ jobs:
|
||||
run: pio run -e ${{ matrix.target.name }}
|
||||
|
||||
- name: Build FS
|
||||
run: pio run --target buildfs -e ${{ matrix.target.name }}
|
||||
run: pio run --target buildfs -e ${{ matrix.target.name }}
|
||||
|
||||
build-rp2350:
|
||||
# RP2350 boards (src/rp2350/, maintained by @cvaldess). The W5500 and W5100S
|
||||
# boards cover both Ethernet drivers. Informative only: if one does not
|
||||
# build, this run stays green and leaves a warning.
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
target:
|
||||
- name: wiznet_5500_evb_pico2_e22p
|
||||
- name: wiznet_5100s_evb_pico2_e22p
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- uses: actions/setup-python@v7
|
||||
with:
|
||||
python-version: "3.13"
|
||||
|
||||
- name: Install PlatformIO Core
|
||||
run: pip install --upgrade platformio
|
||||
|
||||
- name: Build target
|
||||
id: build
|
||||
continue-on-error: true
|
||||
run: pio run -e ${{ matrix.target.name }}
|
||||
|
||||
- name: Report
|
||||
if: steps.build.outcome == 'failure'
|
||||
run: echo "::warning title=RP2350::${{ matrix.target.name }} did not build. The RP2350 boards (src/rp2350/) are maintained by @cvaldess."
|
||||
@@ -37,7 +37,7 @@ ____________________________________________________
|
||||
|
||||
- TTGO Lilygo LoRa32 LoRa32 V2.1 (V1.6 is the same) and T3S3 V1.2.
|
||||
|
||||
- TTGO T-Beam V1.0 , V1.1, V1.2 (also variations with SX1262 and SX1268 LoRa Modules) and Supreme V3.
|
||||
- TTGO T-Beam V1.0 , V1.1, V1.2 (also variations with SX1262 and SX1268 LoRa Modules), Supreme V3 and T-Beam 1W.
|
||||
|
||||
- T-Deck Plus (and also regular T-Deck with/without GPS).
|
||||
|
||||
@@ -59,11 +59,15 @@ ____________________________________________________
|
||||
|
||||
- Wemos Lolin32 Oled + SX1278 DIY Version.
|
||||
|
||||
- RP2350 (Raspberry Pi Pico 2) + WIZnet W5500 Ethernet + Ebyte E22 LoRa Module, wired DIY version (see [Wiznet_5500_EVB_Pico2_E22P](https://github.com/cvaldess/Wiznet_5500_EVB_Pico2_E22P)).
|
||||
|
||||
- and many more...
|
||||
|
||||
<br />
|
||||
|
||||
# Timeline (Versions):
|
||||
- 2026-10-14 T-Beam 1W board added (with fan control and Tx over-temperature protection).
|
||||
- 2026-10-05 Fix for stored XSS in received packets, Wifi warning with bad password, date on Rx packets, mDNS kiss-tnc for phone apps, APRSPacketLib V1.0.10 update.
|
||||
- 2026-09-30 GPS baud rate auto-detection, CAD timeout (packet dropped after 10s of busy channel)
|
||||
- 2026-09-23 APRSPacketLib V1.0.7 update and many code cleaning with this.
|
||||
- 2026-09-17 Real APRS Symbols added to map and TNC2 output as a posibility in TNC mode.
|
||||
|
||||
+4
-4
@@ -34,10 +34,10 @@ lib_deps =
|
||||
bblanchon/ArduinoJson @ 7.4.3
|
||||
jgromes/RadioLib @ 7.6.0
|
||||
knolleary/PubSubClient @ 2.8
|
||||
ESP32Async/AsyncTCP @ 3.4.10
|
||||
ESP32Async/ESPAsyncWebServer @ 3.11.1
|
||||
mikalhart/TinyGPSPlus @ 1.0.3
|
||||
richonguzman/APRSPacketLib @ 1.0.7
|
||||
ESP32Async/AsyncTCP @ 3.5.0
|
||||
ESP32Async/ESPAsyncWebServer @ 3.12.1
|
||||
mikalhart/TinyGPSPlus @ 1.1.0
|
||||
richonguzman/APRSPacketLib @ 1.0.10
|
||||
display_libs =
|
||||
adafruit/Adafruit GFX Library @ 1.12.6
|
||||
adafruit/Adafruit SSD1306 @ 2.5.17
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"active": false,
|
||||
"messagesToRF": false,
|
||||
"objectsToRF": false,
|
||||
"is2Metadata": false,
|
||||
"server": "rotate.aprs2.net",
|
||||
"passcode": "XYZVW",
|
||||
"port": 14580,
|
||||
@@ -47,8 +48,8 @@
|
||||
"rxSignalBandwidth": 125000,
|
||||
"txActive": false,
|
||||
"txFreq": 433775000,
|
||||
"txSpreadingFactor": 9,
|
||||
"txCodingRate4": 7,
|
||||
"txSpreadingFactor": 12,
|
||||
"txCodingRate4": 5,
|
||||
"txSignalBandwidth": 125000,
|
||||
"power": 20,
|
||||
"cadActive": true
|
||||
|
||||
+233
-13
@@ -69,6 +69,9 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
#received-packets td:nth-child(1),#received-packets td:nth-child(2),#received-packets td:nth-child(4),#received-packets td:nth-child(5){font-variant-numeric:tabular-nums;}
|
||||
#received-packets td:nth-child(3){overflow-wrap:anywhere;}
|
||||
@media(max-width:768px){.app-sidebar{width:60px;padding:12px 6px;}.side-link .label,.nav-group-label{display:none;}.app-main{padding:14px;}}
|
||||
/* phones: the fixed Date/Time/RSSI/SNR widths left Packet ~90 px wide (and made the page scroll sideways):
|
||||
each packet becomes two lines, date/time/RSSI/SNR on top and the packet across the full width below */
|
||||
@media(max-width:768px){#received-packets table,#received-packets tbody{display:block;}#received-packets thead{display:none;}#received-packets tr{display:flex;flex-wrap:wrap;column-gap:.6rem;row-gap:.15rem;padding:.6rem 0;border-bottom:var(--bs-border-width) solid var(--msh-border);}#received-packets td{border:0;padding:0;font-size:.8rem;color:var(--msh-text-dim);}#received-packets td:nth-child(3){flex-basis:100%;order:1;font-size:.95rem;color:var(--msh-text);}#received-packets td:nth-child(4)::after{content:" dBm";}#received-packets td:nth-child(5)::after{content:" dB";}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -192,6 +195,8 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
<button class="side-link" type="button" data-target="sec-maps"><span class="side-ico"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16"><path d="M15.817.113A.5.5 0 0 1 16 .5v14a.5.5 0 0 1-.402.49l-5 1a.5.5 0 0 1-.196 0L5.5 15.01l-4.902.98A.5.5 0 0 1 0 15.5v-14a.5.5 0 0 1 .402-.49l5-1a.5.5 0 0 1 .196 0L10.5.99l4.902-.98a.5.5 0 0 1 .415.103M10 1.91l-4-.8v12.98l4 .8zm1 12.98 4-.8V1.11l-4 .8zm-6-.8V1.11l-4 .8v12.98z"/></svg></span><span class="label">Map</span></button>
|
||||
<button class="side-link" type="button" id="rpToggle"><span class="side-ico"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M5 11.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5m-3 1a1 1 0 1 0 0-2 1 1 0 0 0 0 2m0 4a1 1 0 1 0 0-2 1 1 0 0 0 0 2m0 4a1 1 0 1 0 0-2 1 1 0 0 0 0 2"/></svg></span><span class="label">Received Packets</span></button>
|
||||
<a href="/received-packets" id="rpDummy" style="display:none" aria-hidden="true"></a>
|
||||
<button class="side-link rp2350-only" type="button" data-target="sec-messages" style="display:none"><span class="side-ico"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16"><path d="M0 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v.217l7 4.2 7-4.2V4a1 1 0 0 0-1-1zm13 2.383-4.708 2.825L15 11.105zm-.034 6.876-5.64-3.471L8 9.583l-1.326-.795-5.64 3.47A1 1 0 0 0 2 13h12a1 1 0 0 0 .966-.741M1 11.105l4.708-2.897L1 5.383z"/></svg></span><span class="label">Messages</span></button>
|
||||
<button class="side-link rp2350-only" type="button" data-target="sec-ota" style="display:none"><span class="side-ico"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16"><path d="M8 2a5.53 5.53 0 0 0-3.594 1.342c-.766.66-1.321 1.52-1.464 2.383C1.266 6.095 0 7.555 0 9.318 0 11.366 1.708 13 3.781 13h8.906C14.502 13 16 11.57 16 9.773c0-1.636-1.242-2.969-2.834-3.194C12.923 3.999 10.69 2 8 2m2.354 5.146a.5.5 0 0 1-.708.708L8.5 6.707V10.5a.5.5 0 0 1-1 0V6.707L6.354 7.854a.5.5 0 1 1-.708-.708l2-2a.5.5 0 0 1 .708 0z"/></svg></span><span class="label">Firmware Update</span></button>
|
||||
<a class="side-link side-ota" href="/update"><span class="side-ico"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16"><path d="M8 2a5.53 5.53 0 0 0-3.594 1.342c-.766.66-1.321 1.52-1.464 2.383C1.266 6.095 0 7.555 0 9.318 0 11.366 1.708 13 3.781 13h8.906C14.502 13 16 11.57 16 9.773c0-1.636-1.242-2.969-2.834-3.194C12.923 3.999 10.69 2 8 2m2.354 5.146a.5.5 0 0 1-.708.708L8.5 6.707V10.5a.5.5 0 0 1-1 0V6.707L6.354 7.854a.5.5 0 1 1-.708-.708l2-2a.5.5 0 0 1 .708 0z"/></svg></span><span class="label">Update OTA</span></a>
|
||||
</aside>
|
||||
<main class="app-main">
|
||||
@@ -220,6 +225,102 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
<hr>
|
||||
</div>
|
||||
<div id="configuration">
|
||||
<section class="panel-section" id="sec-messages">
|
||||
<div class="row my-5 d-flex align-items-top">
|
||||
<div class="col-lg-10 col-sm-12">
|
||||
<h3>Send APRS Message</h3>
|
||||
<small>Send an APRS text message to another station. Tip: send <code>?APRSV</code>, <code>?APRSP</code>, <code>?APRSL</code> or <code>?APRSSR</code> to query another iGate.</small>
|
||||
<div class="row mt-4">
|
||||
<div class="col-lg-4 col-sm-12">
|
||||
<label for="message.to" class="form-label">To (callsign)</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="message.to"
|
||||
placeholder="EA4XXX-7"
|
||||
oninput="this.value = this.value.toUpperCase();"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-lg-8 col-sm-12">
|
||||
<label for="message.text" class="form-label">Message</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="message.text"
|
||||
placeholder="Hello world"
|
||||
maxlength="67"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3 align-items-center">
|
||||
<div class="col-lg-3 col-6">
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox" class="form-check-input" id="message.viaRF" checked />
|
||||
<label class="form-check-label" for="message.viaRF">Send via RF</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-6">
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox" class="form-check-input" id="message.viaTCP" />
|
||||
<label class="form-check-label" for="message.viaTCP">Send via APRS-IS (TCP)</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-sm-12 mt-2 mt-lg-0">
|
||||
<button class="btn btn-primary form-control" type="button" id="send-message">Send message now</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h5 class="mt-5">Received messages</h5>
|
||||
<small>Messages addressed to this iGate's callsign. Refreshes every 10 seconds.</small>
|
||||
<table class="table mt-3">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Ago</th>
|
||||
<th scope="col">From</th>
|
||||
<th scope="col">Via</th>
|
||||
<th scope="col">Message</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="received-messages"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="panel-section" id="sec-ota">
|
||||
<div class="row my-5 d-flex align-items-top">
|
||||
<div class="col-lg-8 col-sm-12">
|
||||
<h3>Firmware Update (OTA)</h3>
|
||||
<small>Upload a new <code>firmware.bin</code> over the network. The device flashes it and reboots into the new firmware automatically.</small>
|
||||
<div class="alert alert-secondary mt-3 mb-0" id="ota.current">Current firmware: …</div>
|
||||
<div class="row mt-4">
|
||||
<div class="col-12">
|
||||
<label for="ota.file" class="form-label">Firmware file (firmware.bin)</label>
|
||||
<input type="file" class="form-control" id="ota.file" accept=".bin" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="col-lg-6 col-sm-12">
|
||||
<label for="ota.user" class="form-label">OTA user <small>(only if configured)</small></label>
|
||||
<input type="text" class="form-control" id="ota.user" placeholder="(optional)" />
|
||||
</div>
|
||||
<div class="col-lg-6 col-sm-12">
|
||||
<label for="ota.pass" class="form-label">OTA password</label>
|
||||
<input type="password" class="form-control" id="ota.pass" placeholder="(optional)" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="col-lg-4 col-sm-12">
|
||||
<button class="btn btn-primary form-control" type="button" id="ota.upload">Upload firmware</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="progress mt-4 d-none" id="ota.progresswrap" style="height: 1.6rem;">
|
||||
<div class="progress-bar" id="ota.progress" role="progressbar" style="width: 0%;">0%</div>
|
||||
</div>
|
||||
<div id="ota.status" class="mt-3"></div>
|
||||
<small class="d-block mt-2 text-muted">Do not power off during the update. The connection will drop when the device reboots — that is normal.</small>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="panel-section" id="sec-maps">
|
||||
<div class="row my-5">
|
||||
<div class="col-12">
|
||||
@@ -291,7 +392,7 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
oninput="this.value = this.value.toUpperCase();"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-12 mt-3">
|
||||
<div class="col-12 col-md-9 mt-3">
|
||||
<label
|
||||
for="beacon.comment"
|
||||
class="form-label"
|
||||
@@ -305,6 +406,30 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
placeholder=""
|
||||
/>
|
||||
</div>
|
||||
<div class="col-12 col-md-3 mt-3">
|
||||
<label
|
||||
for="beacon.rfCommentEveryXBeacons"
|
||||
class="form-label"
|
||||
>RF Comment every</label
|
||||
>
|
||||
<div class="input-group">
|
||||
<input
|
||||
type="number"
|
||||
name="beacon.rfCommentEveryXBeacons"
|
||||
id="beacon.rfCommentEveryXBeacons"
|
||||
class="form-control"
|
||||
value="1"
|
||||
min="1"
|
||||
max="100"
|
||||
step="1"
|
||||
required
|
||||
/>
|
||||
<span class="input-group-text"
|
||||
>beacons
|
||||
</span>
|
||||
</div>
|
||||
<small>(1 = every beacon, RF only)</small>
|
||||
</div>
|
||||
<div class="col-12 mt-3">
|
||||
<label
|
||||
for="beacon.path"
|
||||
@@ -577,6 +702,63 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
</section>
|
||||
<section class="panel-section" id="sec-connectivity">
|
||||
|
||||
<div class="row my-5 align-items-top d-none" id="ip-config-section">
|
||||
<div class="col-lg-3 col-sm-12">
|
||||
<h5>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="20"
|
||||
height="20"
|
||||
fill="currentColor"
|
||||
class="bi bi-diagram-3"
|
||||
viewBox="0 0 16 16"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M6 3.5A1.5 1.5 0 0 1 7.5 2h1A1.5 1.5 0 0 1 10 3.5v1A1.5 1.5 0 0 1 8.5 6v1H14a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-1 0V8h-5v.5a.5.5 0 0 1-1 0V8h-5v.5a.5.5 0 0 1-1 0v-1A.5.5 0 0 1 2 7h5.5V6A1.5 1.5 0 0 1 6 4.5zM8.5 5a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5zM0 11.5A1.5 1.5 0 0 1 1.5 10h1A1.5 1.5 0 0 1 4 11.5v1A1.5 1.5 0 0 1 2.5 14h-1A1.5 1.5 0 0 1 0 12.5zm1.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5zm4.5.5A1.5 1.5 0 0 1 7.5 10h1a1.5 1.5 0 0 1 1.5 1.5v1A1.5 1.5 0 0 1 8.5 14h-1A1.5 1.5 0 0 1 6 12.5zm1.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5zm4.5.5a1.5 1.5 0 0 1 1.5-1.5h1a1.5 1.5 0 0 1 1.5 1.5v1a1.5 1.5 0 0 1-1.5 1.5h-1a1.5 1.5 0 0 1-1.5-1.5zm1.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5z"
|
||||
/>
|
||||
</svg>
|
||||
IP Config
|
||||
</h5>
|
||||
<small>Wired Ethernet: choose DHCP (automatic) or a static IP address.</small>
|
||||
</div>
|
||||
<div class="col-lg-9 col-sm-12">
|
||||
<div class="form-check form-switch">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="network.dhcp"
|
||||
id="network.dhcp"
|
||||
class="form-check-input"
|
||||
checked
|
||||
/>
|
||||
<label for="network.dhcp" class="form-label">Use DHCP (automatic IP)</label>
|
||||
</div>
|
||||
<div id="static-ip-config" class="mt-3" style="display: none;">
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-sm-12">
|
||||
<label for="network.ip" class="form-label">IP Address</label>
|
||||
<input type="text" class="form-control" name="network.ip" id="network.ip" placeholder="192.168.1.50" />
|
||||
</div>
|
||||
<div class="col-lg-6 col-sm-12">
|
||||
<label for="network.gateway" class="form-label">Default Gateway</label>
|
||||
<input type="text" class="form-control" name="network.gateway" id="network.gateway" placeholder="192.168.1.1" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="col-lg-6 col-sm-12">
|
||||
<label for="network.subnet" class="form-label">Subnet Mask</label>
|
||||
<input type="text" class="form-control" name="network.subnet" id="network.subnet" placeholder="255.255.255.0" />
|
||||
</div>
|
||||
<div class="col-lg-6 col-sm-12">
|
||||
<label for="network.dns" class="form-label">DNS Server(s) <small>(space-separated for multiple)</small></label>
|
||||
<input type="text" class="form-control" name="network.dns" id="network.dns" placeholder="8.8.8.8 1.1.1.1" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr id="ip-config-hr" style="display:none">
|
||||
|
||||
|
||||
<div class="row my-5 d-flex align-items-top">
|
||||
<div class="col-lg-3 col-sm-12">
|
||||
@@ -913,6 +1095,22 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-check form-switch">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="aprs_is.is2Metadata"
|
||||
id="aprs_is.is2Metadata"
|
||||
class="form-check-input"
|
||||
/>
|
||||
<label
|
||||
for="aprs_is.is2Metadata"
|
||||
class="form-label"
|
||||
>Send IS2 Metadata
|
||||
(RSSI/SNR) to APRS-IS</label
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<label
|
||||
for="aprs_is.server"
|
||||
@@ -1289,10 +1487,10 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
<option value="6">SF6</option>
|
||||
<option value="7">SF7</option>
|
||||
<option value="8">SF8</option>
|
||||
<option value="9" selected>SF9</option>
|
||||
<option value="9">SF9</option>
|
||||
<option value="10">SF10</option>
|
||||
<option value="11">SF11</option>
|
||||
<option value="12">SF12 - Highest sensitivity</option>
|
||||
<option value="12" selected>SF12 - Highest sensitivity</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-6 mt-3">
|
||||
@@ -1311,10 +1509,10 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
<option value="6">SF6</option>
|
||||
<option value="7">SF7</option>
|
||||
<option value="8">SF8</option>
|
||||
<option value="9" selected>SF9</option>
|
||||
<option value="9">SF9</option>
|
||||
<option value="10">SF10</option>
|
||||
<option value="11">SF11</option>
|
||||
<option value="12">SF12 - Highest sensitivity</option>
|
||||
<option value="12" selected>SF12 - Highest sensitivity</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-6 mt-3">
|
||||
@@ -1329,9 +1527,9 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
id="lora.rxCodingRate4"
|
||||
required=""
|
||||
>
|
||||
<option value="5">5</option>
|
||||
<option value="5" selected>5</option>
|
||||
<option value="6">6</option>
|
||||
<option value="7" selected>7</option>
|
||||
<option value="7">7</option>
|
||||
<option value="8">8</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -1347,9 +1545,9 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
id="lora.txCodingRate4"
|
||||
required=""
|
||||
>
|
||||
<option value="5">5</option>
|
||||
<option value="5" selected>5</option>
|
||||
<option value="6">6</option>
|
||||
<option value="7" selected>7</option>
|
||||
<option value="7">7</option>
|
||||
<option value="8">8</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -1397,7 +1595,7 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
<label
|
||||
for="lora.power"
|
||||
class="form-label">
|
||||
Power
|
||||
Power <small>(SX127X Max 20dBm / SX126X Max 22dBm)</small>
|
||||
</label>
|
||||
<div class="input-group">
|
||||
<input
|
||||
@@ -1405,8 +1603,8 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
name="lora.power"
|
||||
id="lora.power"
|
||||
placeholder="20"
|
||||
min="0"
|
||||
max="20"
|
||||
min="2"
|
||||
max="22"
|
||||
step="1"
|
||||
class="form-control"
|
||||
required=""
|
||||
@@ -2330,6 +2528,28 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
>:
|
||||
LoRa APRS iGate Firmware.
|
||||
</p>
|
||||
<p class="mb-1 small rp2350-only" style="display: none">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
fill="currentColor"
|
||||
class="bi bi-cc-circle-fill"
|
||||
viewBox="0 0 16 16"
|
||||
>
|
||||
<path
|
||||
d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0M5.408 5.89c.681 0 1.138.47 1.187 1.107h1.147v-.11c-.053-1.187-1.024-2-2.343-2-1.604 0-2.518 1.05-2.518 2.751v.747c0 1.7.906 2.73 2.518 2.73 1.314 0 2.285-.792 2.343-1.939v-.114H6.595c-.049.615-.497 1.05-1.187 1.05-.84 0-1.318-.62-1.318-1.727v-.742c0-1.112.488-1.754 1.318-1.754Zm5.404 0c.68 0 1.138.47 1.186 1.107h1.147v-.11c-.053-1.187-1.024-2-2.342-2-1.604 0-2.518 1.05-2.518 2.751v.747c0 1.7.905 2.73 2.518 2.73 1.314 0 2.285-.792 2.342-1.939v-.114h-1.147c-.048.615-.496 1.05-1.186 1.05-.84 0-1.319-.62-1.319-1.727v-.742c0-1.112.488-1.754 1.319-1.754Z"
|
||||
/>
|
||||
</svg>
|
||||
2026
|
||||
<b
|
||||
><a
|
||||
href="https://ea4glo.cvaldess.com"
|
||||
target="_blank"
|
||||
>EA4GLO</a
|
||||
></b
|
||||
>: RP2350 port.
|
||||
</p>
|
||||
<br />
|
||||
<p class="mt-4 small">
|
||||
Support this project<br />
|
||||
@@ -2443,7 +2663,7 @@ body{background:var(--msh-bg);color:var(--msh-text);font-family:"Inter",system-u
|
||||
if(window.fetchReceivedPackets)window.fetchReceivedPackets();
|
||||
});
|
||||
var bi=document.getElementById("buildInfo");
|
||||
if(bi){var h=bi.innerHTML; if(/Version date/i.test(h)){h=h.replace(/(<br\s*\/?>)[\s\S]*?(?=Version date)/i,"$1");bi.innerHTML="Board / Environment = "+h;}}
|
||||
if(bi){var h=bi.innerHTML; if(/Version date/i.test(h)){h=h.replace(/(<br\s*\/?>)[\s\S]*?(?=Version: )/i,"$1");bi.innerHTML="Board / Environment = "+h;}}
|
||||
if(window.loadReceivedPackets){var _o=window.loadReceivedPackets;window.loadReceivedPackets=function(p){if(p&&p.slice){p=p.slice().reverse();}return _o(p);};}
|
||||
})();
|
||||
</script>
|
||||
+283
-2
@@ -36,11 +36,19 @@ document.querySelector("input[type=file]").onchange = function () {
|
||||
};
|
||||
};
|
||||
|
||||
function fetchSettings() {
|
||||
function fetchSettings(retries = 2) {
|
||||
fetch("/configuration.json")
|
||||
.then((response) => response.json())
|
||||
.then((settings) => {
|
||||
loadSettings(settings);
|
||||
}, (err) => {
|
||||
// fetch or JSON failed: a board short of sockets (RP2350 + W5100S) refuses
|
||||
// connections while it serves another one, so try again before giving up
|
||||
if (retries > 0) {
|
||||
setTimeout(() => fetchSettings(retries - 1), 1000);
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
@@ -56,6 +64,7 @@ function loadSettings(settings) {
|
||||
document.getElementById("callsign").value = settings.callsign;
|
||||
document.getElementById("tacticalCallsign").value = settings.tacticalCallsign;
|
||||
document.getElementById("beacon.comment").value = settings.beacon.comment;
|
||||
document.getElementById("beacon.rfCommentEveryXBeacons").value = settings.beacon.rfCommentEveryXBeacons;
|
||||
document.getElementById("beacon.path").value = settings.beacon.path;
|
||||
document.getElementById("beacon.symbol").value = settings.beacon.symbol;
|
||||
document.getElementById("beacon.overlay").value = settings.beacon.overlay;
|
||||
@@ -102,6 +111,7 @@ function loadSettings(settings) {
|
||||
document.getElementById("aprs_is.active").checked = settings.aprs_is.active;
|
||||
document.getElementById("aprs_is.messagesToRF").checked = settings.aprs_is.messagesToRF;
|
||||
document.getElementById("aprs_is.objectsToRF").checked = settings.aprs_is.objectsToRF;
|
||||
document.getElementById("aprs_is.is2Metadata").checked = settings.aprs_is.is2Metadata;
|
||||
document.getElementById("aprs_is.server").value = settings.aprs_is.server;
|
||||
document.getElementById("aprs_is.port").value = settings.aprs_is.port;
|
||||
document.getElementById("aprs_is.filter").value = settings.aprs_is.filter;
|
||||
@@ -109,6 +119,7 @@ function loadSettings(settings) {
|
||||
APRSISCheckbox.checked = settings.aprs_is.active;
|
||||
APRSISGateMessages.disabled = !APRSISCheckbox.checked;
|
||||
APRSISGateObjects.disabled = !APRSISCheckbox.checked;
|
||||
APRSISMetadata.disabled = !APRSISCheckbox.checked;
|
||||
APRSISServer.disabled = !APRSISCheckbox.checked;
|
||||
APRSISPort.disabled = !APRSISCheckbox.checked;
|
||||
APRSISPasscode.disabled = !APRSISCheckbox.checked;
|
||||
@@ -277,7 +288,8 @@ function loadSettings(settings) {
|
||||
document.getElementById("ntp.server").value = settings.ntp.server;
|
||||
document.getElementById("ntp.gmtCorrection").value = settings.ntp.gmtCorrection;
|
||||
|
||||
clampOutOfRangeInputs();
|
||||
applyWiredBuildUi(settings); // RP2350 + Ethernet build (see bottom of this file)
|
||||
clampOutOfRangeInputs(); // keep the form submittable (see bottom of this file)
|
||||
|
||||
updateImage();
|
||||
}
|
||||
@@ -349,6 +361,7 @@ StatusCheckbox.addEventListener("change", function() {
|
||||
const APRSISCheckbox = document.querySelector('input[name="aprs_is.active"]');
|
||||
const APRSISGateMessages = document.querySelector('input[name="aprs_is.messagesToRF"]');
|
||||
const APRSISGateObjects = document.querySelector('input[name="aprs_is.objectsToRF"]');
|
||||
const APRSISMetadata = document.querySelector('input[name="aprs_is.is2Metadata"]');
|
||||
const APRSISServer = document.querySelector('input[name="aprs_is.server"]');
|
||||
const APRSISPort = document.querySelector('input[name="aprs_is.port"]');
|
||||
const APRSISPasscode = document.querySelector('input[name="aprs_is.passcode"]');
|
||||
@@ -356,6 +369,7 @@ const APRSISFilter = document.querySelector('input[name="aprs_is.fi
|
||||
APRSISCheckbox.addEventListener("change", function() {
|
||||
APRSISGateMessages.disabled = !this.checked;
|
||||
APRSISGateObjects.disabled = !this.checked;
|
||||
APRSISMetadata.disabled = !this.checked;
|
||||
APRSISServer.disabled = !this.checked;
|
||||
APRSISPort.disabled = !this.checked;
|
||||
APRSISPasscode.disabled = !this.checked;
|
||||
@@ -1115,6 +1129,273 @@ window.showMap = function () {
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------- wired (RP2350) build
|
||||
* The RP2350 + WIZnet W5500 port serves this same page, but that board has no
|
||||
* WiFi, no display and no ElegantOTA page, and it adds a wired IP configuration,
|
||||
* an APRS "Messages" view and its own OTA uploader. All of it is feature-detected
|
||||
* from the configuration ("network" only exists on the wired build), so on ESP32
|
||||
* boards nothing below changes the UI.
|
||||
*/
|
||||
function isWiredBuild(settings) {
|
||||
return !!(settings && settings.network);
|
||||
}
|
||||
|
||||
function markUnavailable(id, note) {
|
||||
const el = document.getElementById(id);
|
||||
if (!el) return;
|
||||
el.disabled = true;
|
||||
el.title = note || "Not available on this board";
|
||||
}
|
||||
|
||||
// Replace the description of the settings block a control belongs to.
|
||||
function describeSection(id, html) {
|
||||
const el = document.getElementById(id);
|
||||
if (!el) return;
|
||||
const row = el.closest(".row.my-5") || el.closest(".row");
|
||||
if (!row) return;
|
||||
const small = row.querySelector("small");
|
||||
if (small && !small.dataset.wiredNote) {
|
||||
small.innerHTML = html;
|
||||
small.dataset.wiredNote = "1";
|
||||
}
|
||||
}
|
||||
|
||||
function applyWiredBuildUi(settings) {
|
||||
if (!isWiredBuild(settings)) return;
|
||||
|
||||
// --- wired IP configuration (DHCP or static), shown only on this build
|
||||
const net = settings.network;
|
||||
document.getElementById("network.dhcp").checked = net.dhcp;
|
||||
document.getElementById("network.ip").value = net.ip || "";
|
||||
document.getElementById("network.gateway").value = net.gateway || "";
|
||||
document.getElementById("network.subnet").value = net.subnet || "255.255.255.0";
|
||||
document.getElementById("network.dns").value = net.dns || "";
|
||||
document.getElementById("ip-config-section").classList.remove("d-none"); // d-flex would override an inline display:none (!important), so the row hides with d-none
|
||||
document.getElementById("ip-config-hr").style.display = "";
|
||||
document.getElementById("static-ip-config").style.display = net.dhcp ? "none" : "";
|
||||
|
||||
// --- sidebar: this build has its own Messages + OTA views, and no ElegantOTA;
|
||||
// the footer credits the port
|
||||
document.querySelectorAll(".rp2350-only").forEach(function (el) {
|
||||
el.style.display = "";
|
||||
});
|
||||
const elegantOta = document.querySelector(".side-link.side-ota");
|
||||
if (elegantOta) elegantOta.style.display = "none";
|
||||
|
||||
// --- APRS-IS -> RF gating is not ported: this build is a receive-only iGate (qAO).
|
||||
// Kept disabled when "Enable APRS-IS connection" is toggled, too.
|
||||
const disableGateToRf = function () {
|
||||
["aprs_is.messagesToRF", "aprs_is.objectsToRF"].forEach(function (id) {
|
||||
const el = document.getElementById(id);
|
||||
if (el) el.checked = false;
|
||||
markUnavailable(id, "Not available on this board: it only gates RF to APRS-IS");
|
||||
});
|
||||
};
|
||||
disableGateToRf();
|
||||
document.getElementById("aprs_is.active").addEventListener("change", disableGateToRf);
|
||||
describeSection("aprs_is.active",
|
||||
"Enter your APRS-IS server and credentials.<br><br>This board only gates RF → APRS-IS "
|
||||
+ "(receive-only iGate): <b>Gate APRS-IS Messages / Objects to RF</b> are not available.");
|
||||
|
||||
// --- WiFi: not present on this board
|
||||
["wifi.autoAP.enabled", "wifi.autoAP.password", "wifi.autoAP.timeout"].forEach(function (id) {
|
||||
markUnavailable(id, "This board connects over Ethernet, it has no WiFi");
|
||||
});
|
||||
const addAp = document.querySelector('[data-bs-target="#add-ap"]');
|
||||
if (addAp) addAp.disabled = true;
|
||||
describeSection("wifi.autoAP.enabled", "<b>Not available</b> — this board connects via Ethernet (W5500), it has no WiFi.");
|
||||
|
||||
// --- Display: headless iGate
|
||||
["display.alwaysOn", "display.turn180", "display.timeout"].forEach(function (id) {
|
||||
markUnavailable(id, "Headless build, no display");
|
||||
});
|
||||
describeSection("display.alwaysOn", "<b>Not available</b> — this is a headless iGate (no display).");
|
||||
|
||||
// --- Battery: only the internal (VSYS) reading exists here
|
||||
["battery.monitorInternalVoltage", "battery.internalSleepVoltage", "battery.sendExternalVoltage",
|
||||
"battery.useExternalI2CSensor", "battery.monitorExternalVoltage", "battery.externalSleepVoltage",
|
||||
"battery.externalVoltagePin", "battery.voltageDividerR1", "battery.voltageDividerR2"].forEach(function (id) {
|
||||
markUnavailable(id, "Needs hardware this iGate does not have");
|
||||
});
|
||||
describeSection("battery.sendInternalVoltage",
|
||||
"Supply-voltage (VSYS) monitor.<br><br>Only <b>Send Internal Voltage</b> (adds <code>Batt=</code> to the beacon) "
|
||||
+ "and <b>Send Voltage As Telemetry</b> are available — the external-voltage / health-sleep options need "
|
||||
+ "hardware this iGate does not have and are disabled.");
|
||||
}
|
||||
|
||||
const dhcpCheckbox = document.getElementById("network.dhcp");
|
||||
if (dhcpCheckbox) {
|
||||
dhcpCheckbox.addEventListener("change", function () {
|
||||
document.getElementById("static-ip-config").style.display = this.checked ? "none" : "";
|
||||
});
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------- Messages view */
|
||||
let receivedMessagesTimer = null;
|
||||
|
||||
function loadReceivedMessages() {
|
||||
fetch("/messages.json")
|
||||
.then((r) => r.json())
|
||||
.then((msgs) => {
|
||||
const tbody = document.getElementById("received-messages");
|
||||
if (!tbody) return;
|
||||
if (!msgs.length) {
|
||||
tbody.innerHTML = '<tr><td colspan="4" class="text-muted">No messages received yet.</td></tr>';
|
||||
return;
|
||||
}
|
||||
tbody.innerHTML = msgs.map((m) => {
|
||||
const ago = m.age < 60 ? m.age + "s" : Math.floor(m.age / 60) + "m";
|
||||
const esc = (t) => t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||
return "<tr><td>" + ago + "</td><td>" + esc(m.from) + "</td><td>" + esc(m.via || "") + "</td><td>" + esc(m.text) + "</td></tr>";
|
||||
}).join("");
|
||||
})
|
||||
.catch((err) => console.error("Failed to load messages", err));
|
||||
}
|
||||
|
||||
const sendMessageButton = document.getElementById("send-message");
|
||||
if (sendMessageButton) {
|
||||
sendMessageButton.addEventListener("click", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const to = document.getElementById("message.to").value.trim();
|
||||
const text = document.getElementById("message.text").value.trim();
|
||||
const viaRF = document.getElementById("message.viaRF").checked;
|
||||
const viaTCP = document.getElementById("message.viaTCP").checked;
|
||||
if (!to || !text) {
|
||||
showToast("Enter both a destination callsign and a message.");
|
||||
return;
|
||||
}
|
||||
if (!viaRF && !viaTCP) {
|
||||
showToast("Pick at least one path: RF and/or APRS-IS.");
|
||||
return;
|
||||
}
|
||||
|
||||
const params = "to=" + encodeURIComponent(to) + "&text=" + encodeURIComponent(text)
|
||||
+ "&rf=" + (viaRF ? "1" : "0") + "&tcp=" + (viaTCP ? "1" : "0");
|
||||
// the iGate answers with what really went out, e.g. "queued (RF); not sent: APRS-IS (not connected)"
|
||||
fetch("/action?type=send-message&" + params, { method: "POST" })
|
||||
.then((r) => r.text().then((reply) => {
|
||||
showToast("Message to <b>" + escapeHtml(to) + "</b>: " + escapeHtml(reply) + ".");
|
||||
if (r.ok) document.getElementById("message.text").value = "";
|
||||
}))
|
||||
.catch(() => showToast("Could not reach the iGate: message not sent."));
|
||||
});
|
||||
}
|
||||
|
||||
const messagesLink = document.querySelector('.side-link[data-target="sec-messages"]');
|
||||
if (messagesLink) {
|
||||
messagesLink.addEventListener("click", function () {
|
||||
loadReceivedMessages();
|
||||
if (!receivedMessagesTimer) {
|
||||
receivedMessagesTimer = setInterval(function () { // refresh only while visible
|
||||
const section = document.getElementById("sec-messages");
|
||||
if (section && section.classList.contains("active")) loadReceivedMessages();
|
||||
}, 10000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ OTA (firmware update) */
|
||||
let otaPrevBuild = "";
|
||||
|
||||
function loadOtaStatus() {
|
||||
const el = document.getElementById("ota.current");
|
||||
if (!el) return;
|
||||
fetch("/status", { cache: "no-store" })
|
||||
.then((r) => r.text())
|
||||
.then((text) => { otaPrevBuild = text.trim(); el.innerHTML = "Current firmware: <b>" + otaPrevBuild + "</b>"; })
|
||||
.catch(() => { el.textContent = "Current firmware: (could not read /status)"; });
|
||||
}
|
||||
|
||||
// after an update: poll /status until the device is back, then confirm
|
||||
function waitForReboot(prev, attempt) {
|
||||
attempt = attempt || 0;
|
||||
const status = document.getElementById("ota.status");
|
||||
const el = document.getElementById("ota.current");
|
||||
if (attempt > 25) {
|
||||
status.innerHTML = '<span class="text-warning">Device did not respond after the update — please check it manually.</span>';
|
||||
return;
|
||||
}
|
||||
const controller = new AbortController();
|
||||
const t = setTimeout(() => controller.abort(), 1500);
|
||||
fetch("/status", { cache: "no-store", signal: controller.signal })
|
||||
.then((r) => r.text())
|
||||
.then((text) => {
|
||||
clearTimeout(t);
|
||||
const now = text.trim();
|
||||
el.innerHTML = "Current firmware: <b>" + now + "</b>";
|
||||
if (now !== prev) {
|
||||
status.innerHTML = '<span class="text-success"><b>✓ Update complete.</b> Now running the new firmware.</span>';
|
||||
} else {
|
||||
status.innerHTML = '<span class="text-success"><b>✓ Device is back online</b> (firmware version unchanged).</span>';
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
clearTimeout(t);
|
||||
status.textContent = "Waiting for the device to reboot... (" + (attempt + 1) + ")";
|
||||
setTimeout(() => waitForReboot(prev, attempt + 1), 2000);
|
||||
});
|
||||
}
|
||||
|
||||
const otaLink = document.querySelector('.side-link[data-target="sec-ota"]');
|
||||
if (otaLink) otaLink.addEventListener("click", loadOtaStatus);
|
||||
|
||||
const otaUploadButton = document.getElementById("ota.upload");
|
||||
if (otaUploadButton) {
|
||||
otaUploadButton.addEventListener("click", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const file = document.getElementById("ota.file").files[0];
|
||||
if (!file) { showToast("Pick a firmware.bin file first."); return; }
|
||||
|
||||
const user = document.getElementById("ota.user").value.trim();
|
||||
const pass = document.getElementById("ota.pass").value;
|
||||
const wrap = document.getElementById("ota.progresswrap");
|
||||
const bar = document.getElementById("ota.progress");
|
||||
const status = document.getElementById("ota.status");
|
||||
|
||||
wrap.classList.remove("d-none");
|
||||
bar.style.width = "0%"; bar.textContent = "0%";
|
||||
status.textContent = "Uploading " + file.name + " (" + file.size + " bytes)...";
|
||||
|
||||
let bodySent = false;
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/update", true);
|
||||
if (user) xhr.setRequestHeader("Authorization", "Basic " + btoa(user + ":" + pass));
|
||||
|
||||
xhr.upload.onprogress = function (ev) {
|
||||
if (ev.lengthComputable) {
|
||||
const pct = Math.round(ev.loaded * 100 / ev.total);
|
||||
bar.style.width = pct + "%"; bar.textContent = pct + "%";
|
||||
}
|
||||
};
|
||||
xhr.upload.onload = function () { bodySent = true; };
|
||||
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
bar.style.width = "100%"; bar.textContent = "100%";
|
||||
status.innerHTML = "Update staged — waiting for the device to reboot...";
|
||||
setTimeout(() => waitForReboot(otaPrevBuild, 0), 4000);
|
||||
} else if (xhr.status === 401) {
|
||||
status.innerHTML = '<span class="text-danger">Unauthorized — check the OTA user/password.</span>';
|
||||
} else {
|
||||
status.innerHTML = '<span class="text-danger">Update failed: ' + xhr.status + " " + xhr.responseText + "</span>";
|
||||
}
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
if (bodySent) { // socket dropped after the full upload = device rebooting
|
||||
bar.style.width = "100%"; bar.textContent = "100%";
|
||||
status.innerHTML = "Update sent — waiting for the device to reboot...";
|
||||
setTimeout(() => waitForReboot(otaPrevBuild, 0), 4000);
|
||||
} else {
|
||||
status.innerHTML = '<span class="text-danger">Upload failed (connection error before the firmware was fully sent).</span>';
|
||||
}
|
||||
};
|
||||
xhr.send(file);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------- keeping the form submittable
|
||||
* A control that fails HTML5 validation blocks the whole form, and when it sits in
|
||||
* a panel that is not the visible one the browser cannot show its bubble either:
|
||||
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
double latitude;
|
||||
double longitude;
|
||||
String comment;
|
||||
int rfCommentEveryXBeacons;
|
||||
int interval;
|
||||
String overlay;
|
||||
String symbol;
|
||||
@@ -64,6 +65,7 @@ public:
|
||||
String filter;
|
||||
bool messagesToRF;
|
||||
bool objectsToRF;
|
||||
bool is2Metadata;
|
||||
};
|
||||
|
||||
class DIGI {
|
||||
@@ -171,6 +173,15 @@ public:
|
||||
bool beaconOverMqtt;
|
||||
};
|
||||
|
||||
class NETWORK { // IP configuration (Ethernet boards)
|
||||
public:
|
||||
bool dhcp; // true = DHCP, false = static IP below
|
||||
String ip;
|
||||
String gateway;
|
||||
String subnet;
|
||||
String dns; // one or more servers, space/comma-separated
|
||||
};
|
||||
|
||||
class Configuration {
|
||||
public:
|
||||
String callsign;
|
||||
@@ -197,6 +208,7 @@ public:
|
||||
NTP ntp;
|
||||
REMOTE_MANAGEMENT remoteManagement;
|
||||
MQTT mqtt;
|
||||
NETWORK network;
|
||||
|
||||
void setup();
|
||||
void setDefaultValues();
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
namespace GPS_Utils {
|
||||
|
||||
String getiGateLoRaBeaconPacket();
|
||||
void generateBeacons();
|
||||
String buildDistanceAndComment(float latitude, float longitude, const String& comment);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
namespace LoRa_Utils {
|
||||
|
||||
int validPower(int requested);
|
||||
void setup();
|
||||
void sendNewPacket(const String& newPacket);
|
||||
String receivePacketFromSleep();
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
|
||||
namespace QUERY_Utils {
|
||||
|
||||
String process(const String& query, const String& station, bool queryFromAPRSIS, bool thirdParty);
|
||||
bool isQuery(const String& message);
|
||||
String process(const String& query, const String& station, bool queryFromAPRSIS, bool thirdParty);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/* Copyright (C) 2026 Ricardo Guzman - CA2RXU
|
||||
*
|
||||
* This file is part of LoRa APRS iGate.
|
||||
*
|
||||
* LoRa APRS iGate is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LoRa APRS iGate is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Fan / thermal control adapted from KJ7NYE's LoRa_FieldOps_APRS_Tracker (GPLv3)
|
||||
|
||||
#ifndef THERMAL_UTILS_H_
|
||||
#define THERMAL_UTILS_H_
|
||||
|
||||
#include "board_pinout.h"
|
||||
|
||||
#ifdef FAN_CTRL_PIN
|
||||
|
||||
namespace THERMAL_Utils {
|
||||
|
||||
void setup();
|
||||
void monitor();
|
||||
void onTxStart();
|
||||
void onTxEnd();
|
||||
void turnOffFan();
|
||||
bool isTxBlocked();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -40,6 +40,7 @@ namespace Utils {
|
||||
void checkBeaconInterval();
|
||||
void checkDisplayInterval();
|
||||
void validateFreqs();
|
||||
String padForDisplay(const String& text);
|
||||
void updateLoRaPacketDisplayInfo(APRSPacket& aprsPacket, const uint8_t packetType);
|
||||
void updateAPRSISPacketDisplayInfo(const String& packet);
|
||||
void print(const String& text);
|
||||
|
||||
@@ -20,6 +20,7 @@ platform = espressif32 @ 6.12.0
|
||||
board_build.partitions = min_spiffs.csv
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
build_src_filter = +<*> -<rp2350/> ; src/rp2350/ is the RP2350 port, built only by its own envs
|
||||
board_build.embed_files =
|
||||
data_embed/index.html.gz
|
||||
data_embed/style.css.gz
|
||||
|
||||
@@ -197,6 +197,7 @@
|
||||
}
|
||||
|
||||
void uploadToAPRSIS(const String& packet) {
|
||||
if (packet == "") return; // never send an empty line to APRS-IS
|
||||
beaconBytesSent = checkATResponse("AT+CIPSEND=0," + String(packet.length()+1));
|
||||
delay(2000);
|
||||
if (beaconBytesSent) {
|
||||
|
||||
+12
-2
@@ -52,6 +52,7 @@ ___________________________________________________________________*/
|
||||
#include "syslog_utils.h"
|
||||
#include "power_utils.h"
|
||||
#include "sleep_utils.h"
|
||||
#include "thermal_utils.h"
|
||||
#include "mqtt_utils.h"
|
||||
#include "lora_utils.h"
|
||||
#include "wifi_utils.h"
|
||||
@@ -68,8 +69,8 @@ ___________________________________________________________________*/
|
||||
#endif
|
||||
|
||||
|
||||
String versionDate = "2026-10-02";
|
||||
String versionNumber = "4.0.2";
|
||||
String versionDate = "2026-11-17";
|
||||
String versionNumber = "4.0.5";
|
||||
Configuration Config;
|
||||
WiFiClient aprsIsClient;
|
||||
WiFiClient mqttClient;
|
||||
@@ -108,6 +109,9 @@ void setup() {
|
||||
}
|
||||
networkManager->setHostName("iGATE-" + Config.callsign);
|
||||
POWER_Utils::setup();
|
||||
#ifdef FAN_CTRL_PIN
|
||||
THERMAL_Utils::setup();
|
||||
#endif
|
||||
Utils::setupDisplay();
|
||||
LoRa_Utils::setup();
|
||||
Utils::validateFreqs();
|
||||
@@ -135,6 +139,9 @@ void loop() {
|
||||
SLEEP_Utils::checkWakeUpFlag();
|
||||
Utils::checkBeaconInterval();
|
||||
STATION_Utils::processOutputPacketBufferUltraEcoMode();
|
||||
#ifdef FAN_CTRL_PIN
|
||||
THERMAL_Utils::monitor();
|
||||
#endif
|
||||
Utils::checkSleepByLowBatteryVoltage(1);
|
||||
SLEEP_Utils::startSleeping();
|
||||
} else {
|
||||
@@ -222,6 +229,9 @@ void loop() {
|
||||
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
||||
#endif
|
||||
|
||||
#ifdef FAN_CTRL_PIN
|
||||
THERMAL_Utils::monitor();
|
||||
#endif
|
||||
Utils::checkRebootTime();
|
||||
Utils::checkSleepByLowBatteryVoltage(1);
|
||||
}
|
||||
|
||||
+40
-54
@@ -60,6 +60,7 @@ uint32_t lastServerCheck = 0;
|
||||
namespace APRS_IS_Utils {
|
||||
|
||||
void upload(const String& line) {
|
||||
if (line == "") return; // never send an empty line to APRS-IS
|
||||
aprsIsClient.print(line + "\r\n");
|
||||
}
|
||||
|
||||
@@ -151,42 +152,36 @@ namespace APRS_IS_Utils {
|
||||
return packetToUpload;
|
||||
}
|
||||
|
||||
String buildIS2Meta() {
|
||||
static String fixedTail; // rx_modem + rx_bitrate + rx_frequency: RX config doesn't change at runtime
|
||||
if (fixedTail == "") {
|
||||
// LoRa bit rate = SF * (BW / 2^SF) * 4/CR (CR = denominator: 5..8)
|
||||
uint32_t bitrate = (uint32_t)(Config.loramodule.rxSpreadingFactor
|
||||
* ((float)Config.loramodule.rxSignalBandwidth / (1 << Config.loramodule.rxSpreadingFactor))
|
||||
* (4.0 / Config.loramodule.rxCodingRate4));
|
||||
fixedTail = " rx_modem=2 rx_bitrate=" + String(bitrate) + " rx_frequency=" + String(Config.loramodule.rxFreq);
|
||||
}
|
||||
return "#is2-meta rx_rssi_dbm=" + String(lastAprsPacket.rssi) + " rx_snr_db=" + String(lastAprsPacket.snr, 1) + fixedTail;
|
||||
}
|
||||
|
||||
bool processReceivedLoRaMessage(const String& sender, const String& packet) {
|
||||
String receivedMessage;
|
||||
int leftCurlyBraceIndex = packet.indexOf("{");
|
||||
int colonIndex = packet.indexOf(":");
|
||||
if (leftCurlyBraceIndex > 0) { // ack?
|
||||
String ackMessage = "ack";
|
||||
ackMessage.concat(packet.substring(leftCurlyBraceIndex + 1));
|
||||
ackMessage.trim();
|
||||
//Serial.println(ackMessage);
|
||||
|
||||
String addToBuffer = Config.callsign;
|
||||
addToBuffer += ">APLRG1";
|
||||
if (lastAprsPacket.header == "") addToBuffer += ",RFONLY";
|
||||
if (Config.beacon.path != "") {
|
||||
addToBuffer += ",";
|
||||
addToBuffer += Config.beacon.path;
|
||||
}
|
||||
addToBuffer += "::";
|
||||
|
||||
String processedSender = sender;
|
||||
for (int i = sender.length(); i < 9; i++) {
|
||||
processedSender += ' ';
|
||||
}
|
||||
addToBuffer += processedSender;
|
||||
|
||||
addToBuffer += ":";
|
||||
addToBuffer += ackMessage;
|
||||
STATION_Utils::addToOutputPacketBuffer(addToBuffer);
|
||||
String ackCallsign = (Config.tacticalCallsign == "") ? Config.callsign : Config.tacticalCallsign; // ack from the callsign the message was addressed to
|
||||
String ackPath = (lastAprsPacket.header == "") ? "RFONLY," + Config.beacon.path : Config.beacon.path;
|
||||
String ackPacket = APRSPacketLib::generateAckPacket(ackCallsign, "APLRG1", ackPath, sender, packet);
|
||||
if (ackPacket != "") STATION_Utils::addToOutputPacketBuffer(ackPacket);
|
||||
receivedMessage = packet.substring(colonIndex + 1, leftCurlyBraceIndex);
|
||||
} else {
|
||||
receivedMessage = packet.substring(colonIndex + 1);
|
||||
}
|
||||
if (receivedMessage.indexOf("?") == 0) {
|
||||
if (QUERY_Utils::isQuery(receivedMessage)) {
|
||||
if (!Config.display.alwaysOn && Config.display.timeout != 0) displayToggle(true);
|
||||
|
||||
STATION_Utils::addToOutputPacketBuffer(QUERY_Utils::process(receivedMessage, sender, false, lastAprsPacket.header != ""));
|
||||
String queryAnswer = QUERY_Utils::process(receivedMessage, sender, false, lastAprsPacket.header != "");
|
||||
if (queryAnswer != "") STATION_Utils::addToOutputPacketBuffer(queryAnswer); // unknown query: no answer
|
||||
lastScreenOn = millis();
|
||||
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, "Callsign = " + sender, "TYPE --> QUERY", 0);
|
||||
return true;
|
||||
@@ -219,7 +214,11 @@ namespace APRS_IS_Utils {
|
||||
A7670_Utils::uploadToAPRSIS(aprsPacketToUpload);
|
||||
stationBeacon = false;
|
||||
#else
|
||||
upload(aprsPacketToUpload);
|
||||
if (Config.aprs_is.is2Metadata && aprsPacketToUpload != "") {
|
||||
upload(buildIS2Meta() + "\r\n" + aprsPacketToUpload); // IS2PLAIN: meta line right before the packet, same write
|
||||
} else {
|
||||
upload(aprsPacketToUpload);
|
||||
}
|
||||
#endif
|
||||
Utils::println("(Uploaded to APRS-IS)");
|
||||
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
||||
@@ -274,21 +273,9 @@ namespace APRS_IS_Utils {
|
||||
}
|
||||
|
||||
void processAckMessage(const String& sender, const String& message) {
|
||||
String ackPacket = Config.callsign;
|
||||
ackPacket += ">APLRG1,TCPIP,qAC::";
|
||||
|
||||
String senderCallsign = sender;
|
||||
for (int i = sender.length(); i < 9; i++) {
|
||||
senderCallsign += ' ';
|
||||
}
|
||||
ackPacket += senderCallsign;
|
||||
ackPacket += ":";
|
||||
|
||||
String ackMessage = "ack";
|
||||
ackMessage += message.substring(message.indexOf("{") + 1);
|
||||
ackMessage.trim();
|
||||
ackPacket += ackMessage;
|
||||
|
||||
String ackPacket = APRSPacketLib::generateAckPacket(Config.callsign, "APLRG1", "", sender, message);
|
||||
if (ackPacket == "") return;
|
||||
ackPacket = APRSPacketLib::generateAPRSISPacket(ackPacket);
|
||||
#ifdef HAS_A7670
|
||||
A7670_Utils::uploadToAPRSIS(ackPacket);
|
||||
#else
|
||||
@@ -314,7 +301,7 @@ namespace APRS_IS_Utils {
|
||||
if (Config.digi.backupDigiMode) lastServerCheck = currentTime;
|
||||
} else {
|
||||
int doubleColonIndex = packet.indexOf("::");
|
||||
if (Config.aprs_is.messagesToRF && doubleColonIndex > 0) {
|
||||
if (doubleColonIndex > 0) { // messages for this station are always answered; messagesToRF only gates forwarding to RF
|
||||
String Sender = packet.substring(0, packet.indexOf(">"));
|
||||
const String& AddresseeAndMessage = packet.substring(doubleColonIndex + 2);
|
||||
int colonIndex = AddresseeAndMessage.indexOf(":");
|
||||
@@ -329,7 +316,7 @@ namespace APRS_IS_Utils {
|
||||
} else {
|
||||
receivedMessage = AddresseeAndMessage.substring(colonIndex + 1);
|
||||
}
|
||||
if (receivedMessage.indexOf("?") == 0) {
|
||||
if (QUERY_Utils::isQuery(receivedMessage)) {
|
||||
Utils::println("Rx Query (APRS-IS) : " + packet);
|
||||
String queryAnswer = QUERY_Utils::process(receivedMessage, Sender, true, false);
|
||||
//Serial.println("---> QUERY Answer : " + queryAnswer.substring(0,queryAnswer.indexOf("\n")));
|
||||
@@ -337,24 +324,23 @@ namespace APRS_IS_Utils {
|
||||
displayToggle(true);
|
||||
}
|
||||
lastScreenOn = currentTime;
|
||||
#ifdef HAS_A7670
|
||||
A7670_Utils::uploadToAPRSIS(queryAnswer);
|
||||
#else
|
||||
upload(queryAnswer);
|
||||
#endif
|
||||
SYSLOG_Utils::logAPRSISTx(queryAnswer);
|
||||
fifthLine = "APRS-IS ----> APRS-IS";
|
||||
sixthLine = Config.callsign;
|
||||
for (int j = sixthLine.length();j < 9;j++) {
|
||||
sixthLine += " ";
|
||||
if (queryAnswer != "") { // unknown query: no answer
|
||||
#ifdef HAS_A7670
|
||||
A7670_Utils::uploadToAPRSIS(queryAnswer);
|
||||
#else
|
||||
upload(queryAnswer);
|
||||
#endif
|
||||
SYSLOG_Utils::logAPRSISTx(queryAnswer);
|
||||
}
|
||||
fifthLine = "APRS-IS ----> APRS-IS";
|
||||
sixthLine = Utils::padForDisplay(Config.callsign);
|
||||
sixthLine += "> ";
|
||||
sixthLine += Sender;
|
||||
seventhLine = "QUERY = ";
|
||||
seventhLine += receivedMessage;
|
||||
}
|
||||
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
||||
} else {
|
||||
} else if (Config.aprs_is.messagesToRF) {
|
||||
Utils::print("Rx Message (APRS-IS): " + packet);
|
||||
if (STATION_Utils::wasHeard(Addressee) && packet.indexOf("EQNS.") == -1 && packet.indexOf("UNIT.") == -1 && packet.indexOf("PARM.") == -1) {
|
||||
STATION_Utils::addToOutputPacketBuffer(buildPacketToTx(packet, 1));
|
||||
|
||||
+88
-9
@@ -17,7 +17,17 @@
|
||||
*/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
#include <LittleFS.h>
|
||||
#define IGATE_FS LittleFS
|
||||
#define IGATE_FS_BEGIN() LittleFS.begin()
|
||||
#define IGATE_RESTART() rp2040.restart()
|
||||
#else
|
||||
#include <SPIFFS.h>
|
||||
#define IGATE_FS SPIFFS
|
||||
#define IGATE_FS_BEGIN() SPIFFS.begin(false)
|
||||
#define IGATE_RESTART() ESP.restart()
|
||||
#endif
|
||||
#include "configuration.h"
|
||||
#include "board_pinout.h"
|
||||
#include "display.h"
|
||||
@@ -30,7 +40,7 @@ bool Configuration::writeFile() {
|
||||
Serial.println("Saving configuration...");
|
||||
|
||||
JsonDocument data;
|
||||
File configFile = SPIFFS.open("/igate_conf.json", "w");
|
||||
File configFile = IGATE_FS.open("/igate_conf.json", "w");
|
||||
|
||||
if (!configFile) {
|
||||
Serial.println("Error: Could not open config file for writing");
|
||||
@@ -63,8 +73,10 @@ bool Configuration::writeFile() {
|
||||
data["aprs_is"]["filter"] = aprs_is.filter;
|
||||
data["aprs_is"]["messagesToRF"] = aprs_is.messagesToRF;
|
||||
data["aprs_is"]["objectsToRF"] = aprs_is.objectsToRF;
|
||||
data["aprs_is"]["is2Metadata"] = aprs_is.is2Metadata;
|
||||
|
||||
data["beacon"]["comment"] = beacon.comment;
|
||||
data["beacon"]["rfCommentEveryXBeacons"] = beacon.rfCommentEveryXBeacons;
|
||||
data["beacon"]["interval"] = beacon.interval;
|
||||
data["beacon"]["latitude"] = beacon.latitude;
|
||||
data["beacon"]["longitude"] = beacon.longitude;
|
||||
@@ -180,6 +192,16 @@ bool Configuration::writeFile() {
|
||||
data["ntp"]["server"] = ntp.server;
|
||||
data["ntp"]["gmtCorrection"] = ntp.gmtCorrection;
|
||||
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
// Wired IP settings: only the RP2350 + W5500 build has an Ethernet stack
|
||||
// to configure (the web UI shows its "IP Config" block when this exists).
|
||||
data["network"]["dhcp"] = network.dhcp;
|
||||
data["network"]["ip"] = network.ip;
|
||||
data["network"]["gateway"] = network.gateway;
|
||||
data["network"]["subnet"] = network.subnet;
|
||||
data["network"]["dns"] = network.dns;
|
||||
#endif
|
||||
|
||||
data["other"]["rebootMode"] = rebootMode;
|
||||
data["other"]["rebootModeTime"] = rebootModeTime;
|
||||
|
||||
@@ -197,7 +219,7 @@ bool Configuration::writeFile() {
|
||||
|
||||
bool Configuration::readFile() {
|
||||
Serial.println("Reading config..");
|
||||
File configFile = SPIFFS.open("/igate_conf.json", "r");
|
||||
File configFile = IGATE_FS.open("/igate_conf.json", "r");
|
||||
|
||||
if (configFile) {
|
||||
bool needsRewrite = false;
|
||||
@@ -237,7 +259,8 @@ bool Configuration::readFile() {
|
||||
data["aprs_is"]["port"].isNull() ||
|
||||
data["aprs_is"]["filter"].isNull() ||
|
||||
data["aprs_is"]["messagesToRF"].isNull() ||
|
||||
data["aprs_is"]["objectsToRF"].isNull()) needsRewrite = true;
|
||||
data["aprs_is"]["objectsToRF"].isNull() ||
|
||||
data["aprs_is"]["is2Metadata"].isNull()) needsRewrite = true;
|
||||
aprs_is.active = data["aprs_is"]["active"] | false;
|
||||
aprs_is.passcode = data["aprs_is"]["passcode"] | "XYZWV";
|
||||
aprs_is.server = data["aprs_is"]["server"] | "rotate.aprs2.net";
|
||||
@@ -245,10 +268,12 @@ bool Configuration::readFile() {
|
||||
aprs_is.filter = data["aprs_is"]["filter"] | "m/10";
|
||||
aprs_is.messagesToRF = data["aprs_is"]["messagesToRF"] | false;
|
||||
aprs_is.objectsToRF = data["aprs_is"]["objectsToRF"] | false;
|
||||
aprs_is.is2Metadata = data["aprs_is"]["is2Metadata"] | false;
|
||||
|
||||
if (data["beacon"]["latitude"].isNull() ||
|
||||
data["beacon"]["longitude"].isNull() ||
|
||||
data["beacon"]["comment"].isNull() ||
|
||||
data["beacon"]["rfCommentEveryXBeacons"].isNull() ||
|
||||
data["beacon"]["interval"].isNull() ||
|
||||
data["beacon"]["overlay"].isNull() ||
|
||||
data["beacon"]["symbol"].isNull() ||
|
||||
@@ -263,6 +288,7 @@ bool Configuration::readFile() {
|
||||
beacon.latitude = data["beacon"]["latitude"] | 0.0;
|
||||
beacon.longitude = data["beacon"]["longitude"] | 0.0;
|
||||
beacon.comment = data["beacon"]["comment"] | "LoRa APRS";
|
||||
beacon.rfCommentEveryXBeacons = data["beacon"]["rfCommentEveryXBeacons"] | 1;
|
||||
beacon.interval = data["beacon"]["interval"] | 15;
|
||||
beacon.overlay = data["beacon"]["overlay"] | "L";
|
||||
beacon.symbol = data["beacon"]["symbol"] | "a";
|
||||
@@ -415,6 +441,15 @@ bool Configuration::readFile() {
|
||||
ntp.server = data["ntp"]["server"] | "pool.ntp.org";
|
||||
ntp.gmtCorrection = data["ntp"]["gmtCorrection"] | 0.0;
|
||||
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
if (data["network"]["dhcp"].isNull()) needsRewrite = true;
|
||||
network.dhcp = data["network"]["dhcp"] | true;
|
||||
network.ip = data["network"]["ip"] | "";
|
||||
network.gateway = data["network"]["gateway"] | "";
|
||||
network.subnet = data["network"]["subnet"] | "255.255.255.0";
|
||||
network.dns = data["network"]["dns"] | "";
|
||||
#endif
|
||||
|
||||
if (data["other"]["rebootMode"].isNull() ||
|
||||
data["other"]["rebootModeTime"].isNull()) needsRewrite = true;
|
||||
rebootMode = data["other"]["rebootMode"] | false;
|
||||
@@ -436,7 +471,7 @@ bool Configuration::readFile() {
|
||||
Serial.println("Config JSON incomplete, rewriting...");
|
||||
writeFile();
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
IGATE_RESTART();
|
||||
}
|
||||
Serial.println("Config read successfuly");
|
||||
return true;
|
||||
@@ -470,8 +505,10 @@ void Configuration::setDefaultValues() {
|
||||
aprs_is.filter = "m/10";
|
||||
aprs_is.messagesToRF = false;
|
||||
aprs_is.objectsToRF = false;
|
||||
aprs_is.is2Metadata = false;
|
||||
|
||||
beacon.comment = "LoRa APRS";
|
||||
beacon.rfCommentEveryXBeacons = 1;
|
||||
beacon.latitude = 0.0;
|
||||
beacon.longitude = 0.0;
|
||||
beacon.interval = 15;
|
||||
@@ -564,6 +601,12 @@ void Configuration::setDefaultValues() {
|
||||
ntp.server = "pool.ntp.org";
|
||||
ntp.gmtCorrection = 0.0;
|
||||
|
||||
network.dhcp = true;
|
||||
network.ip = "";
|
||||
network.gateway = "";
|
||||
network.subnet = "255.255.255.0";
|
||||
network.dns = "";
|
||||
|
||||
rebootMode = false;
|
||||
rebootModeTime = 0;
|
||||
|
||||
@@ -573,22 +616,58 @@ void Configuration::setDefaultValues() {
|
||||
}
|
||||
|
||||
void Configuration::setup() {
|
||||
if (!SPIFFS.begin(false)) {
|
||||
if (!IGATE_FS_BEGIN()) {
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
// A stale/incompatible LittleFS (e.g. this board previously ran a
|
||||
// firmware with a different filesystem_size, leaving the FS region with
|
||||
// data that mounts but can't be written) fails to mount cleanly — format
|
||||
// once and retry rather than giving up.
|
||||
Serial.println("File system mount failed — formatting...");
|
||||
LittleFS.format();
|
||||
if (!IGATE_FS_BEGIN()) {
|
||||
Serial.println("File system unusable after format");
|
||||
return;
|
||||
}
|
||||
Serial.println("File system formatted and mounted");
|
||||
#else
|
||||
Serial.println("SPIFFS Mount Failed, formatting...");
|
||||
|
||||
if (!SPIFFS.begin(true)) {
|
||||
Serial.println("SPIFFS Format Failed");
|
||||
return;
|
||||
}
|
||||
Serial.println("SPIFFS Ready");
|
||||
#endif
|
||||
} else {
|
||||
Serial.println("File system mounted");
|
||||
}
|
||||
Serial.println("SPIFFS Ready");
|
||||
|
||||
if (!SPIFFS.exists("/igate_conf.json")) {
|
||||
bool exists = IGATE_FS.exists("/igate_conf.json");
|
||||
if (!exists) {
|
||||
Serial.println("Config not found, creating default...");
|
||||
setDefaultValues();
|
||||
writeFile();
|
||||
bool ok = writeFile();
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
if (!ok) {
|
||||
// Mounted but the write was rejected (stale FS from a different
|
||||
// layout). Format once, remount and retry so we never reboot-loop
|
||||
// here on a config that can't be created.
|
||||
Serial.println("Config write failed — formatting file system and retrying...");
|
||||
LittleFS.format();
|
||||
IGATE_FS_BEGIN();
|
||||
ok = writeFile();
|
||||
}
|
||||
if (ok) {
|
||||
delay(1000);
|
||||
IGATE_RESTART();
|
||||
} else {
|
||||
Serial.println("Config could not be persisted — continuing with defaults");
|
||||
}
|
||||
#else
|
||||
(void)ok;
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
IGATE_RESTART();
|
||||
#endif
|
||||
}
|
||||
|
||||
readFile();
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
extern Configuration Config;
|
||||
extern uint32_t lastScreenOn;
|
||||
extern APRSPacket lastAprsPacket;
|
||||
extern String iGateBeaconPacket;
|
||||
extern String firstLine;
|
||||
extern String secondLine;
|
||||
extern String thirdLine;
|
||||
|
||||
+6
-16
@@ -40,7 +40,7 @@ extern Configuration Config;
|
||||
extern HardwareSerial gpsSerial;
|
||||
extern TinyGPSPlus gps;
|
||||
extern bool stationCallsignIsValid;
|
||||
String distance, iGateBeaconPacket, iGateLoRaBeaconPacket;
|
||||
String distance, iGateAPRSISBeaconPacket, iGateLoRaBeaconPacket;
|
||||
|
||||
|
||||
namespace GPS_Utils {
|
||||
@@ -115,13 +115,8 @@ namespace GPS_Utils {
|
||||
}
|
||||
#endif
|
||||
|
||||
String getiGateLoRaBeaconPacket() {
|
||||
return iGateLoRaBeaconPacket;
|
||||
}
|
||||
|
||||
void generateBeacons() {
|
||||
String beaconPacket = APRSPacketLib::generateBasePacket(Config.callsign, "APLRG1", Config.beacon.path);
|
||||
String encodedGPS = APRSPacketLib::encodeGPSIntoBase91(Config.beacon.latitude, Config.beacon.longitude, 0, 0, Config.beacon.symbol, false, 0, true, Config.beacon.ambiguityLevel);
|
||||
String beaconCallsign = Config.callsign;
|
||||
|
||||
if (Config.callsign.indexOf("NOCALL-10") != 0) {
|
||||
if (!stationCallsignIsValid) {
|
||||
@@ -133,7 +128,7 @@ namespace GPS_Utils {
|
||||
Config.digi.mode = 0;
|
||||
Config.digi.backupDigiMode = false;
|
||||
} else if (stationCallsignIsValid && Config.tacticalCallsign != "") {
|
||||
beaconPacket = APRSPacketLib::generateBasePacket(Config.tacticalCallsign, "APLRG1", Config.beacon.path);
|
||||
beaconCallsign = Config.tacticalCallsign;
|
||||
Config.aprs_is.active = false;
|
||||
Config.beacon.sendViaAPRSIS = false;
|
||||
Config.digi.backupDigiMode = false;
|
||||
@@ -143,15 +138,10 @@ namespace GPS_Utils {
|
||||
Config.beacon.sendViaRF = false;
|
||||
}
|
||||
|
||||
iGateBeaconPacket = beaconPacket;
|
||||
iGateBeaconPacket += ",qAC:=";
|
||||
iGateBeaconPacket += Config.beacon.overlay;
|
||||
iGateBeaconPacket += encodedGPS;
|
||||
String encodedGPS = APRSPacketLib::encodeGPSIntoBase91(Config.beacon.latitude, Config.beacon.longitude, 0, 0, Config.beacon.symbol, false, 0, true, Config.beacon.ambiguityLevel);
|
||||
|
||||
iGateLoRaBeaconPacket = beaconPacket;
|
||||
iGateLoRaBeaconPacket += ":=";
|
||||
iGateLoRaBeaconPacket += Config.beacon.overlay;
|
||||
iGateLoRaBeaconPacket += encodedGPS;
|
||||
iGateLoRaBeaconPacket = APRSPacketLib::generateBase91GPSBeaconPacket(beaconCallsign, "APLRG1", Config.beacon.path, Config.beacon.overlay, encodedGPS);
|
||||
iGateAPRSISBeaconPacket = APRSPacketLib::generateAPRSISPacket(iGateLoRaBeaconPacket);
|
||||
}
|
||||
|
||||
double calculateDistanceTo(double latitude, double longitude) {
|
||||
|
||||
+55
-22
@@ -28,6 +28,7 @@
|
||||
#include "ntp_utils.h"
|
||||
#include "display.h"
|
||||
#include "utils.h"
|
||||
#include "thermal_utils.h"
|
||||
|
||||
|
||||
extern Configuration Config;
|
||||
@@ -69,6 +70,18 @@ int rssi, freqError;
|
||||
float snr;
|
||||
APRSPacket lastAprsPacket;
|
||||
|
||||
#if defined(HAS_SX1278) || defined(HAS_SX1276)
|
||||
#define CHIP_MIN_POWER 2 // PA_BOOST (below 2 RadioLib switches to RFO, not wired on most modules)
|
||||
#define CHIP_MAX_POWER 20
|
||||
#else // SX1262 / SX1268 / LLCC68
|
||||
#define CHIP_MIN_POWER -9
|
||||
#define CHIP_MAX_POWER 22
|
||||
#endif
|
||||
|
||||
#ifndef RADIO_MAX_POWER // optional per board in board_pinout.h (e.g. 1W PA modules)
|
||||
#define RADIO_MAX_POWER CHIP_MAX_POWER
|
||||
#endif
|
||||
|
||||
|
||||
namespace LoRa_Utils {
|
||||
|
||||
@@ -85,10 +98,21 @@ namespace LoRa_Utils {
|
||||
operationDone = true;
|
||||
}
|
||||
|
||||
int validPower(int requested) {
|
||||
const int maxPower = (RADIO_MAX_POWER < CHIP_MAX_POWER) ? RADIO_MAX_POWER : CHIP_MAX_POWER;
|
||||
int power = constrain(requested, CHIP_MIN_POWER, maxPower);
|
||||
#if defined(HAS_SX1278) || defined(HAS_SX1276)
|
||||
if (power > 17 && power < 20) power = 17; // SX127x PA_BOOST: only 2-17 or 20
|
||||
#endif
|
||||
return power;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
#ifdef RADIO_VCC_PIN // LoRa module power switch (QRP Labs LightGateway, T-Beam 1W)
|
||||
pinMode(RADIO_VCC_PIN, OUTPUT);
|
||||
digitalWrite(RADIO_VCC_PIN, HIGH);
|
||||
#endif
|
||||
#if defined (LIGHTGATEWAY_1_0) || defined(LIGHTGATEWAY_PLUS_1_0)
|
||||
pinMode(RADIO_VCC_PIN,OUTPUT);
|
||||
digitalWrite(RADIO_VCC_PIN,HIGH);
|
||||
loraSPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN, RADIO_CS_PIN);
|
||||
#else
|
||||
SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN);
|
||||
@@ -103,6 +127,8 @@ namespace LoRa_Utils {
|
||||
#endif
|
||||
#if (defined(RADIO_RXEN) && defined(RADIO_TXEN)) // before begin() so RF switch is driven from start (Ebyte E22/E32 1W, QRP Labs LightGateway)
|
||||
radio.setRfSwitchPins(RADIO_RXEN, RADIO_TXEN);
|
||||
#elif defined(RADIO_RXEN) // T-Beam 1W: RXEN = LNA only, DIO2 drives the PA
|
||||
radio.setRfSwitchPins(RADIO_RXEN, RADIOLIB_NC);
|
||||
#endif
|
||||
int state = radio.begin(freq);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
@@ -131,21 +157,17 @@ namespace LoRa_Utils {
|
||||
radio.setBandwidth(signalBandwidth);
|
||||
radio.setCRC(true);
|
||||
|
||||
/*#ifdef SX126X_DIO2_AS_RF_SWITCH
|
||||
radio.setRfSwitchPins(RADIO_RXEN, RADIOLIB_NC);
|
||||
radio.setDio2AsRfSwitch(true);
|
||||
#endif*/
|
||||
|
||||
#ifdef HAS_1W_LORA // Ebyte E22 400M30S (SX1268) / 900M30S (SX1262) / Ebyte E220 400M30S (LLCC68)
|
||||
state = radio.setOutputPower(Config.loramodule.power); // max value 20dB for 1W modules as they have Low Noise Amp
|
||||
radio.setCurrentLimit(140); // to be validated (100 , 120, 140)?
|
||||
#endif
|
||||
int power = validPower(Config.loramodule.power);
|
||||
if (power != Config.loramodule.power) {
|
||||
Utils::println("LoRa power adjusted: " + String(Config.loramodule.power) + " -> " + String(power));
|
||||
}
|
||||
state = radio.setOutputPower(power);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
Utils::println("LoRa setOutputPower failed! State: " + String(state)); // log and keep going
|
||||
}
|
||||
#if defined(HAS_SX1278) || defined(HAS_SX1276)
|
||||
state = radio.setOutputPower(Config.loramodule.power); // max value 20dB for 400M30S as it has Low Noise Amp
|
||||
radio.setCurrentLimit(100); // to be validated (80 , 100)?
|
||||
#endif
|
||||
#if (defined(HAS_SX1268) || defined(HAS_SX1262)) && !defined(HAS_1W_LORA)
|
||||
state = radio.setOutputPower(Config.loramodule.power + 2); // values available: 10, 17, 22 --> if 20 in tracker_conf.json it will be updated to 22.
|
||||
radio.setCurrentLimit(120); // OCP ceiling for SX127x: ~120mA needed at +20dBm (not a fixed consumption)
|
||||
#else // SX1262 / SX1268 / LLCC68 (also 1W Ebyte E22 / E220 modules)
|
||||
radio.setCurrentLimit(140);
|
||||
#endif
|
||||
|
||||
@@ -156,16 +178,15 @@ namespace LoRa_Utils {
|
||||
#if defined(HAS_TCXO) && !defined(HAS_1W_LORA)
|
||||
radio.setDio2AsRfSwitch();
|
||||
#endif
|
||||
#if defined(TTGO_T_BEAM_1W)
|
||||
radio.setDio2AsRfSwitch(true); // DIO2 drives the 1W PA
|
||||
radio.setPaRampTime(RADIOLIB_SX126X_PA_RAMP_800U); // PA needs >800us to settle (default 200us)
|
||||
#endif
|
||||
#ifdef HAS_TCXO
|
||||
radio.setTCXO(1.8);
|
||||
#endif
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
Utils::println("init : LoRa Module ... done!");
|
||||
} else {
|
||||
Utils::println("Starting LoRa failed! State: " + String(state));
|
||||
while (true);
|
||||
}
|
||||
Utils::println("init : LoRa Module ... done!");
|
||||
}
|
||||
|
||||
void changeFreqTx() {
|
||||
@@ -222,6 +243,12 @@ namespace LoRa_Utils {
|
||||
|
||||
void sendNewPacket(const String& newPacket) {
|
||||
if (!Config.loramodule.txActive) return;
|
||||
#ifdef FAN_CTRL_PIN
|
||||
if (THERMAL_Utils::isTxBlocked()) {
|
||||
Utils::println("Thermal: Tx blocked (over-temperature), packet dropped: " + newPacket);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (Config.loramodule.txFreq != Config.loramodule.rxFreq) {
|
||||
if (!packetIsBeacon || (packetIsBeacon && Config.beacon.beaconFreq == 1)) {
|
||||
@@ -245,7 +272,13 @@ namespace LoRa_Utils {
|
||||
}
|
||||
|
||||
if (!cadDropped) {
|
||||
#ifdef FAN_CTRL_PIN
|
||||
THERMAL_Utils::onTxStart();
|
||||
#endif
|
||||
int state = radio.transmit("\x3c\xff\x01" + newPacket);
|
||||
#ifdef FAN_CTRL_PIN
|
||||
THERMAL_Utils::onTxEnd();
|
||||
#endif
|
||||
transmitFlag = true;
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
if (Config.syslog.active && networkManager->isConnected()) {
|
||||
|
||||
+9
-1
@@ -18,7 +18,11 @@
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include "map_utils.h"
|
||||
#include "ntp_utils.h"
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
#include "rp2350/ntp_rp2350.h" // RP2350 port: lean SNTP client over W5500
|
||||
#else
|
||||
#include "ntp_utils.h"
|
||||
#endif
|
||||
|
||||
#define MAX_MAP_STATIONS 50
|
||||
#define STATION_TTL_MS 3600000UL // 1 hora (en milisegundos)
|
||||
@@ -30,7 +34,11 @@ std::vector<MapStation> mapStations;
|
||||
namespace MAP_Utils {
|
||||
|
||||
void writeFormatedTime(char* dst, size_t size) { // gets NTP time ("HH:MM:SS") and writes it to dst if valid
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
String t = Ntp::synced() ? Ntp::hms(Ntp::nowEpoch()) : String("");
|
||||
#else
|
||||
String t = NTP_Utils::getFormatedTime();
|
||||
#endif
|
||||
if (t.length() == 8 && t.charAt(2) == ':') {
|
||||
t.toCharArray(dst, size);
|
||||
} else {
|
||||
|
||||
+7
-8
@@ -66,7 +66,7 @@ namespace POWER_Utils {
|
||||
}
|
||||
|
||||
void vext_ctrl_OFF() {
|
||||
digitalWrite(VEXT_CTRL_PIN, Config.digi.ecoMode == 1 ? VEXT_CTRL_ON_STATE : !VEXT_CTRL_ON_STATE);
|
||||
digitalWrite(VEXT_CTRL_PIN, !VEXT_CTRL_ON_STATE); // always off, regardless of ecoMode
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -111,9 +111,7 @@ namespace POWER_Utils {
|
||||
PMU.enableALDO3();
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HELTEC_WIRELESS_TRACKER
|
||||
adc_ctrl_ON();
|
||||
#endif
|
||||
// HELTEC_WIRELESS_TRACKER: GPS shares Vext (GPIO3) with the TFT, so it follows the display power (not controlled here)
|
||||
//gpsIsActive = true;
|
||||
}
|
||||
|
||||
@@ -129,9 +127,7 @@ namespace POWER_Utils {
|
||||
PMU.disableALDO3();
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HELTEC_WIRELESS_TRACKER
|
||||
adc_ctrl_OFF();
|
||||
#endif
|
||||
// HELTEC_WIRELESS_TRACKER: GPS shares Vext with the TFT, turned off with it (see activateGPS)
|
||||
//gpsIsActive = false;
|
||||
}
|
||||
|
||||
@@ -199,7 +195,10 @@ namespace POWER_Utils {
|
||||
PMU.setDC1Voltage(3300);
|
||||
PMU.enableDC1();
|
||||
#ifdef TTGO_T_Beam_S3_SUPREME_V3
|
||||
PMU.setALDO1Voltage(3300);
|
||||
PMU.setALDO1Voltage(3300); // BME280, QMC6310, QMI8658, OLED
|
||||
PMU.enableALDO1();
|
||||
PMU.setALDO2Voltage(3300); // sensors/OLED I2C + RTC PCF8563 (must stay on)
|
||||
PMU.enableALDO2();
|
||||
#endif
|
||||
PMU.setButtonBatteryChargeVoltage(3300);
|
||||
PMU.enableButtonBatteryCharge();
|
||||
|
||||
+16
-26
@@ -16,6 +16,7 @@
|
||||
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <APRSPacketLib.h>
|
||||
#include "configuration.h"
|
||||
#include "battery_utils.h"
|
||||
#include "station_utils.h"
|
||||
@@ -36,11 +37,17 @@ extern String versionNumber;
|
||||
|
||||
namespace QUERY_Utils {
|
||||
|
||||
bool isQuery(const String& message) { // "?..." queries, plus "HELP" (any case) without the "?"
|
||||
String queryQuestion = message;
|
||||
queryQuestion.toUpperCase();
|
||||
return queryQuestion.startsWith("?") || queryQuestion == "HELP";
|
||||
}
|
||||
|
||||
String process(const String& query, const String& station, bool queryFromAPRSIS, bool thirdParty) {
|
||||
String answer;
|
||||
String queryQuestion = query;
|
||||
queryQuestion.toUpperCase();
|
||||
if (queryQuestion == "?APRS?" || queryQuestion == "H" || queryQuestion == "HELP" || queryQuestion=="?") {
|
||||
if (queryQuestion == "?APRS?" || queryQuestion == "?" || queryQuestion == "HELP") {
|
||||
answer.concat("?APRSV ?APRSP ?APRSL ?APRSSR ?EM=? ?TX=? "); // ?APRSH ?WHERE callsign
|
||||
} else if (queryQuestion == "?APRSV") {
|
||||
answer.concat("CA2RXU_LoRa_iGate v");
|
||||
@@ -139,32 +146,15 @@ namespace QUERY_Utils {
|
||||
|
||||
if (answer == "") return "";
|
||||
|
||||
String queryAnswer = (Config.tacticalCallsign == "" ? Config.callsign : Config.tacticalCallsign);
|
||||
queryAnswer += ">APLRG1";
|
||||
if (queryFromAPRSIS) {
|
||||
queryAnswer += ",TCPIP,qAC";
|
||||
} else {
|
||||
if (!thirdParty) queryAnswer += ",RFONLY";
|
||||
if (Config.beacon.path != "") {
|
||||
queryAnswer += ",";
|
||||
queryAnswer += Config.beacon.path;
|
||||
}
|
||||
}
|
||||
queryAnswer += "::";
|
||||
answer += " *";
|
||||
answer += char(random(97, 123));
|
||||
answer += char(random(97, 123));
|
||||
answer += "*";
|
||||
|
||||
String processedStation = station;
|
||||
for (int i = station.length(); i < 9; i++) {
|
||||
processedStation += ' ';
|
||||
}
|
||||
queryAnswer += processedStation;
|
||||
queryAnswer += ":";
|
||||
queryAnswer += answer;
|
||||
|
||||
queryAnswer += " *";
|
||||
queryAnswer += char(random(97, 123));
|
||||
queryAnswer += char(random(97, 123));
|
||||
queryAnswer += "*";
|
||||
return queryAnswer;
|
||||
String queryCallsign = (Config.tacticalCallsign == "") ? Config.callsign : Config.tacticalCallsign;
|
||||
String queryPath = queryFromAPRSIS ? "" : (thirdParty ? Config.beacon.path : "RFONLY," + Config.beacon.path);
|
||||
String queryAnswer = APRSPacketLib::generateMessagePacket(queryCallsign, "APLRG1", queryPath, station, answer);
|
||||
return queryFromAPRSIS ? APRSPacketLib::generateAPRSISPacket(queryAnswer) : queryAnswer;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
#include "aprsis_rp2350.h"
|
||||
#include <Ethernet.h>
|
||||
#include <APRSPacketLib.h>
|
||||
#include "configuration.h"
|
||||
#include "station_rp2350.h"
|
||||
#include "syslog_rp2350.h"
|
||||
|
||||
extern Configuration Config;
|
||||
// Inbox store (eth_web.cpp) — poll() runs in netTask, same task that owns it.
|
||||
extern void ethWebAddMessage(const String &from, const String &text, const String &via);
|
||||
|
||||
static EthernetClient aprsClient;
|
||||
static const char *IGATE_VERS = "RP2350iGate 0.1";
|
||||
static uint32_t lastLineMs = 0; // last line of any kind from the server ("#" keepalives too)
|
||||
static uint32_t connectedAt = 0; // when the current connection was opened
|
||||
|
||||
// APRS-IS servers send a "#" keepalive about every 20 s. A connection that stays
|
||||
// quiet this long is dead even if the socket still reports it as connected.
|
||||
static const uint32_t SILENT_DROP_MS = 60000;
|
||||
|
||||
// Parse one APRS-IS line; if it's a message addressed to our callsign, record it
|
||||
// in the inbox and ack it (if it carries a {msgid}).
|
||||
static void processAprsisLine(const String &line) {
|
||||
// Login answer: "# logresp CALL verified, server T2XXX" / "... unverified, ...".
|
||||
// Like the ESP32 (APRS_IS_Utils::processAPRSISPacket), a rejected passcode stops APRS-IS
|
||||
// (until the next boot or config save) instead of reconnecting every 10 s and uploading
|
||||
// packets the server ignores. Only an explicit "unverified" blocks: if a server never
|
||||
// answers, behaviour stays as before. "unverified" contains "verified", so test it first.
|
||||
if (line.startsWith("# logresp") && line.indexOf(Config.callsign) >= 0 && line.indexOf("unverified") >= 0) {
|
||||
Serial.println("\n****APRS PASSCODE NOT VALID****\n");
|
||||
Syslog::logTx("*** APRS-IS passcode NOT valid -> APRS-IS stopped ***");
|
||||
aprsClient.stop();
|
||||
Config.aprs_is.active = false; // in memory only: the saved config keeps APRS-IS enabled
|
||||
return;
|
||||
}
|
||||
if (line.length() == 0 || line[0] == '#') return; // server comment / keepalive
|
||||
int gt = line.indexOf('>');
|
||||
int dc = line.indexOf("::");
|
||||
if (gt <= 0 || dc <= gt) return; // not a message packet
|
||||
String from = line.substring(0, gt);
|
||||
if (from == Config.callsign) return; // ignore our own echoes
|
||||
String rest = line.substring(dc + 2); // "ADDRESSEE :text{id}"
|
||||
int fc = rest.indexOf(':');
|
||||
if (fc < 0) return;
|
||||
String addressee = rest.substring(0, fc);
|
||||
addressee.trim();
|
||||
if (addressee != Config.callsign) return; // not for us
|
||||
|
||||
String text = rest.substring(fc + 1);
|
||||
int brace = text.indexOf('{');
|
||||
String msg = (brace > 0) ? text.substring(0, brace) : text;
|
||||
ethWebAddMessage(from, msg, "IS");
|
||||
|
||||
// ack id = text after the LAST '{'; empty = no ack requested (generateAckMessage)
|
||||
String id = (brace > 0) ? text.substring(text.lastIndexOf('{') + 1) : "";
|
||||
id.trim();
|
||||
if (id.length() && aprsClient.connected()) { // ack it over APRS-IS
|
||||
String ack = Config.callsign;
|
||||
ack += ">APLRG1,TCPIP*::";
|
||||
String padded = from;
|
||||
for (int i = from.length(); i < 9; i++) padded += ' ';
|
||||
ack += padded;
|
||||
ack += ":ack";
|
||||
ack += id;
|
||||
aprsClient.print(ack + "\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
namespace AprsIs {
|
||||
|
||||
bool connected() { return aprsClient.connected(); }
|
||||
|
||||
bool connect() {
|
||||
if (aprsClient.connected()) return true;
|
||||
aprsClient.stop();
|
||||
Serial.printf("[aprsis] connecting %s:%d ...\n",
|
||||
Config.aprs_is.server.c_str(), Config.aprs_is.port);
|
||||
if (!aprsClient.connect(Config.aprs_is.server.c_str(), Config.aprs_is.port)) {
|
||||
Serial.println("[aprsis] connect FAILED");
|
||||
return false;
|
||||
}
|
||||
// login line: "user CALL pass PASSCODE vers SW VER [filter F]"
|
||||
String login = "user ";
|
||||
login += Config.callsign;
|
||||
login += " pass ";
|
||||
login += Config.aprs_is.passcode;
|
||||
login += " vers ";
|
||||
login += IGATE_VERS;
|
||||
if (Config.aprs_is.filter.length()) {
|
||||
login += " filter ";
|
||||
login += Config.aprs_is.filter;
|
||||
}
|
||||
aprsClient.print(login + "\r\n");
|
||||
connectedAt = millis();
|
||||
Serial.println("[aprsis] connected, logged in as " + Config.callsign);
|
||||
return true;
|
||||
}
|
||||
|
||||
void poll() {
|
||||
// read line by line; record messages addressed to us, drop the rest
|
||||
static String lineBuf;
|
||||
while (aprsClient.available()) {
|
||||
char ch = (char)aprsClient.read();
|
||||
if (ch == '\n') { lastLineMs = millis(); processAprsisLine(lineBuf); lineBuf = ""; }
|
||||
else if (ch != '\r') { if (lineBuf.length() < 512) lineBuf += ch; }
|
||||
}
|
||||
// a server that went quiet leaves the socket "connected" forever: drop it so
|
||||
// netTask reconnects
|
||||
if (aprsClient.connected() && millis() - lastLineMs > SILENT_DROP_MS &&
|
||||
millis() - connectedAt > SILENT_DROP_MS) {
|
||||
Serial.println("[aprsis] server silent, reconnecting");
|
||||
aprsClient.stop();
|
||||
}
|
||||
}
|
||||
|
||||
bool silentFor(uint32_t ms) { return millis() - lastLineMs > ms; }
|
||||
|
||||
void send(const String &line) {
|
||||
if (line.length() == 0) return; // never send an empty line to APRS-IS
|
||||
if (aprsClient.connected()) aprsClient.print(line + "\r\n");
|
||||
}
|
||||
|
||||
// Gate rules of APRS_IS_Utils::processLoRaPacket. This build never gates APRS-IS
|
||||
// back to RF (no messagesToRF/objectsToRF), so it is a receive-only iGate and
|
||||
// uses qAO, like the ESP32 with messagesToRF off (buildPacketToUpload).
|
||||
// IS2PLAIN metadata line sent right before the gated packet (same as buildIS2Meta()
|
||||
// in the ESP32 aprs_is_utils.cpp). rx_modem=2 is LoRa; the bit rate is derived from
|
||||
// the RX SF/BW/CR, which only change with a config save (= reboot), so it is cached.
|
||||
static String buildIS2Meta(int rssi, float snr) {
|
||||
static String fixedTail;
|
||||
if (fixedTail == "") {
|
||||
// LoRa bit rate = SF * (BW / 2^SF) * 4/CR (CR = denominator: 5..8)
|
||||
uint32_t bitrate = (uint32_t)(Config.loramodule.rxSpreadingFactor
|
||||
* ((float)Config.loramodule.rxSignalBandwidth / (1 << Config.loramodule.rxSpreadingFactor))
|
||||
* (4.0 / Config.loramodule.rxCodingRate4));
|
||||
fixedTail = " rx_modem=2 rx_bitrate=" + String(bitrate) + " rx_frequency=" + String(Config.loramodule.rxFreq);
|
||||
}
|
||||
return "#is2-meta rx_rssi_dbm=" + String(rssi) + " rx_snr_db=" + String(snr, 1) + fixedTail;
|
||||
}
|
||||
|
||||
void forward(const String &packet, int rssi, float snr) {
|
||||
if (!aprsClient.connected()) return;
|
||||
if (packet.length() < 5) return;
|
||||
String body = packet.substring(3); // skip the 3-byte LoRa-APRS header
|
||||
int gt = body.indexOf('>');
|
||||
int colon = body.indexOf(':');
|
||||
if (gt <= 0 || colon <= gt) return; // not a valid "SENDER>PATH:payload"
|
||||
if (colon + 1 < (int)body.length() && body[colon + 1] == '}') return; // third-party packet
|
||||
|
||||
String sender = body.substring(0, gt);
|
||||
if (sender == Config.callsign || !Station::callsignIsValid(sender)) return;
|
||||
|
||||
// NOGATE / RFONLY / TCPIP count only in the path, not in the payload
|
||||
String hdr = body.substring(gt + 1, colon); // "TOCALL,PATH"
|
||||
int comma = hdr.indexOf(',');
|
||||
String path = (comma > 2) ? hdr.substring(comma + 1) : "";
|
||||
if (path.indexOf("NOGATE") >= 0 || path.indexOf("RFONLY") >= 0 || path.indexOf("TCPIP") >= 0) return;
|
||||
|
||||
// SENDER>TOCALL,PATH,qAO,IGATECALL:payload
|
||||
String line = body.substring(0, colon);
|
||||
line += ",qAO,";
|
||||
line += Config.callsign;
|
||||
line += APRSPacketLib::checkForStartingBytes(body.substring(colon));
|
||||
if (Config.aprs_is.is2Metadata) aprsClient.print(buildIS2Meta(rssi, snr) + "\r\n" + line + "\r\n"); // meta line + packet in one write
|
||||
else aprsClient.print(line + "\r\n");
|
||||
Serial.println("[aprsis] up: " + line);
|
||||
}
|
||||
|
||||
} // namespace AprsIs
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Lean APRS-IS uplink for the RP2350 iGate core path (RX LoRa -> APRS-IS),
|
||||
// over the W5500 (EthernetClient). The full feature set (queries, digi, TNC,
|
||||
// station tracking) of the original aprs_is_utils.cpp is deferred. All calls
|
||||
// touch the W5500/SPI0, so run them from the same task that owns Ethernet.
|
||||
namespace AprsIs {
|
||||
bool connect(); // TCP connect + APRS-IS login
|
||||
bool connected();
|
||||
void poll(); // drain incoming server lines (keepalive); drops a silent connection
|
||||
bool silentFor(uint32_t ms); // no line from the server for `ms` (feeds the backup digi)
|
||||
void send(const String &line); // send a raw APRS-IS line (e.g. beacon)
|
||||
void forward(const String &loraPacket, int rssi, float snr); // RX LoRa packet -> APRS-IS (qAO: receive-only iGate); rssi/snr feed the IS2 meta line
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* RP2350 supply-voltage monitor. Reads VSYS through the board's 3:1 divider on
|
||||
* GP29/ADC3 (Pico2 / W5500-EVB-Pico2): the pin sees VSYS/3, ADC full scale is
|
||||
* the 3.3 V reference. analogRead is cheap and not tied to any bus, so it is safe
|
||||
* to call from whichever task builds the beacon/telemetry.
|
||||
*/
|
||||
#include "battery_rp2350.h"
|
||||
#include "board_pinout.h" // VSYS_CAL per board
|
||||
|
||||
#ifndef PIN_VSYS_ADC
|
||||
#define PIN_VSYS_ADC A3 // GP29 = ADC3 = VSYS/3 on Pico2 / W5500-EVB-Pico2
|
||||
#endif
|
||||
|
||||
// Per-board calibration of the VSYS reading. This code was first tuned on the
|
||||
// WIZnet W5500-EVB-Pico2, whose VSYS sense reads accurately (factor 1.0). On a
|
||||
// genuine Raspberry Pi Pico 2 the on-board 200k/100k divider on GP29 reads
|
||||
// consistently low (~0.59x) under the RP2350 ADC, so the e22-2 variant sets
|
||||
// VSYS_CAL to bring the reported value back to the measured ~5 V supply.
|
||||
#ifndef VSYS_CAL
|
||||
#define VSYS_CAL 1.0f
|
||||
#endif
|
||||
|
||||
namespace Battery {
|
||||
|
||||
void setup() {
|
||||
analogReadResolution(12);
|
||||
}
|
||||
|
||||
float vsys() {
|
||||
// The Raspberry Pi Pico 2's on-board VSYS/3 divider (200k/100k) is high
|
||||
// impedance, so the first ADC sample after the mux selects this channel reads
|
||||
// low (the sample-and-hold cap shares charge with the previous channel/state).
|
||||
// The WIZnet W5500-EVB-Pico2 this was first ported on happened to read fine
|
||||
// with a single shot; a genuine Pico 2 does not. Discard a couple of priming
|
||||
// reads to let the S&H settle on the high-Z source, then average.
|
||||
(void)analogRead(PIN_VSYS_ADC);
|
||||
(void)analogRead(PIN_VSYS_ADC);
|
||||
delayMicroseconds(50);
|
||||
uint32_t acc = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
acc += analogRead(PIN_VSYS_ADC); // 0..4095 over 0..3.3 V
|
||||
delayMicroseconds(20);
|
||||
}
|
||||
return (float)acc / 16.0f * 3.3f / 4096.0f * 3.0f * VSYS_CAL; // undo /3 divider + per-board cal
|
||||
}
|
||||
|
||||
} // namespace Battery
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Supply-voltage monitor for the RP2350 iGate. Reads VSYS via the on-board 3:1
|
||||
// divider on GP29/ADC3 (Pico2 / WIZnet W5500-EVB-Pico2). Reported in the beacon
|
||||
// (Batt=) and/or as APRS telemetry, per Config.battery. No sleep handling — this
|
||||
// is a mains/Ethernet iGate.
|
||||
namespace Battery {
|
||||
void setup(); // ADC resolution
|
||||
float vsys(); // supply voltage in volts (0 if unavailable)
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#include "beacon_rp2350.h"
|
||||
#include <APRSPacketLib.h>
|
||||
#include "configuration.h"
|
||||
#include "wx_rp2350.h"
|
||||
#include "battery_rp2350.h"
|
||||
#include "gps_rp2350.h"
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
namespace Beacon {
|
||||
|
||||
// " Batt=X.XXV" appended to the comment when supply-voltage reporting goes in the
|
||||
// beacon (not as telemetry). Empty otherwise.
|
||||
static String battField() {
|
||||
if (Config.battery.sendInternalVoltage && !Config.battery.sendVoltageAsTelemetry) {
|
||||
char b[12];
|
||||
snprintf(b, sizeof(b), " Batt=%.2fV", (double)Battery::vsys());
|
||||
return String(b);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Base91-compressed position payload: =<overlay><base91> (mirrors gps_utils.cpp).
|
||||
// Uses the live GPS fix when GPS is active and locked, else the fixed config
|
||||
// coordinates (a stationary iGate keeps its saved position until a fix arrives).
|
||||
static String encodedPosition() {
|
||||
double lat = Config.beacon.latitude;
|
||||
double lng = Config.beacon.longitude;
|
||||
#ifdef HAS_GPS
|
||||
if (Config.beacon.gpsActive && Gps::hasFix()) {
|
||||
lat = Gps::lat();
|
||||
lng = Gps::lng();
|
||||
}
|
||||
#endif
|
||||
return APRSPacketLib::encodeGPSIntoBase91(lat, lng, 0, 0, Config.beacon.symbol,
|
||||
false, 0, true, Config.beacon.ambiguityLevel);
|
||||
}
|
||||
|
||||
// Weather field appended after the position when a sensor is active (matches
|
||||
// utils.cpp: position + wxData + comment).
|
||||
static String wxField() {
|
||||
if (!Config.wxsensor.active) return "";
|
||||
String wx = Wx::readAprs();
|
||||
return wx.length() ? wx : ".../...g...t...";
|
||||
}
|
||||
|
||||
String buildAprsisLine() {
|
||||
// Own packet uploaded to APRS-IS: TCPIP* only, no RF path and no q construct
|
||||
// (the server appends qAC itself) -- upstream's generateAPRSISPacket().
|
||||
String line = Config.callsign;
|
||||
line += ">APLRG1,TCPIP*:="; // position w/ messaging
|
||||
line += Config.beacon.overlay;
|
||||
line += encodedPosition();
|
||||
line += wxField();
|
||||
line += Config.beacon.comment;
|
||||
line += battField();
|
||||
return line;
|
||||
}
|
||||
|
||||
// RF beacons built so far. buildRfLine() is called once per RF beacon queued
|
||||
// (loraTask), so counting here matches upstream's rfBeaconCounter in utils.cpp.
|
||||
static uint32_t rfBeaconCounter = 0;
|
||||
|
||||
String buildRfLine() {
|
||||
// Built from loraTask — must NOT touch the BMP280 (Wire/I2C0 is owned by
|
||||
// netTask via buildAprsisLine), so no WX field here. Position + comment only.
|
||||
String line = APRSPacketLib::generateBasePacket(Config.callsign, "APLRG1", Config.beacon.path);
|
||||
line += ":=";
|
||||
line += Config.beacon.overlay;
|
||||
line += encodedPosition();
|
||||
// RF carries the comment only every Nth beacon (APRS-IS always does).
|
||||
int commentEveryX = max(1, Config.beacon.rfCommentEveryXBeacons); // 0 or negative = every beacon
|
||||
if (rfBeaconCounter % commentEveryX == 0) line += Config.beacon.comment;
|
||||
rfBeaconCounter++;
|
||||
line += battField();
|
||||
return line;
|
||||
}
|
||||
|
||||
} // namespace Beacon
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Builds the iGate position beacon (fixed lat/lon from Config.beacon), using
|
||||
// APRSPacketLib's Base91-compressed position — same format as the ESP32 build.
|
||||
namespace Beacon {
|
||||
String buildAprsisLine(); // CALL>APLRG1,PATH,qAC:=<overlay><base91><comment>
|
||||
String buildRfLine(); // CALL>APLRG1,PATH:=<overlay><base91><comment>
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
// Compatibility shim for W5100S builds (the rp2350_igate_w5100s env).
|
||||
//
|
||||
// The RAK13800_W5100S driver ships its API in <RAK13800_W5100S.h> and provides
|
||||
// no <Ethernet.h>, whereas the W5500 (arduino-libraries/Ethernet) build does.
|
||||
// This directory is added to the include path ONLY by the W5100S env, so the
|
||||
// iGate sources' `#include <Ethernet.h>` resolves here and pulls the W5100S
|
||||
// driver — which exposes the same Ethernet/EthernetClient/EthernetServer/
|
||||
// EthernetUDP API, so no other source changes are needed.
|
||||
#include <RAK13800_W5100S.h>
|
||||
@@ -0,0 +1,252 @@
|
||||
// AUTO-ADAPTED from web_utils.cpp::handleWriteConfiguration (lines 148-293).
|
||||
// Applies a posted config form (urlencoded OR multipart/form-data — the SPA uses
|
||||
// fetch + FormData = multipart) to the global Config and persists it. Replaces
|
||||
// ESPAsyncWebServer's request->getParam/hasParam with a tiny local parser.
|
||||
// Regenerate if the original mapping changes.
|
||||
#include <Arduino.h>
|
||||
#include <vector>
|
||||
#include "configuration.h"
|
||||
#include "lora_utils.h"
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
struct FormKV { String k, v; };
|
||||
|
||||
static String urlDecode(const String &s) {
|
||||
String out; out.reserve(s.length());
|
||||
for (size_t i = 0; i < s.length(); i++) {
|
||||
char c = s[i];
|
||||
if (c == '+') out += ' ';
|
||||
else if (c == '%' && i + 2 < s.length()) {
|
||||
auto hx = [](char h) -> int {
|
||||
if (h >= '0' && h <= '9') return h - '0';
|
||||
if (h >= 'a' && h <= 'f') return h - 'a' + 10;
|
||||
if (h >= 'A' && h <= 'F') return h - 'A' + 10;
|
||||
return 0; };
|
||||
out += (char)((hx(s[i + 1]) << 4) | hx(s[i + 2])); i += 2;
|
||||
} else out += c;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static void parseUrlencoded(const String &body, std::vector<FormKV> &kv) {
|
||||
int i = 0, n = body.length();
|
||||
while (i < n) {
|
||||
int amp = body.indexOf('&', i); if (amp < 0) amp = n;
|
||||
String pair = body.substring(i, amp);
|
||||
int eq = pair.indexOf('='); FormKV e;
|
||||
if (eq < 0) { e.k = urlDecode(pair); }
|
||||
else { e.k = urlDecode(pair.substring(0, eq)); e.v = urlDecode(pair.substring(eq + 1)); }
|
||||
if (e.k.length()) kv.push_back(e);
|
||||
i = amp + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Minimal multipart/form-data parser for simple text fields (no file uploads).
|
||||
static void parseMultipart(const String &boundary, const String &body, std::vector<FormKV> &kv) {
|
||||
if (!boundary.length()) return;
|
||||
String delim = "--" + boundary;
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
int start = body.indexOf(delim, pos);
|
||||
if (start < 0) break;
|
||||
start += delim.length();
|
||||
if (body.substring(start, start + 2) == "--") break; // closing boundary
|
||||
if (body.substring(start, start + 2) == "\r\n") start += 2; // skip CRLF
|
||||
int hend = body.indexOf("\r\n\r\n", start);
|
||||
if (hend < 0) break;
|
||||
String headers = body.substring(start, hend);
|
||||
int valStart = hend + 4;
|
||||
int next = body.indexOf(delim, valStart);
|
||||
if (next < 0) next = body.length();
|
||||
int valEnd = next;
|
||||
if (valEnd >= 2 && body.substring(valEnd - 2, valEnd) == "\r\n") valEnd -= 2;
|
||||
int ni = headers.indexOf("name=\"");
|
||||
if (ni >= 0) {
|
||||
ni += 6;
|
||||
int ne = headers.indexOf('"', ni);
|
||||
if (ne > ni) { FormKV e; e.k = headers.substring(ni, ne); e.v = body.substring(valStart, valEnd); kv.push_back(e); }
|
||||
}
|
||||
pos = next;
|
||||
}
|
||||
}
|
||||
|
||||
bool applyConfigForm(const String &contentType, const String &body) {
|
||||
std::vector<FormKV> kv;
|
||||
if (contentType.indexOf("multipart/form-data") >= 0) {
|
||||
int bi = contentType.indexOf("boundary=");
|
||||
String boundary = (bi >= 0) ? contentType.substring(bi + 9) : "";
|
||||
boundary.trim();
|
||||
parseMultipart(boundary, body, kv);
|
||||
} else {
|
||||
parseUrlencoded(body, kv);
|
||||
}
|
||||
auto fHas = [&](const String &name) -> bool { for (auto &e : kv) if (e.k == name) return true; return false; };
|
||||
auto fGet = [&](const String &name) -> String { for (auto &e : kv) if (e.k == name) return e.v; return String(); };
|
||||
auto getParamStringSafe = [&](const String &name, const String &def = "") -> String { return fHas(name) ? fGet(name) : def; };
|
||||
auto getParamIntSafe = [&](const String &name, int def = 0) -> int { return fHas(name) ? fGet(name).toInt() : def; };
|
||||
auto getParamFloatSafe = [&](const String &name, float def = 0.0f) -> float { return fHas(name) ? fGet(name).toFloat() : def; };
|
||||
auto getParamDoubleSafe = [&](const String &name, double def = 0.0) -> double { return fHas(name) ? (double)fGet(name).toDouble() : def; };
|
||||
|
||||
int networks = getParamIntSafe("wifi.APs");
|
||||
|
||||
Config.wifiAPs = {};
|
||||
|
||||
for (int i = 0; i < networks; i++) {
|
||||
WiFi_AP wifiap;
|
||||
wifiap.ssid = getParamStringSafe("wifi.AP." + String(i) + ".ssid");
|
||||
wifiap.password = getParamStringSafe("wifi.AP." + String(i) + ".password");
|
||||
|
||||
Config.wifiAPs.push_back(wifiap);
|
||||
}
|
||||
|
||||
Config.startupDelay = getParamIntSafe("startupDelay", Config.startupDelay);
|
||||
|
||||
Config.callsign = getParamStringSafe("callsign", Config.callsign);
|
||||
Config.tacticalCallsign = getParamStringSafe("tacticalCallsign", Config.tacticalCallsign);
|
||||
Config.wifiAutoAP.enabled = fHas("wifi.autoAP.enabled");
|
||||
Config.wifiAutoAP.password = getParamStringSafe("wifi.autoAP.password", Config.wifiAutoAP.password);
|
||||
Config.wifiAutoAP.timeout = getParamIntSafe("wifi.autoAP.timeout", Config.wifiAutoAP.timeout);
|
||||
|
||||
Config.aprs_is.active = fHas("aprs_is.active");
|
||||
if (Config.aprs_is.active) {
|
||||
Config.aprs_is.messagesToRF = fHas("aprs_is.messagesToRF");
|
||||
Config.aprs_is.objectsToRF = fHas("aprs_is.objectsToRF");
|
||||
Config.aprs_is.is2Metadata = fHas("aprs_is.is2Metadata");
|
||||
Config.aprs_is.server = getParamStringSafe("aprs_is.server", Config.aprs_is.server);
|
||||
Config.aprs_is.passcode = getParamStringSafe("aprs_is.passcode", Config.aprs_is.passcode);
|
||||
Config.aprs_is.port = getParamIntSafe("aprs_is.port", Config.aprs_is.port);
|
||||
Config.aprs_is.filter = getParamStringSafe("aprs_is.filter", Config.aprs_is.filter);
|
||||
}
|
||||
|
||||
Config.beacon.interval = getParamIntSafe("beacon.interval", Config.beacon.interval);
|
||||
Config.beacon.sendViaAPRSIS = fHas("beacon.sendViaAPRSIS");
|
||||
Config.beacon.sendViaRF = fHas("beacon.sendViaRF");
|
||||
Config.beacon.beaconFreq = getParamIntSafe("beacon.beaconFreq", Config.beacon.beaconFreq);
|
||||
Config.beacon.latitude = getParamDoubleSafe("beacon.latitude", Config.beacon.latitude);
|
||||
Config.beacon.longitude = getParamDoubleSafe("beacon.longitude", Config.beacon.longitude);
|
||||
Config.beacon.comment = getParamStringSafe("beacon.comment", Config.beacon.comment);
|
||||
Config.beacon.rfCommentEveryXBeacons = getParamIntSafe("beacon.rfCommentEveryXBeacons", Config.beacon.rfCommentEveryXBeacons);
|
||||
Config.beacon.overlay = getParamStringSafe("beacon.overlay", Config.beacon.overlay);
|
||||
Config.beacon.symbol = getParamStringSafe("beacon.symbol", Config.beacon.symbol);
|
||||
Config.beacon.path = getParamStringSafe("beacon.path", Config.beacon.path);
|
||||
|
||||
Config.beacon.statusActive = fHas("beacon.statusActive");
|
||||
if (Config.beacon.statusActive) {
|
||||
Config.beacon.statusPacket = getParamStringSafe("beacon.statusPacket", Config.beacon.statusPacket);
|
||||
}
|
||||
|
||||
Config.beacon.gpsActive = fHas("beacon.gpsActive");
|
||||
Config.beacon.ambiguityLevel = getParamIntSafe("beacon.ambiguityLevel", Config.beacon.ambiguityLevel);
|
||||
|
||||
Config.personalNote = getParamStringSafe("personalNote", Config.personalNote);
|
||||
|
||||
Config.blacklist = getParamStringSafe("blacklist", Config.blacklist);
|
||||
|
||||
Config.digi.mode = getParamIntSafe("digi.mode", Config.digi.mode);
|
||||
Config.digi.ecoMode = getParamIntSafe("digi.ecoMode", Config.digi.ecoMode);
|
||||
Config.digi.backupDigiMode = fHas("digi.backupDigiMode");
|
||||
|
||||
Config.loramodule.rxActive = fHas("lora.rxActive");
|
||||
Config.loramodule.rxFreq = getParamIntSafe("lora.rxFreq", Config.loramodule.rxFreq);
|
||||
Config.loramodule.rxSpreadingFactor = getParamIntSafe("lora.rxSpreadingFactor", Config.loramodule.rxSpreadingFactor);
|
||||
Config.loramodule.rxCodingRate4 = getParamIntSafe("lora.rxCodingRate4", Config.loramodule.rxCodingRate4);
|
||||
Config.loramodule.rxSignalBandwidth = getParamIntSafe("lora.rxSignalBandwidth", Config.loramodule.rxSignalBandwidth);
|
||||
Config.loramodule.txActive = fHas("lora.txActive");
|
||||
Config.loramodule.txFreq = getParamIntSafe("lora.txFreq", Config.loramodule.txFreq);
|
||||
Config.loramodule.txSpreadingFactor = getParamIntSafe("lora.txSpreadingFactor", Config.loramodule.txSpreadingFactor);
|
||||
Config.loramodule.txCodingRate4 = getParamIntSafe("lora.txCodingRate4", Config.loramodule.txCodingRate4);
|
||||
Config.loramodule.txSignalBandwidth = getParamIntSafe("lora.txSignalBandwidth", Config.loramodule.txSignalBandwidth);
|
||||
Config.loramodule.power = LoRa_Utils::validPower(getParamIntSafe("lora.power", Config.loramodule.power)); // saved as the power the radio chip really uses
|
||||
Config.loramodule.cadActive = fHas("lora.cadActive");
|
||||
|
||||
Config.display.alwaysOn = fHas("display.alwaysOn");
|
||||
if (!Config.display.alwaysOn) {
|
||||
Config.display.timeout = getParamIntSafe("display.timeout", Config.display.timeout);
|
||||
}
|
||||
Config.display.turn180 = fHas("display.turn180");
|
||||
|
||||
Config.battery.sendInternalVoltage = fHas("battery.sendInternalVoltage");
|
||||
Config.battery.monitorInternalVoltage = fHas("battery.monitorInternalVoltage");
|
||||
if (Config.battery.monitorInternalVoltage) {
|
||||
Config.battery.internalSleepVoltage = getParamFloatSafe("battery.internalSleepVoltage", Config.battery.internalSleepVoltage);
|
||||
}
|
||||
|
||||
Config.battery.sendExternalVoltage = fHas("battery.sendExternalVoltage");
|
||||
if (Config.battery.sendExternalVoltage) {
|
||||
Config.battery.useExternalI2CSensor = fHas("battery.useExternalI2CSensor");
|
||||
}
|
||||
if (Config.battery.sendExternalVoltage) {
|
||||
Config.battery.externalVoltagePin = getParamIntSafe("battery.externalVoltagePin", Config.battery.externalVoltagePin);
|
||||
Config.battery.voltageDividerR1 = getParamFloatSafe("battery.voltageDividerR1", Config.battery.voltageDividerR1);
|
||||
Config.battery.voltageDividerR2 = getParamFloatSafe("battery.voltageDividerR2", Config.battery.voltageDividerR2);
|
||||
}
|
||||
Config.battery.monitorExternalVoltage = fHas("battery.monitorExternalVoltage");
|
||||
if (Config.battery.monitorExternalVoltage) {
|
||||
Config.battery.externalSleepVoltage = getParamFloatSafe("battery.externalSleepVoltage", Config.battery.externalSleepVoltage);
|
||||
}
|
||||
Config.battery.sendVoltageAsTelemetry = fHas("battery.sendVoltageAsTelemetry");
|
||||
|
||||
Config.wxsensor.active = fHas("wxsensor.active");
|
||||
if (Config.wxsensor.active) {
|
||||
Config.wxsensor.heightCorrection = getParamIntSafe("wxsensor.heightCorrection", Config.wxsensor.heightCorrection);
|
||||
Config.wxsensor.temperatureCorrection = getParamFloatSafe("wxsensor.temperatureCorrection", Config.wxsensor.temperatureCorrection);
|
||||
Config.beacon.symbol = "_";
|
||||
}
|
||||
|
||||
Config.syslog.active = fHas("syslog.active");
|
||||
if (Config.syslog.active) {
|
||||
Config.syslog.server = getParamStringSafe("syslog.server", Config.syslog.server);
|
||||
Config.syslog.port = getParamIntSafe("syslog.port", Config.syslog.port);
|
||||
Config.syslog.logBeaconOverTCPIP = fHas("syslog.logBeaconOverTCPIP");
|
||||
}
|
||||
|
||||
Config.tnc.enableServer = fHas("tnc.enableServer");
|
||||
Config.tnc.enableSerial = fHas("tnc.enableSerial");
|
||||
Config.tnc.acceptOwn = fHas("tnc.acceptOwn");
|
||||
Config.tnc.aprsBridgeActive = fHas("tnc.aprsBridgeActive");
|
||||
Config.tnc.kissProtocol = getParamStringSafe("tnc.kissProtocol", Config.tnc.kissProtocol ? "KISS" : "TNC2") != "TNC2";
|
||||
|
||||
Config.mqtt.active = fHas("mqtt.active");
|
||||
if (Config.mqtt.active) {
|
||||
Config.mqtt.server = getParamStringSafe("mqtt.server", Config.mqtt.server);
|
||||
Config.mqtt.topic = getParamStringSafe("mqtt.topic", Config.mqtt.topic);
|
||||
Config.mqtt.username = getParamStringSafe("mqtt.username", Config.mqtt.username);
|
||||
Config.mqtt.password = getParamStringSafe("mqtt.password", Config.mqtt.password);
|
||||
Config.mqtt.port = getParamIntSafe("mqtt.port", Config.mqtt.port);
|
||||
Config.mqtt.beaconOverMqtt = fHas("mqtt.beaconOverMqtt");
|
||||
}
|
||||
|
||||
Config.rebootMode = fHas("other.rebootMode");
|
||||
if (Config.rebootMode) {
|
||||
Config.rebootModeTime = getParamIntSafe("other.rebootModeTime", Config.rebootModeTime);
|
||||
}
|
||||
|
||||
Config.ota.username = getParamStringSafe("ota.username", Config.ota.username);
|
||||
Config.ota.password = getParamStringSafe("ota.password", Config.ota.password);
|
||||
|
||||
Config.webadmin.active = fHas("webadmin.active");
|
||||
if (Config.webadmin.active) {
|
||||
Config.webadmin.username = getParamStringSafe("webadmin.username", Config.webadmin.username);
|
||||
Config.webadmin.password = getParamStringSafe("webadmin.password", Config.webadmin.password);
|
||||
}
|
||||
|
||||
Config.remoteManagement.managers = getParamStringSafe("remoteManagement.managers", Config.remoteManagement.managers);
|
||||
Config.remoteManagement.rfOnly = fHas("remoteManagement.rfOnly");
|
||||
|
||||
Config.ntp.server = getParamStringSafe("ntp.server", Config.ntp.server);
|
||||
Config.ntp.gmtCorrection = getParamFloatSafe("ntp.gmtCorrection", Config.ntp.gmtCorrection);
|
||||
|
||||
Config.network.dhcp = fHas("network.dhcp");
|
||||
if (!Config.network.dhcp) {
|
||||
Config.network.ip = getParamStringSafe("network.ip", Config.network.ip);
|
||||
Config.network.gateway = getParamStringSafe("network.gateway", Config.network.gateway);
|
||||
Config.network.subnet = getParamStringSafe("network.subnet", Config.network.subnet);
|
||||
Config.network.dns = getParamStringSafe("network.dns", Config.network.dns);
|
||||
}
|
||||
|
||||
Config.rememberStationTime = getParamIntSafe("other.rememberStationTime", Config.rememberStationTime);
|
||||
|
||||
Serial.printf("[cfg] applied %d form fields\n", (int)kv.size());
|
||||
return Config.writeFile();
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* RP2350 digipeater — lean port of DIGI_Utils (src/digi_utils.cpp).
|
||||
* Computes the WIDEn-N-rewritten packet to re-transmit over RF. The actual TX
|
||||
* is done by the caller (loraTask, which owns the radio) via
|
||||
* LoRa_Utils::sendNewPacket(), so this module never touches the radio or W5500.
|
||||
*/
|
||||
#include "digi_rp2350.h"
|
||||
#include "configuration.h"
|
||||
#include "station_rp2350.h"
|
||||
|
||||
extern Configuration Config;
|
||||
// Backup digi running right now (Config.digi.backupDigiMode ticked and APRS-IS
|
||||
// down); set by netTask in main.cpp, the RP2350 counterpart of the ESP32 global
|
||||
// backupDigiMode in LoRa_APRS_iGate.cpp.
|
||||
extern volatile bool g_backupDigi;
|
||||
|
||||
namespace {
|
||||
|
||||
String stationCall() {
|
||||
return Config.tacticalCallsign.length() ? Config.tacticalCallsign : Config.callsign;
|
||||
}
|
||||
|
||||
// strip any residual on-air header bytes ('<' 0xFF 0x01) appended to the payload
|
||||
String checkForStartingBytes(const String& packet) {
|
||||
int idx = packet.indexOf("\x3c\xff\x01");
|
||||
return (idx != -1) ? packet.substring(0, idx) : packet;
|
||||
}
|
||||
|
||||
// Drop used WIDE1*/WIDE2* hops, matching whole path tokens only (port of
|
||||
// DIGI_Utils::cleanPath).
|
||||
String cleanPath(const String& path) {
|
||||
String result;
|
||||
unsigned int start = 0;
|
||||
while (true) {
|
||||
int delim = path.indexOf(',', start);
|
||||
int end = (delim == -1) ? path.length() : delim;
|
||||
String token = path.substring(start, end);
|
||||
if (token != "WIDE1*" && token != "WIDE2*") {
|
||||
if (result.length() > 0) result += ",";
|
||||
result += token;
|
||||
}
|
||||
if (delim == -1) break;
|
||||
start = delim + 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Offset of `token` as a whole comma-separated path element, or -1 (port of
|
||||
// DIGI_Utils' pathTokenIndex).
|
||||
int pathTokenIndex(const String& path, const String& token) {
|
||||
unsigned int start = 0;
|
||||
while (start < path.length()) {
|
||||
int end = path.indexOf(",", start);
|
||||
if (end == -1) end = path.length();
|
||||
if (path.substring(start, end) == token) return start;
|
||||
start = end + 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Port of DIGI_Utils::processMode3Path: digipeat only when our own callsign is
|
||||
// listed (unused) in the path, keeping the rest of the path intact and marking
|
||||
// our token with '*'. Every token before ours must already be marked.
|
||||
String processMode3Path(const String& path, const String& call) {
|
||||
int start = 0;
|
||||
bool prevTokensAllStar = true;
|
||||
int ownTokenEnd = -1;
|
||||
|
||||
while (start < (int)path.length()) {
|
||||
int delim = path.indexOf(',', start);
|
||||
if (delim == -1) delim = path.length();
|
||||
|
||||
String token = path.substring(start, delim);
|
||||
bool tokenIsOwn = (token == call) || (token == call + "*");
|
||||
bool tokenStar = token.endsWith("*");
|
||||
|
||||
if (tokenIsOwn) {
|
||||
if (tokenStar) return ""; // already digipeated by us
|
||||
if (!prevTokensAllStar) return ""; // earlier hops must be marked
|
||||
ownTokenEnd = delim;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!tokenStar) prevTokensAllStar = false;
|
||||
start = delim + 1;
|
||||
}
|
||||
|
||||
if (ownTokenEnd == -1) return "";
|
||||
return cleanPath(path.substring(0, ownTokenEnd)) + "*" + path.substring(ownTokenEnd);
|
||||
}
|
||||
|
||||
// Port of DIGI_Utils::buildPacket, non-crossFreq / non-thirdParty branch only.
|
||||
// `packet` is the headerless "SENDER>PATH:payload"; `path` is the part after the
|
||||
// first comma in PATH (e.g. "WIDE1-1" or "WIDE2-2").
|
||||
String buildPacket(const String& path, const String& packet) {
|
||||
String call = stationCall();
|
||||
int colon = packet.indexOf(':');
|
||||
int digiMode = Config.digi.mode;
|
||||
String tempPath = path;
|
||||
|
||||
if (tempPath.indexOf("WIDE1-1") != -1 && (digiMode == 1 || digiMode == 2 || g_backupDigi)) {
|
||||
if (tempPath.indexOf('*') != -1) return ""; // '*' shouldn't precede WIDE1-1
|
||||
if (pathTokenIndex(tempPath, "WIDE1-1") != 0) return ""; // WIDE1-1 must be the first hop
|
||||
tempPath = call + "*" + tempPath.substring(7);
|
||||
} else if (tempPath.indexOf("WIDE2-") != -1 && digiMode == 2) {
|
||||
tempPath = cleanPath(path);
|
||||
int idx = pathTokenIndex(tempPath, "WIDE2-1");
|
||||
if (idx != -1) {
|
||||
tempPath = tempPath.substring(0, idx) + call + "*" + tempPath.substring(idx + 7);
|
||||
} else {
|
||||
idx = pathTokenIndex(tempPath, "WIDE2-2");
|
||||
if (idx == -1) return ""; // WIDE2-3+ unsupported
|
||||
tempPath = tempPath.substring(0, idx) + call + "*,WIDE2-1" + tempPath.substring(idx + 7);
|
||||
}
|
||||
} else if (digiMode == 3) { // own-callsign path digi
|
||||
tempPath = processMode3Path(tempPath, call);
|
||||
if (tempPath == "") return "";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
String out = packet.substring(0, packet.indexOf(',') + 1); // "SENDER>APxxxx,"
|
||||
out += tempPath;
|
||||
out += checkForStartingBytes(packet.substring(colon)); // ":payload"
|
||||
return out;
|
||||
}
|
||||
|
||||
// Port of DIGI_Utils::generateDigipeatedPacket, non-thirdParty / non-crossFreq.
|
||||
String generateDigipeatedPacket(const String& packet) {
|
||||
int gt = packet.indexOf('>');
|
||||
int colon = packet.indexOf(':');
|
||||
if (gt < 0 || colon <= gt) return "";
|
||||
String hdr = packet.substring(gt + 1, colon); // "APxxxx,WIDE1-1,..."
|
||||
int comma = hdr.indexOf(',');
|
||||
int digiMode = Config.digi.mode;
|
||||
bool backup = g_backupDigi;
|
||||
|
||||
if (comma <= 2) return ""; // no path -> nothing to consume
|
||||
String path = hdr.substring(comma + 1);
|
||||
|
||||
if (digiMode == 1 || backup) { // WIDE1-1 fill-in digi
|
||||
return (path.indexOf("WIDE1-1") != -1) ? buildPacket(path, packet) : "";
|
||||
}
|
||||
if (digiMode == 2) { // WIDE2-n (+ WIDE1-1) digi
|
||||
int w1 = path.indexOf("WIDE1-1");
|
||||
int w2 = path.indexOf("WIDE2-");
|
||||
bool hasW1 = w1 != -1, hasW2 = w2 != -1;
|
||||
if (hasW1 && hasW2 && w2 < w1) return ""; // WIDE1 must precede WIDE2
|
||||
if (hasW1 || hasW2) return buildPacket(path, packet);
|
||||
}
|
||||
if (digiMode == 3) { // repeat only if we are in the path
|
||||
if (path.indexOf(stationCall()) != -1) return buildPacket(path, packet);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace Digi {
|
||||
|
||||
bool enabled() {
|
||||
// Digi modes (upstream V4.0.0 numbering): 1 = WIDE1-1 fill-in, 2 = WIDE2-n,
|
||||
// 3 = own-callsign path. CrossFreq digipeating is not ported.
|
||||
return (Config.digi.mode >= 1 && Config.digi.mode <= 3) || g_backupDigi;
|
||||
}
|
||||
|
||||
String process(const String& rawPacket) {
|
||||
if (!enabled()) return "";
|
||||
if (rawPacket.length() < 5) return "";
|
||||
|
||||
String packet = rawPacket.substring(3); // drop 3-byte LoRa-APRS header
|
||||
int gt = packet.indexOf('>');
|
||||
if (gt < 3) return "";
|
||||
int colon = packet.indexOf(':');
|
||||
if (colon < gt) return "";
|
||||
String sender = packet.substring(0, gt);
|
||||
|
||||
// NOGATE in the path is not repeated (as DIGI_Utils::processLoRaPacket). RFONLY
|
||||
// only keeps a packet off APRS-IS, so it is still digipeated.
|
||||
String hdr = packet.substring(gt + 1, colon); // "APxxxx,WIDE1-1,..."
|
||||
int comma = hdr.indexOf(',');
|
||||
if (comma > 2 && hdr.substring(comma + 1).indexOf("NOGATE") >= 0) return "";
|
||||
|
||||
String call = stationCall();
|
||||
if (sender == call) return ""; // never repeat ourselves
|
||||
if (Config.tacticalCallsign.length() == 0 && !Station::callsignIsValid(sender)) return "";
|
||||
|
||||
// NOTE: duplicate filtering + blacklist are applied upstream in loraTask
|
||||
// (Station::isDuplicate / isBlacklisted), shared with the gate path.
|
||||
return generateDigipeatedPacket(packet);
|
||||
}
|
||||
|
||||
} // namespace Digi
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Lean APRS digipeater for the RP2350 port. Faithful port of the WIDEn-N path
|
||||
// rewriting from src/digi_utils.cpp (DIGI_Utils), trimmed to the single-radio /
|
||||
// same-frequency case (no cross-freq, no third-party, no message queries — those
|
||||
// belong to the iGate/TNC paths). Read-only on Config; keeps its own small dedup
|
||||
// ring buffer to break repeater loops.
|
||||
//
|
||||
// Modes (Config.digi.mode, matching the web UI since V4.0.0):
|
||||
// 0 OFF
|
||||
// 1 WIDE1 (fill-in) digi — consume WIDE1-1 only
|
||||
// 2 WIDE2 (+WIDE1) digi — consume WIDE1-1 and WIDE2-n
|
||||
// 3 own-callsign digi — repeat only when our callsign is next in the path
|
||||
// While the backup digi runs (Config.digi.backupDigiMode ticked AND APRS-IS down,
|
||||
// see g_backupDigi in main.cpp) only WIDE1-1 is repeated, whatever the mode.
|
||||
namespace Digi {
|
||||
// True when digipeating is enabled (so the caller can skip the work entirely).
|
||||
bool enabled();
|
||||
|
||||
// Given the RAW received packet (WITH the 3-byte LoRa-APRS header), returns
|
||||
// the headerless packet to re-transmit over RF ("SENDER>PATH:payload"), or ""
|
||||
// if this packet should not be digipeated (off, self, dup, no WIDE to consume,
|
||||
// invalid callsign, NOGATE in the path).
|
||||
String process(const String& rawPacket);
|
||||
}
|
||||
@@ -0,0 +1,459 @@
|
||||
#include "eth_web.h"
|
||||
#include <Arduino.h>
|
||||
#include <Ethernet.h>
|
||||
#include <LittleFS.h>
|
||||
#include <vector>
|
||||
#include "web_assets.h" // gzipped SPA assets embedded in flash
|
||||
#include "ntp_rp2350.h"
|
||||
#include "ota_rp2350.h"
|
||||
#include "map_utils.h" // stations heard with a decoded position (web "Map" view)
|
||||
#include "configuration.h"
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
// Apply a posted config form (urlencoded or multipart) to Config + persist.
|
||||
extern bool applyConfigForm(const String &contentType, const String &body);
|
||||
|
||||
// Set by POST /action?type=send-beacon; netTask sends an APRS-IS beacon and clears it.
|
||||
extern volatile bool g_beaconNow;
|
||||
// Set by POST /action?type=send-rf-beacon; loraTask sends an RF beacon and clears it.
|
||||
extern volatile bool g_rfBeaconNow;
|
||||
// Originate an APRS message (RF via loraTask and/or APRS-IS via the socket);
|
||||
// sentRF / sentTCP report which copies actually went out.
|
||||
extern void webSendMessage(const String &to, const String &text, bool viaRF, bool viaTCP,
|
||||
bool &sentRF, bool &sentTCP);
|
||||
|
||||
static const int WEB_PORT = 80;
|
||||
static const size_t MAX_LINE_LEN = 512;
|
||||
static const long MAX_CONFIG_BODY = 64 * 1024; // POST /configuration.json; bigger = 413
|
||||
static const size_t MAX_HEADER_LINES = 40;
|
||||
static const char *CONFIG_PATH = "/igate_conf.json";
|
||||
|
||||
static EthernetServer webServer(WEB_PORT);
|
||||
static bool webStarted = false;
|
||||
|
||||
// --- incoming APRS messages addressed to us (shown in the Messages view) ---
|
||||
struct RxMsg { String from; String text; String via; uint32_t when; };
|
||||
static std::vector<RxMsg> rxMessages; // netTask-owned, newest pushed to back
|
||||
static const size_t RXMSG_MAX = 20;
|
||||
|
||||
void ethWebAddMessage(const String &from, const String &text, const String &via) {
|
||||
if (rxMessages.size() >= RXMSG_MAX) rxMessages.erase(rxMessages.begin());
|
||||
rxMessages.push_back({from, text, via, millis()});
|
||||
Serial.println("[msg] from " + from + " (" + via + "): " + text);
|
||||
}
|
||||
|
||||
// --- received LoRa packets log (shown in the Received packets view) ---
|
||||
struct RxPkt { String frame; int rssi; float snr; uint32_t when; };
|
||||
static std::vector<RxPkt> rxPackets; // netTask-owned, newest pushed to back
|
||||
static const size_t RXPKT_MAX = 10;
|
||||
|
||||
void ethWebAddPacket(const String &frame, int rssi, float snr) {
|
||||
if (rxPackets.size() >= RXPKT_MAX) rxPackets.erase(rxPackets.begin());
|
||||
rxPackets.push_back({frame, rssi, snr, millis()});
|
||||
}
|
||||
|
||||
struct Request {
|
||||
String method;
|
||||
String path;
|
||||
String query;
|
||||
String contentType;
|
||||
String authorization;
|
||||
String ifNoneMatch;
|
||||
long contentLength = 0;
|
||||
};
|
||||
|
||||
// minimal percent-decoder for query-string values
|
||||
static String urlDecodeQ(const String &s) {
|
||||
String out; out.reserve(s.length());
|
||||
for (size_t i = 0; i < s.length(); i++) {
|
||||
char ch = s[i];
|
||||
if (ch == '+') out += ' ';
|
||||
else if (ch == '%' && i + 2 < s.length()) {
|
||||
auto hx = [](char h) -> int {
|
||||
if (h >= '0' && h <= '9') return h - '0';
|
||||
if (h >= 'a' && h <= 'f') return h - 'a' + 10;
|
||||
if (h >= 'A' && h <= 'F') return h - 'A' + 10;
|
||||
return 0; };
|
||||
out += (char)((hx(s[i + 1]) << 4) | hx(s[i + 2])); i += 2;
|
||||
} else out += ch;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// extract a query-string parameter ("key=value", value up to '&'), url-decoded
|
||||
static String getQueryParam(const String &query, const char *key) {
|
||||
String needle = String(key) + "=";
|
||||
int i = query.indexOf(needle);
|
||||
if (i < 0) return "";
|
||||
i += needle.length();
|
||||
int amp = query.indexOf('&', i);
|
||||
if (amp < 0) amp = query.length();
|
||||
return urlDecodeQ(query.substring(i, amp));
|
||||
}
|
||||
|
||||
// standard base64 of a string (for HTTP Basic auth comparison)
|
||||
static String b64(const String &data) {
|
||||
static const char *T = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
String r;
|
||||
int v = 0, c = 0;
|
||||
for (size_t i = 0; i < data.length(); i++) {
|
||||
v = (v << 8) | (uint8_t)data[i];
|
||||
c += 8;
|
||||
while (c >= 6) { c -= 6; r += T[(v >> c) & 0x3F]; }
|
||||
}
|
||||
if (c > 0) r += T[(v << (6 - c)) & 0x3F];
|
||||
while (r.length() % 4) r += '=';
|
||||
return r;
|
||||
}
|
||||
|
||||
// web-interface HTTP Basic auth: allowed unless webadmin is active with creds and
|
||||
// the request lacks the matching "Authorization: Basic <base64(user:pass)>".
|
||||
static bool webAuthOk(const String &authHeader) {
|
||||
if (!Config.webadmin.active) return true;
|
||||
if (Config.webadmin.username.length() == 0 && Config.webadmin.password.length() == 0) return true;
|
||||
if (!authHeader.startsWith("Basic ")) return false;
|
||||
String token = authHeader.substring(6);
|
||||
token.trim();
|
||||
return token == b64(Config.webadmin.username + ":" + Config.webadmin.password);
|
||||
}
|
||||
|
||||
// escape a string for embedding in a JSON string literal
|
||||
static String jsonEscape(const String &s) {
|
||||
String out; out.reserve(s.length() + 4);
|
||||
for (size_t i = 0; i < s.length(); i++) {
|
||||
char ch = s[i];
|
||||
if (ch == '"' || ch == '\\') { out += '\\'; out += ch; }
|
||||
else if (ch == '\n') out += "\\n";
|
||||
else if (ch == '\r') out += "\\r";
|
||||
else if (ch == '\t') out += "\\t";
|
||||
else if ((uint8_t)ch < 0x20) { /* drop other control chars */ }
|
||||
else out += ch;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// ---- HTTP request parsing (adapted from mesh/eth/ethApiHandlers.cpp) ----
|
||||
static bool readLine(EthernetClient &c, String &out, uint32_t deadlineMs) {
|
||||
out = "";
|
||||
while ((int32_t)(millis() - deadlineMs) < 0) {
|
||||
if (!c.connected()) return false;
|
||||
if (!c.available()) { delay(1); continue; }
|
||||
int ch = c.read();
|
||||
if (ch < 0) continue;
|
||||
if (ch == '\n') return true;
|
||||
if (ch == '\r') continue;
|
||||
if (out.length() >= MAX_LINE_LEN) return false;
|
||||
out += (char)ch;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool headerIs(const String &line, const char *prefix, String &valueOut) {
|
||||
size_t pl = strlen(prefix);
|
||||
if (line.length() < pl + 1) return false;
|
||||
for (size_t i = 0; i < pl; i++) {
|
||||
char a = line.charAt(i), b = prefix[i];
|
||||
if (a >= 'A' && a <= 'Z') a += 32;
|
||||
if (b >= 'A' && b <= 'Z') b += 32;
|
||||
if (a != b) return false;
|
||||
}
|
||||
if (line.charAt(pl) != ':') return false;
|
||||
valueOut = line.substring(pl + 1);
|
||||
valueOut.trim();
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parseRequest(EthernetClient &c, Request &req, uint32_t deadlineMs) {
|
||||
String line;
|
||||
if (!readLine(c, line, deadlineMs) || line.length() == 0) return false;
|
||||
int sp1 = line.indexOf(' ');
|
||||
int sp2 = line.indexOf(' ', sp1 + 1);
|
||||
if (sp1 <= 0 || sp2 <= sp1) return false;
|
||||
req.method = line.substring(0, sp1);
|
||||
String full = line.substring(sp1 + 1, sp2);
|
||||
int q = full.indexOf('?');
|
||||
if (q >= 0) { req.path = full.substring(0, q); req.query = full.substring(q + 1); }
|
||||
else { req.path = full; req.query = ""; }
|
||||
size_t n = 0; String val;
|
||||
while (n++ < MAX_HEADER_LINES) {
|
||||
if (!readLine(c, line, deadlineMs)) return false;
|
||||
if (line.length() == 0) return true; // end of headers
|
||||
if (headerIs(line, "Content-Length", val)) req.contentLength = val.toInt();
|
||||
else if (headerIs(line, "Content-Type", val)) req.contentType = val;
|
||||
else if (headerIs(line, "Authorization", val)) req.authorization = val;
|
||||
else if (headerIs(line, "If-None-Match", val)) req.ifNoneMatch = val;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---- response helpers ----
|
||||
static void sendStatus(EthernetClient &c, int code, const char *reason) {
|
||||
c.print("HTTP/1.1 "); c.print(code); c.print(' '); c.print(reason); c.print("\r\n");
|
||||
}
|
||||
// WIZnet's socketSend() clamps a write to the socket TX buffer (SSIZE, 2 KB here)
|
||||
// but EthernetClient::write() returns the size it was ASKED for, not what it sent,
|
||||
// so a single print() of a longer body silently loses the tail: a /stations.json of
|
||||
// 2616 bytes reached the browser cut at 2048, mid-JSON, and the map stayed empty.
|
||||
// Always hand the socket chunks that fit, and give up if the peer goes away or
|
||||
// stops reading for 5 s (an idle timeout, not a total one: the page is one ~185 KB
|
||||
// response now, see tools/gen_web_assets_rp2350.py, and a slow client may need longer).
|
||||
static void sendBody(EthernetClient &c, const uint8_t *data, size_t len) {
|
||||
size_t sent = 0;
|
||||
uint32_t deadline = millis() + 5000;
|
||||
while (sent < len && c.connected() && (int32_t)(millis() - deadline) < 0) {
|
||||
size_t chunk = len - sent;
|
||||
if (chunk > 1024) chunk = 1024;
|
||||
size_t w = c.write(data + sent, chunk);
|
||||
if (w == 0) { delay(1); continue; } // TX buffer full: let it drain
|
||||
sent += w;
|
||||
deadline = millis() + 5000;
|
||||
}
|
||||
if (sent < len) Serial.printf("[web] short send: %u of %u bytes\n", (unsigned)sent, (unsigned)len);
|
||||
}
|
||||
|
||||
static void sendText(EthernetClient &c, int code, const char *reason, const char *ctype, const String &body) {
|
||||
sendStatus(c, code, reason);
|
||||
c.print("Content-Type: "); c.print(ctype); c.print("\r\n");
|
||||
c.print("Content-Length: "); c.print(body.length()); c.print("\r\n");
|
||||
c.print("Connection: close\r\n\r\n");
|
||||
sendBody(c, (const uint8_t *)body.c_str(), body.length());
|
||||
}
|
||||
|
||||
static void serveConfig(EthernetClient &c) {
|
||||
File f = LittleFS.open(CONFIG_PATH, "r");
|
||||
if (!f) { sendText(c, 200, "OK", "application/json", "{}"); return; }
|
||||
sendStatus(c, 200, "OK");
|
||||
c.print("Content-Type: application/json\r\n");
|
||||
c.print("Content-Length: "); c.print((uint32_t)f.size()); c.print("\r\n");
|
||||
c.print("Connection: close\r\n\r\n");
|
||||
uint8_t buf[256];
|
||||
size_t n;
|
||||
while ((n = f.read(buf, sizeof(buf))) > 0) c.write(buf, n);
|
||||
f.close();
|
||||
}
|
||||
|
||||
// Serve a gzipped flash asset (chunked — the W5500 TX buffer is ~2 KB/socket).
|
||||
// The SPA assets live in flash, so they only change when the firmware does:
|
||||
// tag them with the build stamp and let the browser revalidate on each load.
|
||||
// With a plain "max-age" a browser kept serving the old page for an hour after
|
||||
// an OTA -- and mixed old and new files, since each asset expires on its own --
|
||||
// which looks exactly like a broken web UI.
|
||||
static String assetEtag(const WebAsset &a) {
|
||||
extern const char *FW_BUILD;
|
||||
uint32_t h = 5381;
|
||||
for (const char *p = FW_BUILD; *p; p++) h = h * 33u + (uint8_t)*p;
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof(buf), "\"%08lx-%x\"", (unsigned long)h, (unsigned)a.len);
|
||||
return String(buf);
|
||||
}
|
||||
|
||||
static void serveAsset(EthernetClient &c, const WebAsset &a, const String &ifNoneMatch) {
|
||||
String etag = assetEtag(a);
|
||||
if (ifNoneMatch.length() && ifNoneMatch.indexOf(etag) >= 0) { // unchanged since last load
|
||||
sendStatus(c, 304, "Not Modified");
|
||||
c.print("ETag: "); c.print(etag); c.print("\r\n");
|
||||
c.print("Cache-Control: no-cache\r\n");
|
||||
c.print("Content-Length: 0\r\nConnection: close\r\n\r\n");
|
||||
return;
|
||||
}
|
||||
sendStatus(c, 200, "OK");
|
||||
c.print("Content-Type: "); c.print(a.ctype); c.print("\r\n");
|
||||
c.print("Content-Encoding: gzip\r\n");
|
||||
c.print("Cache-Control: no-cache\r\n");
|
||||
c.print("ETag: "); c.print(etag); c.print("\r\n");
|
||||
c.print("Content-Length: "); c.print((uint32_t)a.len); c.print("\r\n");
|
||||
c.print("Connection: close\r\n\r\n");
|
||||
sendBody(c, a.data, a.len); // RP2350: flash is directly addressable
|
||||
}
|
||||
|
||||
// POST /configuration.json : read the urlencoded body, apply to Config, persist,
|
||||
// then redirect + reboot (mirrors the original web_utils flow).
|
||||
static void handleConfigPost(EthernetClient &c, const Request &req) {
|
||||
if (req.contentLength > MAX_CONFIG_BODY) {
|
||||
sendText(c, 413, "Payload Too Large", "text/plain", "config form too large");
|
||||
c.flush();
|
||||
return;
|
||||
}
|
||||
String body;
|
||||
if (req.contentLength > 0) body.reserve(req.contentLength);
|
||||
uint32_t dl = millis() + 8000;
|
||||
while ((long)body.length() < req.contentLength && (int32_t)(millis() - dl) < 0) {
|
||||
int avail = c.available();
|
||||
if (avail > 0) {
|
||||
while (avail-- > 0 && (long)body.length() < req.contentLength) body += (char)c.read();
|
||||
} else if (!c.connected()) break;
|
||||
else delay(1);
|
||||
}
|
||||
Serial.printf("[web] POST /configuration.json: %d bytes (%s)\n",
|
||||
(int)body.length(), req.contentType.c_str());
|
||||
if (applyConfigForm(req.contentType, body)) {
|
||||
sendStatus(c, 302, "Found");
|
||||
c.print("Location: /?success=1\r\n");
|
||||
c.print("Content-Length: 0\r\nConnection: close\r\n\r\n");
|
||||
c.flush();
|
||||
delay(500);
|
||||
Serial.println("[web] config saved -> reboot");
|
||||
rp2040.restart();
|
||||
} else {
|
||||
sendText(c, 500, "Internal Server Error", "text/plain", "could not save config");
|
||||
c.flush();
|
||||
}
|
||||
}
|
||||
|
||||
static void handleClient(EthernetClient &c) {
|
||||
Request req;
|
||||
uint32_t deadline = millis() + 3000;
|
||||
if (!parseRequest(c, req, deadline)) return;
|
||||
Serial.printf("[web] %s %s\n", req.method.c_str(), req.path.c_str());
|
||||
|
||||
// web-interface auth (HTTP Basic) when enabled. /status (version probe) and
|
||||
// /update (its own OTA auth) are exempt to avoid breaking probes / double-auth.
|
||||
if (req.path != "/status" && req.path != "/update" && !webAuthOk(req.authorization)) {
|
||||
sendStatus(c, 401, "Unauthorized");
|
||||
c.print("WWW-Authenticate: Basic realm=\"iGate Admin\"\r\n");
|
||||
c.print("Content-Length: 0\r\nConnection: close\r\n\r\n");
|
||||
c.flush();
|
||||
return;
|
||||
}
|
||||
if (req.path == "/status") {
|
||||
extern const char *FW_BUILD;
|
||||
sendText(c, 200, "OK", "text/plain", String("LoRa APRS iGate RP2350 — built ") + FW_BUILD);
|
||||
c.flush();
|
||||
return;
|
||||
}
|
||||
if (req.path == "/stations.json") { // stations with a position, for the Map view
|
||||
sendText(c, 200, "OK", "application/json", MAP_Utils::getStationsJson());
|
||||
c.flush();
|
||||
return;
|
||||
}
|
||||
if (req.path == "/messages.json") {
|
||||
String body = "[";
|
||||
uint32_t now = millis();
|
||||
for (size_t i = rxMessages.size(); i-- > 0; ) { // newest first
|
||||
const RxMsg &m = rxMessages[i];
|
||||
body += "{\"from\":\""; body += jsonEscape(m.from);
|
||||
body += "\",\"text\":\""; body += jsonEscape(m.text);
|
||||
body += "\",\"via\":\""; body += jsonEscape(m.via);
|
||||
body += "\",\"age\":"; body += String((now - m.when) / 1000);
|
||||
body += "}";
|
||||
if (i != 0) body += ",";
|
||||
}
|
||||
body += "]";
|
||||
sendText(c, 200, "OK", "application/json", body);
|
||||
c.flush();
|
||||
return;
|
||||
}
|
||||
if (req.path == "/received-packets.json") {
|
||||
String body = "[";
|
||||
uint32_t now = millis();
|
||||
for (size_t i = rxPackets.size(); i-- > 0; ) { // newest first
|
||||
const RxPkt &p = rxPackets[i];
|
||||
uint32_t age = (now - p.when) / 1000;
|
||||
String ago = age < 60 ? String(age) + "s" : String(age / 60) + "m";
|
||||
// real wall-clock = NTP-now minus this packet's age (works even for
|
||||
// packets received before the NTP sync); fall back to "ago" if no NTP
|
||||
// (and no date, like upstream's empty getFormatedDate())
|
||||
uint32_t rxEpoch = Ntp::nowEpoch() - age;
|
||||
String rxDate = Ntp::synced() ? Ntp::ymd(rxEpoch) : "";
|
||||
String rxTime = Ntp::synced() ? Ntp::hms(rxEpoch) : ago;
|
||||
body += "{\"rxDate\":\""; body += rxDate;
|
||||
body += "\",\"rxTime\":\""; body += rxTime;
|
||||
body += "\",\"packet\":\""; body += jsonEscape(p.frame);
|
||||
body += "\",\"RSSI\":"; body += String(p.rssi);
|
||||
body += ",\"SNR\":"; body += String(p.snr, 1);
|
||||
body += "}";
|
||||
if (i != 0) body += ",";
|
||||
}
|
||||
body += "]";
|
||||
sendText(c, 200, "OK", "application/json", body);
|
||||
c.flush();
|
||||
return;
|
||||
}
|
||||
if (req.path == "/update") { // POST raw firmware.bin -> arduino-pico Updater
|
||||
if (req.method == "POST") { Ota::handleUpdate(c, req.authorization, req.contentLength); return; }
|
||||
sendText(c, 405, "Method Not Allowed", "text/plain", "POST firmware.bin");
|
||||
c.flush();
|
||||
return;
|
||||
}
|
||||
if (req.path == "/configuration.json") {
|
||||
if (req.method == "GET") { serveConfig(c); c.flush(); return; }
|
||||
if (req.method == "POST") { handleConfigPost(c, req); return; } // reboots on success
|
||||
sendText(c, 405, "Method Not Allowed", "text/plain", "GET or POST");
|
||||
c.flush();
|
||||
return;
|
||||
}
|
||||
if (req.path == "/action") { // POST /action?type=send-beacon | send-rf-beacon | send-message | reboot
|
||||
if (req.method != "POST") { // POST only, as on ESP32 (web_utils.cpp)
|
||||
sendText(c, 405, "Method Not Allowed", "text/plain", "POST only");
|
||||
c.flush();
|
||||
return;
|
||||
}
|
||||
if (req.query.indexOf("send-message") >= 0) {
|
||||
String to = getQueryParam(req.query, "to");
|
||||
String text = getQueryParam(req.query, "text");
|
||||
bool viaRF = req.query.indexOf("rf=1") >= 0;
|
||||
bool viaTCP = req.query.indexOf("tcp=1") >= 0;
|
||||
if (!viaRF && !viaTCP) viaRF = true; // default to RF if unspecified
|
||||
if (to.length() == 0 || text.length() == 0) {
|
||||
sendText(c, 400, "Bad Request", "text/plain", "need to= and text=");
|
||||
} else {
|
||||
bool sentRF, sentTCP;
|
||||
webSendMessage(to, text, viaRF, viaTCP, sentRF, sentTCP);
|
||||
// tell the page which copies really went out (it shows this text)
|
||||
String sent, failed;
|
||||
if (sentRF) sent = "RF";
|
||||
if (sentTCP) sent += sent.length() ? " + APRS-IS" : "APRS-IS";
|
||||
if (viaRF && !sentRF) failed = "RF (TX queue full)";
|
||||
if (viaTCP && !sentTCP) failed += failed.length() ? ", APRS-IS (not connected)" : "APRS-IS (not connected)";
|
||||
String reply = sent.length() ? String("queued (") + sent + ")" : String("not sent");
|
||||
if (failed.length()) reply += String(sent.length() ? "; not sent: " : ": ") + failed;
|
||||
if (sent.length()) sendText(c, 200, "OK", "text/plain", reply);
|
||||
else sendText(c, 503, "Service Unavailable", "text/plain", reply);
|
||||
}
|
||||
} else if (req.query.indexOf("send-rf-beacon") >= 0) {
|
||||
g_rfBeaconNow = true;
|
||||
sendText(c, 200, "OK", "text/plain", "rf beacon queued");
|
||||
} else if (req.query.indexOf("send-beacon") >= 0) {
|
||||
g_beaconNow = true;
|
||||
sendText(c, 200, "OK", "text/plain", "beacon queued");
|
||||
} else if (req.query.indexOf("reboot") >= 0) {
|
||||
sendText(c, 200, "OK", "text/plain", "rebooting");
|
||||
c.flush();
|
||||
delay(300);
|
||||
rp2040.restart();
|
||||
} else {
|
||||
sendText(c, 404, "Not Found", "text/plain", "unknown action");
|
||||
}
|
||||
c.flush();
|
||||
return;
|
||||
}
|
||||
if (req.method == "GET") { // static SPA assets
|
||||
for (size_t i = 0; i < WEB_ASSETS_N; i++) {
|
||||
if (req.path == WEB_ASSETS[i].path) {
|
||||
serveAsset(c, WEB_ASSETS[i], req.ifNoneMatch);
|
||||
c.flush();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
sendText(c, 404, "Not Found", "text/plain", "not found");
|
||||
c.flush();
|
||||
}
|
||||
|
||||
void ethWebSetup() {
|
||||
if (webStarted) return;
|
||||
LittleFS.begin();
|
||||
webServer.begin();
|
||||
webStarted = true;
|
||||
Serial.println("[web] HTTP config server on :80 (/status, /configuration.json)");
|
||||
}
|
||||
|
||||
void ethWebPoll() {
|
||||
if (!webStarted) return;
|
||||
EthernetClient client = webServer.accept();
|
||||
if (client) {
|
||||
handleClient(client);
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
// Minimal HTTP config server for the RP2350 iGate port, over the W5500
|
||||
// (arduino-libraries/Ethernet). Adapted from the Meshtastic fork's mesh/eth
|
||||
// transport (request parsing / response helpers), without the PhoneAPI
|
||||
// / protobuf / OSThread coupling. Plain EthernetClient, served from a FreeRTOS
|
||||
// task. Routes: GET /status, GET /configuration.json (more added incrementally).
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
void ethWebSetup(); // bind EthernetServer on :80 + mount LittleFS
|
||||
void ethWebPoll(); // accept + handle one pending client (call from the net task loop)
|
||||
|
||||
// Record an incoming APRS message addressed to us (served at GET /messages.json).
|
||||
// `via` is "RF" or "IS". Call from the net task only (store is netTask-owned).
|
||||
void ethWebAddMessage(const String &from, const String &text, const String &via);
|
||||
|
||||
// Record a received LoRa packet for GET /received-packets.json (net task only).
|
||||
void ethWebAddPacket(const String &frame, int rssi, float snr);
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* RP2350 GPS reader (UART1 / Serial2 -> TinyGPS++). Ported from the ESP32
|
||||
* gps_utils.cpp (excluded from the RP2350 build_src_filter). The UART is opened
|
||||
* whenever the firmware is built with -D HAS_GPS so the fix can be observed on
|
||||
* the serial log for bring-up; the beacon only *uses* the GPS position when
|
||||
* Config.beacon.gpsActive is set (see beacon_rp2350.cpp encodedPosition()).
|
||||
*
|
||||
* poll() runs in netTask and updates a plain snapshot; the beacon builders read
|
||||
* that snapshot (from netTask and loraTask). Only scalar reads cross tasks, so a
|
||||
* momentarily torn value is harmless (a slightly stale beacon position).
|
||||
*/
|
||||
#include "gps_rp2350.h"
|
||||
#include "configuration.h"
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
#ifdef HAS_GPS
|
||||
#include <TinyGPS++.h>
|
||||
|
||||
#ifndef GPS_BAUDRATE
|
||||
#define GPS_BAUDRATE 9600 // most NMEA modules (incl. the DL20U9A) default here
|
||||
#endif
|
||||
#ifndef PIN_GPS_TX
|
||||
#define PIN_GPS_TX 8 // RP2350 UART1 TX (GP08) -> GPS RX
|
||||
#endif
|
||||
#ifndef PIN_GPS_RX
|
||||
#define PIN_GPS_RX 9 // RP2350 UART1 RX (GP09) <- GPS TX
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
TinyGPSPlus tinyGps;
|
||||
bool started = false;
|
||||
struct {
|
||||
bool valid = false;
|
||||
double lat = 0.0;
|
||||
double lng = 0.0;
|
||||
double alt = NAN;
|
||||
uint32_t sats = 0;
|
||||
} fix;
|
||||
}
|
||||
#endif // HAS_GPS
|
||||
|
||||
namespace Gps {
|
||||
|
||||
void setup() {
|
||||
#ifdef HAS_GPS
|
||||
Serial2.setTX(PIN_GPS_TX);
|
||||
Serial2.setRX(PIN_GPS_RX);
|
||||
// Enlarge the RX ring buffer: poll() only drains the UART when the net loop
|
||||
// runs, so a brief stall (web request, APRS-IS reconnect) would overflow the
|
||||
// 32-byte default and corrupt NMEA sentences. 256 B covers a full 1 Hz burst.
|
||||
Serial2.setFIFOSize(256);
|
||||
Serial2.begin(GPS_BAUDRATE);
|
||||
started = true;
|
||||
Serial.printf("[gps] UART1 @%d baud (TX=GP%d RX=GP%d), gpsActive=%d\n",
|
||||
GPS_BAUDRATE, PIN_GPS_TX, PIN_GPS_RX, (int)Config.beacon.gpsActive);
|
||||
#endif
|
||||
}
|
||||
|
||||
void poll() {
|
||||
#ifdef HAS_GPS
|
||||
if (!started) return;
|
||||
while (Serial2.available() > 0) tinyGps.encode(Serial2.read());
|
||||
|
||||
if (tinyGps.location.isValid() &&
|
||||
tinyGps.location.lat() != 0.0 && tinyGps.location.lng() != 0.0) {
|
||||
fix.valid = true;
|
||||
fix.lat = tinyGps.location.lat();
|
||||
fix.lng = tinyGps.location.lng();
|
||||
fix.alt = tinyGps.altitude.isValid() ? tinyGps.altitude.meters() : NAN;
|
||||
fix.sats = tinyGps.satellites.isValid() ? tinyGps.satellites.value() : 0;
|
||||
}
|
||||
|
||||
#ifdef GPS_DEBUG
|
||||
// Bring-up diagnostic (opt-in, -D GPS_DEBUG): charsProcessed()==0 means no
|
||||
// NMEA is arriving (wiring or baud); otherwise shows fix progress (sats climb,
|
||||
// then a valid position). Off in release images to keep the serial log clean.
|
||||
static uint32_t lastLog = 0;
|
||||
if (millis() - lastLog > 15000) {
|
||||
lastLog = millis();
|
||||
Serial.printf("[gps] chars=%lu csum-ok=%lu csum-fail=%lu sats=%d fix=%d lat=%.5f lng=%.5f alt=%.0f\n",
|
||||
(unsigned long)tinyGps.charsProcessed(),
|
||||
(unsigned long)tinyGps.passedChecksum(),
|
||||
(unsigned long)tinyGps.failedChecksum(),
|
||||
tinyGps.satellites.isValid() ? (int)tinyGps.satellites.value() : 0,
|
||||
(int)fix.valid, fix.lat, fix.lng, fix.alt);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool hasFix() {
|
||||
#ifdef HAS_GPS
|
||||
return started && fix.valid;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
double lat() {
|
||||
#ifdef HAS_GPS
|
||||
return fix.lat;
|
||||
#else
|
||||
return 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
double lng() {
|
||||
#ifdef HAS_GPS
|
||||
return fix.lng;
|
||||
#else
|
||||
return 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
double altMeters() {
|
||||
#ifdef HAS_GPS
|
||||
return fix.alt;
|
||||
#else
|
||||
return NAN;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t satellites() {
|
||||
#ifdef HAS_GPS
|
||||
return fix.sats;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Gps
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// GPS reader for the RP2350 iGate port: hardware UART (UART1 / Serial2) parsed
|
||||
// with TinyGPS++. Compiles to no-ops unless built with -D HAS_GPS. When
|
||||
// Config.beacon.gpsActive is set and a valid fix is present, the beacon uses the
|
||||
// live GPS position (see beacon_rp2350.cpp) instead of the fixed config position.
|
||||
namespace Gps {
|
||||
void setup(); // begin the UART (HAS_GPS only); call from setup()
|
||||
void poll(); // feed available UART bytes to TinyGPS++; call each net loop
|
||||
bool hasFix(); // true when a valid, non-zero position fix is available
|
||||
double lat(); // last valid latitude (0 if no fix)
|
||||
double lng(); // last valid longitude (0 if no fix)
|
||||
double altMeters(); // last valid altitude in metres (NAN if unknown)
|
||||
uint32_t satellites(); // satellites in use (0 if unknown)
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* RP2350 implementation of the LoRa_Utils API (include/lora_utils.h), reusing
|
||||
* the validated E22P / SX1262 radio bring-up (SPI1, DIO2-as-RF-switch, TCXO).
|
||||
* Replaces the ESP32-centric src/lora_utils.cpp (excluded from the RP2350
|
||||
* build_src_filter). LoRa-APRS framing: on-air packets are prefixed with the
|
||||
* 3 bytes '<' 0xFF 0x01 (OE5BPA standard).
|
||||
*/
|
||||
#include "lora_utils.h"
|
||||
#include <RadioLib.h>
|
||||
#include <SPI.h>
|
||||
#include "configuration.h"
|
||||
#include "board_pinout.h"
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
// The same E22 / E22P footprint takes a 433 MHz (SX1268) or an 868/915 MHz (SX1262)
|
||||
// module, and the version string the die reports varies by batch (an E22-400M30S
|
||||
// here reports "SX1262", an E22P-433M30S "SX1268"). RadioLib's begin() rejects a
|
||||
// mismatch with RADIOLIB_ERR_CHIP_NOT_FOUND, so setup() tries one class and falls
|
||||
// back to the other. Both share the SX126x command set: everything else goes
|
||||
// through `radio`.
|
||||
static SX1262 radio1262 = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN, SPI1);
|
||||
static SX1268 radio1268 = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN, SPI1);
|
||||
static SX126x* radio = &radio1262;
|
||||
static volatile bool rxFlag = false;
|
||||
|
||||
// How often to warm-reset the SX126x analog frontend / AGC state (see resetAGC).
|
||||
// Ported from upstream PR #440 (ndoo / Andrew Yong), itself from Meshtastic.
|
||||
#define AGC_RESET_INTERVAL_MS 60000
|
||||
|
||||
// Signal stats of the last received packet (read by the ?APRSSR query; the
|
||||
// original firmware keeps these as globals, so the query module externs them).
|
||||
int rssi = 0;
|
||||
float snr = 0;
|
||||
int freqError = 0;
|
||||
static float rxFreqMHz = 433.775f;
|
||||
static float txFreqMHz = 433.775f;
|
||||
|
||||
static void onLoraDio1() { rxFlag = true; }
|
||||
|
||||
#define CHIP_MIN_POWER -9 // SX1262 / SX1268
|
||||
#define CHIP_MAX_POWER 22
|
||||
|
||||
// The E22(P)-xxxM30S carries its own 30 dBm PA; driving the SX126x above 20 dBm
|
||||
// overdrives it -> ~690 mA current spike -> supply brownout that wedges the
|
||||
// module in a low-sensitivity state until a physical power cycle (verified on
|
||||
// the .243 W5100S: power=22 went deaf, cold-boot recovered ~10 dB). Cap the
|
||||
// SX126x drive at 20 dBm — no useful range is gained above it on this front-end.
|
||||
#ifndef RADIO_MAX_POWER
|
||||
#define RADIO_MAX_POWER 20
|
||||
#endif
|
||||
|
||||
namespace LoRa_Utils {
|
||||
|
||||
int validPower(int requested) {
|
||||
const int maxPower = (RADIO_MAX_POWER < CHIP_MAX_POWER) ? RADIO_MAX_POWER : CHIP_MAX_POWER;
|
||||
return constrain(requested, CHIP_MIN_POWER, maxPower);
|
||||
}
|
||||
|
||||
// Undocumented Heltec/Semtech-recommended SX126x register patch (bit 0 of 0x8B5)
|
||||
// that measurably reduces packet loss. Needs RADIOLIB_LOW_LEVEL=1 for getMod().
|
||||
// Calibrate(0x7F) clears it, so resetAGC() re-applies it after every calibration.
|
||||
static void applyRxSensitivityPatch() {
|
||||
if (radio->getMod()->SPIsetRegValue(0x8B5, 0x01, 0, 0) == RADIOLIB_ERR_NONE)
|
||||
Serial.println("[lora] applied SX126x 0x8B5 RX-sensitivity patch");
|
||||
else
|
||||
Serial.println("[lora] FAILED to apply SX126x 0x8B5 RX-sensitivity patch");
|
||||
}
|
||||
|
||||
// SX126x has no true AGC; the frontend gain can get stuck low after prolonged RX.
|
||||
// Periodically warm-reset it (warm sleep + full calibration), skipping if a packet
|
||||
// is actively arriving. Called from receivePacket() only (loraTask owns SPI1).
|
||||
static void resetAGC() {
|
||||
uint32_t irqFlags = radio->getIrqFlags();
|
||||
if (irqFlags & (RADIOLIB_SX126X_IRQ_HEADER_VALID | RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED))
|
||||
return; // packet actively arriving, don't disturb it
|
||||
|
||||
radio->sleep(true); // warm sleep - resets the analog frontend / AGC state
|
||||
radio->standby(RADIOLIB_SX126X_STANDBY_RC, true); // wake to RC standby for stable calibration
|
||||
|
||||
uint8_t calData = RADIOLIB_SX126X_CALIBRATE_ALL;
|
||||
radio->getMod()->SPIwriteStream(RADIOLIB_SX126X_CMD_CALIBRATE, &calData, 1, true, false);
|
||||
|
||||
radio->getMod()->hal->delay(5);
|
||||
uint32_t calibrationStart = millis();
|
||||
while (radio->getMod()->hal->digitalRead(radio->getMod()->getGpio())) {
|
||||
if (millis() - calibrationStart > 50) {
|
||||
Serial.println("[lora] SX126x AGC reset: calibration did not complete within 50ms");
|
||||
break;
|
||||
}
|
||||
radio->getMod()->hal->yield();
|
||||
}
|
||||
|
||||
float freq = (float)Config.loramodule.rxFreq / 1000000;
|
||||
radio->calibrateImage(freq); // Calibrate(0x7F) defaults image cal to the wrong band otherwise
|
||||
|
||||
radio->setRxBoostedGainMode(true); // re-apply settings that Calibrate(0x7F) resets
|
||||
applyRxSensitivityPatch();
|
||||
|
||||
radio->startReceive();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// RF front-end control depends on how TXEN is wired (see board_pinout.h):
|
||||
// RADIO_TXEN >= 0 -> canonical E22-400M30S / E22P-433M30S design (datasheet
|
||||
// §4.1/§5.2): TXEN and RXEN are separate MCU-driven lines,
|
||||
// DIO2 floating. RadioLib toggles both switch pins around
|
||||
// every RX/TX transition (LNA off in TX, PA off in RX).
|
||||
// RADIO_TXEN < 0 -> bridged front-end (DIO2->TXEN): a single RFEN (RXEN)
|
||||
// line held HIGH, dropped by hand during transmit. The
|
||||
// default on the boards, whose DIO2-TXEN jumper ships fitted.
|
||||
#if RADIO_TXEN < 0
|
||||
pinMode(RADIO_RXEN, OUTPUT);
|
||||
digitalWrite(RADIO_RXEN, HIGH); // bridged: RFEN held HIGH while active
|
||||
#endif
|
||||
SPI1.setSCK(RADIO_SCLK_PIN);
|
||||
SPI1.setTX(RADIO_MOSI_PIN);
|
||||
SPI1.setRX(RADIO_MISO_PIN);
|
||||
SPI1.begin(false);
|
||||
|
||||
// Deliberate E22 reset with the RF front-end held OFF (PA + LNA), so a *software*
|
||||
// reboot (config save -> rp2040.restart, which does NOT power-cycle the module)
|
||||
// recovers a module left in a bad state instead of needing a physical power
|
||||
// cycle. RadioLib's begin() also resets, but a longer, front-end-safe pulse here
|
||||
// is more reliable after a glitchy restart.
|
||||
#if RADIO_TXEN >= 0
|
||||
pinMode(RADIO_TXEN, OUTPUT); digitalWrite(RADIO_TXEN, LOW); // PA off during reset
|
||||
pinMode(RADIO_RXEN, OUTPUT); digitalWrite(RADIO_RXEN, LOW); // LNA off during reset
|
||||
#endif
|
||||
pinMode(RADIO_RST_PIN, OUTPUT);
|
||||
digitalWrite(RADIO_RST_PIN, LOW); delay(5);
|
||||
digitalWrite(RADIO_RST_PIN, HIGH); delay(5);
|
||||
|
||||
#ifdef LORA_DIAG
|
||||
Serial.println("[diag] ==== LoRa bring-up diagnostic ====");
|
||||
// Low-level reach-the-chip probe (separates "dead/stuck chip" from "bad MISO/SPI").
|
||||
pinMode(RADIO_BUSY_PIN, INPUT);
|
||||
pinMode(RADIO_RST_PIN, OUTPUT);
|
||||
pinMode(RADIO_CS_PIN, OUTPUT);
|
||||
digitalWrite(RADIO_CS_PIN, HIGH);
|
||||
Serial.printf("[diag] pins CS=%d SCK=%d MOSI=%d MISO=%d RST=%d BUSY=%d DIO1=%d\n", RADIO_CS_PIN,
|
||||
RADIO_SCLK_PIN, RADIO_MOSI_PIN, RADIO_MISO_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN, RADIO_DIO1_PIN);
|
||||
Serial.printf("[diag] BUSY before reset = %d\n", digitalRead(RADIO_BUSY_PIN));
|
||||
digitalWrite(RADIO_RST_PIN, LOW);
|
||||
delay(2);
|
||||
Serial.printf("[diag] BUSY while NRST low = %d\n", digitalRead(RADIO_BUSY_PIN));
|
||||
digitalWrite(RADIO_RST_PIN, HIGH);
|
||||
delay(1);
|
||||
int bA = digitalRead(RADIO_BUSY_PIN);
|
||||
delay(10);
|
||||
int bB = digitalRead(RADIO_BUSY_PIN);
|
||||
// A live SX126x pulses BUSY high during boot then drops it LOW (ready) ~1-2 ms
|
||||
// after NRST is released. BUSY stuck HIGH => chip not running (dead/power/clock).
|
||||
Serial.printf("[diag] BUSY after reset: +1ms=%d +11ms=%d (expect ->0 if chip alive)\n", bA, bB);
|
||||
// Raw GetStatus (opcode 0xC0): clock out the status byte. 0x00 or 0xFF on MISO
|
||||
// = no chip / dead MISO path; anything else = SPI link to the die is alive.
|
||||
SPI1.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
|
||||
digitalWrite(RADIO_CS_PIN, LOW);
|
||||
uint8_t op = SPI1.transfer(0xC0);
|
||||
uint8_t stbyte = SPI1.transfer(0x00);
|
||||
digitalWrite(RADIO_CS_PIN, HIGH);
|
||||
SPI1.endTransaction();
|
||||
Serial.printf("[diag] SX126x GetStatus raw: op=%02X status=%02X (00/FF = mudo)\n", op, stbyte);
|
||||
// Version string (REG 0x0320, 16 bytes). RadioLib findChip() strncmp's the
|
||||
// first 6 chars vs the class name -> a "SX1262" here is why the SX1268 class
|
||||
// rejected this E22-400M30S with -2.
|
||||
{
|
||||
uint8_t ver[17] = {0};
|
||||
SPI1.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
|
||||
digitalWrite(RADIO_CS_PIN, LOW);
|
||||
SPI1.transfer(0x1D); // ReadRegister opcode
|
||||
SPI1.transfer(0x03); // addr hi (0x0320)
|
||||
SPI1.transfer(0x20); // addr lo
|
||||
SPI1.transfer(0x00); // status NOP
|
||||
for (int k = 0; k < 16; k++) ver[k] = SPI1.transfer(0x00);
|
||||
digitalWrite(RADIO_CS_PIN, HIGH);
|
||||
SPI1.endTransaction();
|
||||
Serial.printf("[diag] chip version string = '%s'\n", (char *)ver);
|
||||
}
|
||||
#endif
|
||||
|
||||
rxFreqMHz = (float)Config.loramodule.rxFreq / 1000000.0f;
|
||||
txFreqMHz = (float)Config.loramodule.txFreq / 1000000.0f;
|
||||
float bw = (float)Config.loramodule.rxSignalBandwidth / 1000.0f;
|
||||
|
||||
int power = validPower(Config.loramodule.power);
|
||||
if (power != Config.loramodule.power)
|
||||
Serial.printf("[lora] power adjusted: %d -> %d dBm\n", Config.loramodule.power, power);
|
||||
|
||||
auto begin = [&](auto& chip, bool useLDO) {
|
||||
return chip.begin(rxFreqMHz, bw, Config.loramodule.rxSpreadingFactor,
|
||||
Config.loramodule.rxCodingRate4, 0x12, power,
|
||||
8, SX126X_DIO3_TCXO_VOLTAGE, useLDO);
|
||||
};
|
||||
radio = &radio1262;
|
||||
int st = begin(radio1262, false);
|
||||
if (st == RADIOLIB_ERR_CHIP_NOT_FOUND) { // die reports itself as SX1268
|
||||
radio = &radio1268;
|
||||
st = begin(radio1268, false);
|
||||
}
|
||||
if (st != RADIOLIB_ERR_NONE) { // some E22 modules need the LDO regulator
|
||||
Serial.printf("[lora] begin %d -> retry LDO\n", st);
|
||||
st = (radio == &radio1268) ? begin(radio1268, true) : begin(radio1262, true);
|
||||
}
|
||||
#if RADIO_TXEN < 0
|
||||
radio->setDio2AsRfSwitch(true); // bridged: DIO2 -> TXEN on-module (DIO2 wired)
|
||||
#else
|
||||
// Canonical front-end: DIO2 is left floating; RadioLib drives the external
|
||||
// TXEN/RXEN switch pins itself (mutually exclusive) on every RX/TX transition.
|
||||
radio->setRfSwitchPins(RADIO_RXEN, RADIO_TXEN);
|
||||
#endif
|
||||
radio->setRxBoostedGainMode(true); // boosted LNA gain (higher RX sensitivity)
|
||||
applyRxSensitivityPatch(); // undocumented 0x8B5 RX patch (upstream PR #440)
|
||||
radio->setDio1Action(onLoraDio1);
|
||||
radio->startReceive();
|
||||
Serial.printf("[lora] %s %s @%.4f MHz SF%d BW%.0f CR4:%d (state %d)\n",
|
||||
radio == &radio1268 ? "SX1268" : "SX1262",
|
||||
st == RADIOLIB_ERR_NONE ? "RX listening" : "FAILED", rxFreqMHz,
|
||||
Config.loramodule.rxSpreadingFactor, bw, Config.loramodule.rxCodingRate4, st);
|
||||
}
|
||||
|
||||
String receivePacket() {
|
||||
// Periodic AGC warm-reset (upstream PR #440). Only when no packet is pending —
|
||||
// resetAGC() sleeps/calibrates the radio, which would drop an already-received
|
||||
// (RxDone) packet waiting in the FIFO. It also bails internally if one is
|
||||
// mid-arrival (HEADER_VALID / PREAMBLE_DETECTED).
|
||||
#ifdef LORA_RX_POLL
|
||||
bool rxPending = radio->getIrqFlags() & RADIOLIB_SX126X_IRQ_RX_DONE;
|
||||
#else
|
||||
bool rxPending = rxFlag;
|
||||
#endif
|
||||
static uint32_t lastAgcResetTime = 0;
|
||||
if (!rxPending && millis() - lastAgcResetTime > AGC_RESET_INTERVAL_MS) {
|
||||
resetAGC();
|
||||
lastAgcResetTime = millis();
|
||||
}
|
||||
|
||||
#ifdef LORA_RX_POLL
|
||||
// Optional fallback for a carrier that genuinely doesn't route the SX126x
|
||||
// DIO1 RxDone interrupt to the MCU: poll the IRQ register over SPI instead of
|
||||
// relying on the DIO1 interrupt / rxFlag. Not needed on the current boards —
|
||||
// the W5100S carrier was verified (isr fires on TxDone and RxDone, GP14 goes
|
||||
// high) to deliver the DIO1 IRQ once the DIO2->TXEN bridge was cut and the
|
||||
// canonical RF switch (setRfSwitchPins) is used.
|
||||
if (!(radio->getIrqFlags() & RADIOLIB_SX126X_IRQ_RX_DONE)) return "";
|
||||
#else
|
||||
if (!rxFlag) return "";
|
||||
#endif
|
||||
rxFlag = false;
|
||||
String str;
|
||||
int st = radio->readData(str);
|
||||
rssi = (int)radio->getRSSI();
|
||||
snr = radio->getSNR();
|
||||
freqError = (int)radio->getFrequencyError();
|
||||
radio->startReceive(); // re-arm
|
||||
if (st != RADIOLIB_ERR_NONE) return "";
|
||||
// Return the RAW packet WITH its 3-byte LoRa-APRS header ('<' 0xFF 0x01) —
|
||||
// the iGate processing (gate + digi) does packet.substring(3) to skip it.
|
||||
return str;
|
||||
}
|
||||
|
||||
String receivePacketFromSleep() { return receivePacket(); }
|
||||
|
||||
void changeFreqTx() { radio->standby(); radio->setFrequency(txFreqMHz); }
|
||||
void changeFreqRx() { radio->standby(); radio->setFrequency(rxFreqMHz); radio->startReceive(); }
|
||||
|
||||
// --- CAD / DIFS / BEB (port of the channel access in src/lora_utils.cpp) --------
|
||||
// Listen before transmitting: DIFS = N consecutive free CAD slots, then a binary
|
||||
// exponential backoff of free slots. Enabled per config (LoRa -> "Channel Activity
|
||||
// Detection"). Bounded like upstream (V4.0.2): after CAD_MAX_WAIT_MS of busy
|
||||
// channel the packet is dropped, so loraTask (which also services RX and the TX
|
||||
// buffer) never blocks forever on a permanently busy channel.
|
||||
#define DIFS_SLOTS 2
|
||||
#define CAD_MAX_WAIT_MS 10000
|
||||
|
||||
static const int CAD_BACKOFF_MAX = 4;
|
||||
static uint32_t cadStartTime = 0;
|
||||
|
||||
static bool doCAD() { return radio->scanChannel() != RADIOLIB_CHANNEL_FREE; } // true = busy
|
||||
|
||||
static bool doDIFS() {
|
||||
for (uint8_t i = DIFS_SLOTS; i > 0; i--) {
|
||||
if (doCAD()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cadTimedOut() { return millis() - cadStartTime > CAD_MAX_WAIT_MS; }
|
||||
|
||||
static void waitForDIFS() {
|
||||
while (!doDIFS()) {
|
||||
if (cadTimedOut()) return;
|
||||
}
|
||||
}
|
||||
|
||||
static void doBEB() {
|
||||
int backoff = random(1, CAD_BACKOFF_MAX + 1);
|
||||
while (backoff > 0) {
|
||||
if (cadTimedOut()) return;
|
||||
if (doCAD()) {
|
||||
waitForDIFS(); // busy channel: freeze backoff and restart DIFS
|
||||
} else {
|
||||
backoff--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sendNewPacket(const String& newPacket) {
|
||||
if (!Config.loramodule.txActive) return; // RF TX disabled (RX-only iGate / ?TX=OFF)
|
||||
changeFreqTx();
|
||||
if (Config.loramodule.cadActive) { // listen before transmit
|
||||
cadStartTime = millis();
|
||||
waitForDIFS();
|
||||
doBEB();
|
||||
if (cadTimedOut()) {
|
||||
Serial.println("[lora] CAD timeout, packet dropped: " + newPacket);
|
||||
changeFreqRx();
|
||||
rxFlag = false; // DIO1 also fires on CAD done: don't read that back as RX
|
||||
return;
|
||||
}
|
||||
}
|
||||
#if RADIO_TXEN < 0
|
||||
digitalWrite(RADIO_RXEN, LOW); // bridged: RX path off; DIO2 drives TXEN during transmit
|
||||
#endif
|
||||
String tx;
|
||||
tx.reserve(newPacket.length() + 3);
|
||||
tx += '<';
|
||||
tx += (char)0xFF;
|
||||
tx += (char)0x01;
|
||||
tx += newPacket;
|
||||
int st = radio->transmit(tx);
|
||||
Serial.printf("[lora] TX %d B (state %d)\n", (int)tx.length(), st);
|
||||
#if RADIO_TXEN < 0
|
||||
digitalWrite(RADIO_RXEN, HIGH); // bridged: restore RX path
|
||||
#endif
|
||||
changeFreqRx();
|
||||
// DIO1 fires on TxDone as well as RxDone, so transmit() just set rxFlag.
|
||||
// Clear it (after re-arming RX) so the next receivePacket() doesn't read the
|
||||
// stale TX FIFO back as a bogus "received" packet (self-RX -> duplicate gate).
|
||||
rxFlag = false;
|
||||
}
|
||||
|
||||
void wakeRadio() { radio->standby(); radio->startReceive(); }
|
||||
void sleepRadio() { radio->sleep(); }
|
||||
|
||||
} // namespace LoRa_Utils
|
||||
@@ -0,0 +1,388 @@
|
||||
/*
|
||||
* LoRa APRS iGate — RP2350 (WIZnet W5500-EVB-Pico2 + E22).
|
||||
* Core path: receive LoRa-APRS packets (SPI1, LoRa_Utils) and forward them to
|
||||
* APRS-IS over Ethernet (W5500/SPI0, AprsIs), plus the web config server.
|
||||
*
|
||||
* Concurrency (FreeRTOS SMP):
|
||||
* - loraTask : owns the radio (SPI1); RX packets -> rxQueue.
|
||||
* - netTask : owns the W5500 (SPI0); DHCP + web server + APRS-IS connect/
|
||||
* poll/forward. ALL Ethernet/W5500 access lives here (no race).
|
||||
* - loop() : LED heartbeat + status line.
|
||||
* The two SPI buses are separate, so radio and network run truly in parallel.
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <queue.h>
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include "configuration.h"
|
||||
#include "board_pinout.h" // PIN_ETH_* (W5500 / W5100S on SPI0)
|
||||
#include "lora_utils.h"
|
||||
#include "eth_web.h"
|
||||
#include "aprsis_rp2350.h"
|
||||
#include "beacon_rp2350.h"
|
||||
#include "wx_rp2350.h"
|
||||
#include "digi_rp2350.h"
|
||||
#include "station_rp2350.h"
|
||||
#include "query_rp2350.h"
|
||||
#include "message_rp2350.h"
|
||||
#include "tnc_rp2350.h"
|
||||
#include "telemetry_rp2350.h"
|
||||
#include "ntp_rp2350.h"
|
||||
#include "mqtt_rp2350.h"
|
||||
#include "syslog_rp2350.h"
|
||||
#include "battery_rp2350.h"
|
||||
#include "gps_rp2350.h"
|
||||
#include "map_utils.h" // stations map behind the web "Map" view (/stations.json)
|
||||
#include <APRSPacketLib.h>
|
||||
#include "pico/unique_id.h" // pico_get_unique_board_id (cached at boot — SMP-safe)
|
||||
|
||||
#ifndef HB_LED
|
||||
#define HB_LED 25 // onboard LED (GP25 on the WIZnet W5500-EVB-Pico2)
|
||||
#endif
|
||||
|
||||
// Firmware build timestamp — shown in the boot banner and served at GET /status
|
||||
// (lets you confirm which build is running, e.g. after an OTA).
|
||||
const char *FW_BUILD = __DATE__ " " __TIME__;
|
||||
|
||||
// Global iGate config instance (lives in LoRa_APRS_iGate.cpp on ESP32, excluded
|
||||
// from the RP2350 build; the modules extern it).
|
||||
Configuration Config;
|
||||
|
||||
static byte mac[6];
|
||||
static QueueHandle_t rxQueue; // heap String* handoff: loraTask -> netTask
|
||||
static QueueHandle_t txMsgQueue; // heap String* handoff: netTask -> loraTask (outgoing msgs)
|
||||
static QueueHandle_t rxMsgQueue; // heap String* handoff: loraTask -> netTask (incoming msgs for us)
|
||||
static QueueHandle_t rxPktQueue; // heap String* handoff: loraTask -> netTask (RX packets log)
|
||||
|
||||
// Signal stats of the last RX (set in lora_utils_rp2350.cpp's receivePacket()).
|
||||
extern int rssi;
|
||||
extern float snr;
|
||||
volatile bool g_beaconNow = false; // set by POST /action?type=send-beacon (eth_web)
|
||||
volatile bool g_rfBeaconNow = false; // set by POST /action?type=send-rf-beacon (eth_web)
|
||||
// Backup digi running (RP2350 counterpart of the ESP32 runtime backupDigiMode):
|
||||
// written by netTask, read by loraTask and the digi.
|
||||
volatile bool g_backupDigi = false;
|
||||
|
||||
// Called from netTask (eth_web /action handler) to originate an APRS message.
|
||||
// We build here (Config is read-only) and hand the packet to loraTask, the sole
|
||||
// owner of the Station output buffer (no cross-task race on outBuffer).
|
||||
// Called from netTask (eth_web /action). RF goes via the queue to loraTask; the
|
||||
// APRS-IS copy is sent right here (netTask owns the socket). sentRF / sentTCP say
|
||||
// which copies actually went out, for the reply to the web page.
|
||||
void webSendMessage(const String &to, const String &text, bool viaRF, bool viaTCP,
|
||||
bool &sentRF, bool &sentTCP) {
|
||||
sentRF = sentTCP = false;
|
||||
if (viaRF) {
|
||||
String pkt = Message::buildRF(to, text);
|
||||
if (pkt.length()) {
|
||||
String *p = new String(pkt);
|
||||
if (xQueueSend(txMsgQueue, &p, 0) == pdTRUE) sentRF = true;
|
||||
else delete p;
|
||||
}
|
||||
}
|
||||
if (viaTCP && AprsIs::connected()) {
|
||||
String line = Message::buildAprsis(to, text);
|
||||
if (line.length()) {
|
||||
AprsIs::send(line);
|
||||
sentTCP = true;
|
||||
Serial.println("[msg] APRS-IS: " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Called from loraTask (Query::handleMessage) when an APRS message addressed to
|
||||
// us is received. Hand it to netTask (the W5500 owner) for the /messages.json
|
||||
// store via a queue — no cross-task race on the message list.
|
||||
void onIncomingMessage(const String &from, const String &text) {
|
||||
String *p = new String(from + "\t" + text);
|
||||
if (xQueueSend(rxMsgQueue, &p, 0) != pdTRUE) delete p;
|
||||
}
|
||||
|
||||
// Called from netTask (TNC KISS client, MQTT downlink) to transmit a frame over
|
||||
// RF. Hands it to loraTask via txMsgQueue (Station output buffer owner).
|
||||
void enqueueRfFrame(const String &frame) {
|
||||
if (frame.length() == 0) return;
|
||||
String *p = new String(frame);
|
||||
if (xQueueSend(txMsgQueue, &p, 0) != pdTRUE) delete p;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------- LoRa RX/TX task
|
||||
// Owns the radio (SPI1): transmits the RF beacon (when Config.beacon.sendViaRF or
|
||||
// while the backup digi runs, as the ESP32 does) and receives LoRa-APRS packets.
|
||||
// Both run from THIS task so the radio is never touched concurrently.
|
||||
void loraTask(void *) {
|
||||
LoRa_Utils::setup();
|
||||
uint32_t lastRfBeacon = 0;
|
||||
for (;;) {
|
||||
// --- RF beacon TX: enqueue into the anti-collision output buffer ---
|
||||
if (Config.beacon.sendViaRF || g_backupDigi) {
|
||||
bool locOk = !(Config.beacon.latitude == 0.0 && Config.beacon.longitude == 0.0);
|
||||
#ifdef HAS_GPS
|
||||
if (Config.beacon.gpsActive && Gps::hasFix()) locOk = true; // GPS fix supplies the position
|
||||
#endif
|
||||
if (locOk && (lastRfBeacon == 0 || g_rfBeaconNow ||
|
||||
(millis() - lastRfBeacon >= (uint32_t)Config.beacon.interval * 60000UL))) {
|
||||
lastRfBeacon = millis();
|
||||
g_rfBeaconNow = false;
|
||||
String rf = Beacon::buildRfLine();
|
||||
Serial.println("[beacon] RF queued: " + rf);
|
||||
Station::enqueueTx(rf, true);
|
||||
}
|
||||
}
|
||||
// --- RX ---
|
||||
String pkt = LoRa_Utils::receivePacket(); // raw packet (with 3-byte hdr), "" if none
|
||||
if (pkt.length() > 0) {
|
||||
Station::noteRx();
|
||||
String body = pkt.length() > 3 ? pkt.substring(3) : pkt; // strip LoRa-APRS header
|
||||
Serial.println("[lora] RX: " + body);
|
||||
|
||||
// log every RX packet for the web "Received packets" view (frame +
|
||||
// signal stats captured together, before policy filtering)
|
||||
String *lp = new String(String(rssi) + "\t" + String(snr, 1) + "\t" + body);
|
||||
if (xQueueSend(rxPktQueue, &lp, 0) != pdTRUE) delete lp;
|
||||
|
||||
// packet policy (shared by gate + digi): parse SENDER + payload
|
||||
int gt = body.indexOf('>');
|
||||
int colon = body.indexOf(':');
|
||||
String sender = (gt > 0) ? body.substring(0, gt) : "";
|
||||
String payload = (colon >= 0) ? body.substring(colon) : body;
|
||||
|
||||
// our own packet heard back (e.g. digipeated by another station): do
|
||||
// not gate/digi it, nor count it as a heard station (matches upstream).
|
||||
String selfCall = Config.tacticalCallsign.length() ? Config.tacticalCallsign : Config.callsign;
|
||||
bool isSelf = sender.length() && sender == selfCall;
|
||||
bool blacklisted = sender.length() && Station::isBlacklisted(sender);
|
||||
bool dup = !isSelf && sender.length() && Station::isDuplicate(sender, payload);
|
||||
if (sender.length() && !isSelf) Station::updateLastHeard(sender);
|
||||
|
||||
if (isSelf) {
|
||||
Serial.println("[lora] ignored own packet heard back: " + sender);
|
||||
} else if (blacklisted) {
|
||||
Serial.println("[lora] dropped (blacklist): " + sender);
|
||||
} else if (dup) {
|
||||
Serial.println("[lora] dropped (dup <25s): " + sender);
|
||||
} else if (sender.length() && Query::handleMessage(body, sender)) {
|
||||
// it was a query addressed to us — answered over RF, don't gate/digi
|
||||
} else {
|
||||
// gate to APRS-IS (handed to netTask, the W5500 owner)
|
||||
// "rssi\tsnr\tframe": the signal stats travel with the frame for the IS2 meta line
|
||||
String *p = new String(String(rssi) + "\t" + String(snr, 1) + "\t" + pkt);
|
||||
if (xQueueSend(rxQueue, &p, 0) != pdTRUE) delete p; // drop if full
|
||||
// digipeat: rewrite WIDEn-N and enqueue for anti-collision TX
|
||||
if (Digi::enabled()) {
|
||||
String repeat = Digi::process(pkt);
|
||||
if (repeat.length() > 0) {
|
||||
Serial.println("[digi] queued: " + repeat);
|
||||
Station::enqueueTx(repeat, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// --- outgoing messages handed over by netTask (web /action) ---
|
||||
String *m;
|
||||
while (xQueueReceive(txMsgQueue, &m, 0) == pdTRUE) {
|
||||
Serial.println("[msg] queued: " + *m);
|
||||
Station::enqueueTx(*m, false);
|
||||
delete m;
|
||||
}
|
||||
// --- pump the RF output buffer (spaces TX, backs off after RX) ---
|
||||
Station::processTxBuffer();
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- Network task
|
||||
void netTask(void *) {
|
||||
pinMode(PIN_ETH_RST, OUTPUT);
|
||||
digitalWrite(PIN_ETH_RST, LOW); vTaskDelay(pdMS_TO_TICKS(10));
|
||||
digitalWrite(PIN_ETH_RST, HIGH); vTaskDelay(pdMS_TO_TICKS(60));
|
||||
SPI.setRX(PIN_ETH_MISO);
|
||||
SPI.setSCK(PIN_ETH_SCK);
|
||||
SPI.setTX(PIN_ETH_MOSI);
|
||||
#ifdef USE_W5100S
|
||||
// The RAK13800_W5100S driver defines only the two-arg init(SPIClass&, cs);
|
||||
// pass the SPI0 port configured just above.
|
||||
Ethernet.init(SPI, PIN_ETH_CS);
|
||||
#else
|
||||
Ethernet.init(PIN_ETH_CS);
|
||||
#endif
|
||||
|
||||
// MAC derived from the chip's unique board ID (like Meshtastic's getMacAddr).
|
||||
// pico_get_unique_board_id() returns a value cached at boot by an SDK ctor
|
||||
// (single-core, before the scheduler) — it does NOT touch flash here, so it's
|
||||
// safe under FreeRTOS SMP. mac[0]=0x02 => locally administered + unicast; the
|
||||
// 4 chip bytes make two identical boards differ on the LAN (no DHCP clash).
|
||||
pico_unique_board_id_t uid;
|
||||
pico_get_unique_board_id(&uid);
|
||||
mac[0] = 0x02; mac[1] = 0x00;
|
||||
mac[2] = uid.id[4]; mac[3] = uid.id[5]; mac[4] = uid.id[6]; mac[5] = uid.id[7];
|
||||
Serial.printf("[ETH] MAC %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
if (!Config.network.dhcp) {
|
||||
// static IP — parse the strings; first DNS of the list goes to the stack
|
||||
IPAddress ip, gw, sn, dns;
|
||||
ip.fromString(Config.network.ip);
|
||||
gw.fromString(Config.network.gateway);
|
||||
sn.fromString(Config.network.subnet.length() ? Config.network.subnet : String("255.255.255.0"));
|
||||
String d = Config.network.dns; d.trim();
|
||||
int sep = d.indexOf(' '); if (sep < 0) sep = d.indexOf(',');
|
||||
dns.fromString(sep > 0 ? d.substring(0, sep) : d);
|
||||
Ethernet.begin(mac, ip, dns, gw, sn); // synchronous, no DHCP wait
|
||||
Serial.print("[ETH] static IP: "); Serial.println(Ethernet.localIP());
|
||||
} else {
|
||||
Serial.println("[ETH] DHCP...");
|
||||
if (Ethernet.begin(mac) == 0) Serial.println("[ETH] DHCP FAILED (check link/cable)");
|
||||
else { Serial.print("[ETH] IP: "); Serial.println(Ethernet.localIP()); }
|
||||
}
|
||||
|
||||
ethWebSetup();
|
||||
Tnc::setup(); // KISS TNC server on :8001 (if enabled)
|
||||
Mqtt::setup(); // MQTT bridge (if Config.mqtt.active)
|
||||
Syslog::setup(); // remote syslog (if Config.syslog.active)
|
||||
|
||||
uint32_t lastMaintain = millis();
|
||||
uint32_t lastAprsTry = 0;
|
||||
uint32_t lastHb = 0;
|
||||
uint32_t lastBeacon = 0;
|
||||
for (;;) {
|
||||
ethWebPoll();
|
||||
Gps::poll(); // feed GPS NMEA -> TinyGPS++ (HAS_GPS only)
|
||||
Tnc::poll(); // accept KISS clients + read their frames
|
||||
Ntp::poll(); // SNTP time sync (real timestamps)
|
||||
Mqtt::loop(); // MQTT (re)connect + service
|
||||
if (Config.aprs_is.active) {
|
||||
if (!AprsIs::connected() && (millis() - lastAprsTry > 10000)) {
|
||||
lastAprsTry = millis();
|
||||
AprsIs::connect();
|
||||
}
|
||||
AprsIs::poll();
|
||||
// Backup digi (WIFI_Utils::checkWiFi on ESP32): with the option ticked,
|
||||
// 30 s without a line from the server = APRS-IS down -> repeat WIDE1-1
|
||||
// and beacon over RF; back to normal as soon as the server talks again.
|
||||
bool backup = Config.digi.backupDigiMode && AprsIs::silentFor(30000);
|
||||
if (backup != g_backupDigi) {
|
||||
g_backupDigi = backup;
|
||||
const char *note = backup ? "*** APRS-IS down -> Backup Digi Mode ***"
|
||||
: "*** APRS-IS back -> Stopping Backup Digi Mode ***";
|
||||
Serial.println(note);
|
||||
Syslog::logTx(note);
|
||||
}
|
||||
// telemetry channel definitions (EQNS/UNIT/PARM) at boot + ~daily
|
||||
if (AprsIs::connected() && Telemetry::dueDefinitions()) Telemetry::sendDefinitions();
|
||||
// periodic position beacon over APRS-IS (config has sendViaAPRSIS)
|
||||
bool locOk = !(Config.beacon.latitude == 0.0 && Config.beacon.longitude == 0.0);
|
||||
#ifdef HAS_GPS
|
||||
if (Config.beacon.gpsActive && Gps::hasFix()) locOk = true; // GPS fix supplies the position
|
||||
#endif
|
||||
if (Config.beacon.sendViaAPRSIS && AprsIs::connected() && !g_backupDigi && locOk &&
|
||||
(lastBeacon == 0 || g_beaconNow ||
|
||||
(millis() - lastBeacon >= (uint32_t)Config.beacon.interval * 60000UL))) {
|
||||
lastBeacon = millis();
|
||||
g_beaconNow = false;
|
||||
String b = Beacon::buildAprsisLine();
|
||||
AprsIs::send(b);
|
||||
Serial.println("[beacon] APRS-IS: " + b);
|
||||
String t = Telemetry::dataPacket(); // classic T# telemetry packet
|
||||
AprsIs::send(t);
|
||||
Serial.println("[telemetry] " + t);
|
||||
Mqtt::publishBeacon(b); // mirror beacon to MQTT (if beaconOverMqtt)
|
||||
if (Config.syslog.logBeaconOverTCPIP) Syslog::logTx("APRSIS BEACON / " + b);
|
||||
}
|
||||
}
|
||||
// forward any LoRa packets handed over by loraTask
|
||||
String *p;
|
||||
while (xQueueReceive(rxQueue, &p, 0) == pdTRUE) {
|
||||
if (Config.aprs_is.active) {
|
||||
int t1 = p->indexOf('\t');
|
||||
int t2 = (t1 >= 0) ? p->indexOf('\t', t1 + 1) : -1;
|
||||
if (t2 > t1) AprsIs::forward(p->substring(t2 + 1), p->substring(0, t1).toInt(), p->substring(t1 + 1, t2).toFloat());
|
||||
}
|
||||
delete p;
|
||||
}
|
||||
// store any incoming messages addressed to us (for GET /messages.json)
|
||||
String *m;
|
||||
while (xQueueReceive(rxMsgQueue, &m, 0) == pdTRUE) {
|
||||
int tab = m->indexOf('\t');
|
||||
if (tab > 0) ethWebAddMessage(m->substring(0, tab), m->substring(tab + 1), "RF");
|
||||
delete m;
|
||||
}
|
||||
// store RX packets log (for GET /received-packets.json): "rssi\tsnr\tframe"
|
||||
// and forward each received frame to any connected KISS TNC clients.
|
||||
String *lp;
|
||||
while (xQueueReceive(rxPktQueue, &lp, 0) == pdTRUE) {
|
||||
int t1 = lp->indexOf('\t');
|
||||
int t2 = lp->indexOf('\t', t1 + 1);
|
||||
if (t1 > 0 && t2 > t1) {
|
||||
String frame = lp->substring(t2 + 1);
|
||||
int prssi = lp->substring(0, t1).toInt();
|
||||
float psnr = lp->substring(t1 + 1, t2).toFloat();
|
||||
ethWebAddPacket(frame, prssi, psnr);
|
||||
// feed the stations map (upstream V4 "Map" view -> GET /stations.json).
|
||||
// Decoded here, in netTask, because that task owns both the map store
|
||||
// and the web server (no cross-core access to mapStations).
|
||||
APRSPacket ap = APRSPacketLib::processReceivedPacket(frame, prssi, psnr, 0);
|
||||
if (ap.type == 0 || ap.type == 4) { // 0 = GPS position, 4 = Mic-E
|
||||
MAP_Utils::upsert(ap.sender, ap.latitude, ap.longitude, ap.path,
|
||||
ap.overlay + ap.symbol, ap.rssi, ap.snr);
|
||||
}
|
||||
Tnc::broadcast(frame);
|
||||
Mqtt::publishRx(frame);
|
||||
Syslog::logRx(frame, prssi, psnr);
|
||||
}
|
||||
delete lp;
|
||||
}
|
||||
if (millis() - lastMaintain > 5000) { Ethernet.maintain(); lastMaintain = millis(); }
|
||||
// heartbeat printed HERE (netTask owns the W5500 — no SPI race)
|
||||
if (millis() - lastHb > 3000) {
|
||||
lastHb = millis();
|
||||
IPAddress ip = Ethernet.localIP();
|
||||
String clock = Ntp::synced() ? Ntp::hms(Ntp::nowEpoch()) : "--:--:--";
|
||||
Serial.printf("[hb] up=%lus %s ip=%d.%d.%d.%d callsign=%s aprsis=%s stations=%u vsys=%.2fV\n",
|
||||
(unsigned long)(millis() / 1000), clock.c_str(), ip[0], ip[1], ip[2], ip[3],
|
||||
Config.callsign.c_str(), AprsIs::connected() ? "up" : "down",
|
||||
(unsigned)Station::activeCount(), Battery::vsys());
|
||||
}
|
||||
// scheduled auto-reboot (Config "Reboot Time", in hours of uptime)
|
||||
if (Config.rebootMode && Config.rebootModeTime > 0 &&
|
||||
millis() > (uint32_t)Config.rebootModeTime * 3600UL * 1000UL) {
|
||||
Serial.println("[reboot] scheduled reboot time reached, restarting...");
|
||||
delay(100);
|
||||
rp2040.restart();
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(15));
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------- setup
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
uint32_t t0 = millis();
|
||||
while (!Serial && (millis() - t0 < 3000)) {}
|
||||
Serial.println(String("\n=== LoRa APRS iGate — RP2350 (built ") + FW_BUILD + ") ===");
|
||||
|
||||
pinMode(HB_LED, OUTPUT);
|
||||
Config.setup(); // LittleFS + /igate_conf.json (defaults on first boot)
|
||||
if (Config.rebootMode && Config.rebootModeTime > 0)
|
||||
Serial.printf("[reboot] auto-reboot every %d h\n", Config.rebootModeTime);
|
||||
Station::setup(); // load blacklist/managers from Config
|
||||
Battery::setup(); // VSYS ADC
|
||||
Wx::setup(); // BMP280 on I2C0 (Wire) — single-threaded init here
|
||||
Gps::setup(); // GPS UART (UART1 / Serial2) — HAS_GPS only
|
||||
|
||||
rxQueue = xQueueCreate(8, sizeof(String *));
|
||||
txMsgQueue = xQueueCreate(4, sizeof(String *));
|
||||
rxMsgQueue = xQueueCreate(8, sizeof(String *));
|
||||
rxPktQueue = xQueueCreate(8, sizeof(String *));
|
||||
xTaskCreate(loraTask, "lora", 4096, nullptr, 3, nullptr);
|
||||
xTaskCreate(netTask, "net", 4096, nullptr, 2, nullptr);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// LED blink ONLY — no W5500/Ethernet access here (that lives in netTask),
|
||||
// otherwise concurrent SPI0 access corrupts both readers.
|
||||
static uint32_t tick = 0;
|
||||
digitalWrite(HB_LED, (tick++ & 1) ? HIGH : LOW); // ~2 Hz proof-of-life
|
||||
vTaskDelay(pdMS_TO_TICKS(250));
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* RP2350 APRS message originator. Builds a standard message packet addressed to
|
||||
* another station. Pure (read-only on Config); the caller enqueues the result
|
||||
* into the Station output buffer from loraTask.
|
||||
*/
|
||||
#include "message_rp2350.h"
|
||||
#include "configuration.h"
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
namespace Message {
|
||||
|
||||
static String envelope(const String& tocallPath, const String& to, const String& text) {
|
||||
String pkt = Config.callsign;
|
||||
pkt += ">APLRG1";
|
||||
pkt += tocallPath; // ",PATH" (RF) or ",TCPIP*" (APRS-IS)
|
||||
pkt += "::";
|
||||
String padded = to;
|
||||
for (int i = to.length(); i < 9; i++) padded += ' '; // APRS addressee is 9 chars
|
||||
pkt += padded;
|
||||
pkt += ':';
|
||||
pkt += text;
|
||||
return pkt;
|
||||
}
|
||||
|
||||
String buildRF(const String& to, const String& text) {
|
||||
if (to.length() == 0 || text.length() == 0) return "";
|
||||
String path = Config.beacon.path.length() ? ("," + Config.beacon.path) : "";
|
||||
return envelope(path, to, text);
|
||||
}
|
||||
|
||||
String buildAprsis(const String& to, const String& text) {
|
||||
if (to.length() == 0 || text.length() == 0) return "";
|
||||
return envelope(",TCPIP*", to, text);
|
||||
}
|
||||
|
||||
} // namespace Message
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Originate APRS text messages from the iGate. A small feature (no UI yet — first
|
||||
// driven over the web /action API for testing the query responder, later wirable
|
||||
// to the SPA). Builds a standard APRS message packet:
|
||||
// CALL>APLRG1[,path]::ADDRESSEE :text (addressee padded to 9 chars)
|
||||
// The text is sent verbatim; append a "{id" suffix if you want the recipient to
|
||||
// ack it.
|
||||
namespace Message {
|
||||
// Pure builders (read-only on Config) — safe to call from any task. Return ""
|
||||
// on empty to/text.
|
||||
// buildRF : headerless packet for Station::enqueueTx (RF; LoRa_Utils
|
||||
// prepends the 3-byte LoRa-APRS header at TX).
|
||||
// buildAprsis: line for AprsIs::send (APRS-IS over TCP, TCPIP* q-construct).
|
||||
String buildRF(const String& to, const String& text);
|
||||
String buildAprsis(const String& to, const String& text);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* RP2350 MQTT bridge — lean port of mqtt_utils (PubSubClient), WiFiClient ->
|
||||
* EthernetClient. Publishes RX packets, subscribes for an RF downlink. netTask
|
||||
* only (the W5500 owner; PubSubClient and the EthernetClient live here).
|
||||
*/
|
||||
#include "mqtt_rp2350.h"
|
||||
#include <Ethernet.h>
|
||||
#include <PubSubClient.h>
|
||||
#include "configuration.h"
|
||||
|
||||
extern Configuration Config;
|
||||
extern void enqueueRfFrame(const String &frame); // main.cpp: -> txMsgQueue -> loraTask
|
||||
|
||||
static EthernetClient mqttNet;
|
||||
static PubSubClient pubSub(mqttNet);
|
||||
static bool started = false;
|
||||
static uint32_t lastTry = 0;
|
||||
|
||||
// True if `sender` is this iGate (callsign or tactical). Used to break feedback
|
||||
// loops: our subscription "<topic>/<callsign>/#" also matches "<topic>/<callsign>"
|
||||
// (MQTT '#' includes the parent), so our own publishes echo back to us.
|
||||
static bool isOurs(const String &sender) {
|
||||
return sender == Config.callsign ||
|
||||
(Config.tacticalCallsign.length() && sender == Config.tacticalCallsign);
|
||||
}
|
||||
|
||||
// Inbound MQTT message on the subscribed topic -> transmit over RF.
|
||||
static void onMessage(char *topic, byte *payload, unsigned int len) {
|
||||
String msg;
|
||||
msg.reserve(len);
|
||||
for (unsigned int i = 0; i < len; i++) msg += (char)payload[i];
|
||||
int gt = msg.indexOf('>');
|
||||
String sender = (gt > 0) ? msg.substring(0, gt) : "";
|
||||
if (isOurs(sender)) { // our own packet echoed back by the broker — don't re-TX
|
||||
Serial.println("[mqtt] ignored own frame echoed back");
|
||||
return;
|
||||
}
|
||||
Serial.println("[mqtt] rx " + String(topic) + ": " + msg);
|
||||
enqueueRfFrame(msg);
|
||||
}
|
||||
|
||||
namespace Mqtt {
|
||||
|
||||
void setup() {
|
||||
if (!Config.mqtt.active) return;
|
||||
pubSub.setServer(Config.mqtt.server.c_str(), Config.mqtt.port);
|
||||
pubSub.setCallback(onMessage);
|
||||
started = true;
|
||||
Serial.printf("[mqtt] enabled, broker %s:%d\n", Config.mqtt.server.c_str(), Config.mqtt.port);
|
||||
}
|
||||
|
||||
static void connect() {
|
||||
if (Config.mqtt.server.isEmpty() || Config.mqtt.port <= 0) return;
|
||||
Serial.println("[mqtt] connecting...");
|
||||
bool ok = Config.mqtt.username.length()
|
||||
? pubSub.connect(Config.callsign.c_str(), Config.mqtt.username.c_str(), Config.mqtt.password.c_str())
|
||||
: pubSub.connect(Config.callsign.c_str());
|
||||
if (ok) {
|
||||
String sub = Config.mqtt.topic + "/" + Config.callsign + "/#";
|
||||
pubSub.subscribe(sub.c_str());
|
||||
Serial.println("[mqtt] connected, subscribed " + sub);
|
||||
} else {
|
||||
Serial.println("[mqtt] connect failed rc=" + String(pubSub.state()));
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (!started) return;
|
||||
if (!pubSub.connected()) {
|
||||
if (millis() - lastTry > 10000) { lastTry = millis(); connect(); }
|
||||
return;
|
||||
}
|
||||
pubSub.loop();
|
||||
}
|
||||
|
||||
void publishRx(const String &frame) {
|
||||
if (!started || !pubSub.connected()) return;
|
||||
int gt = frame.indexOf('>');
|
||||
String sender = (gt > 0) ? frame.substring(0, gt) : "unknown";
|
||||
if (isOurs(sender)) return; // don't publish our own packets (they'd echo back -> RF loop)
|
||||
String topic = Config.mqtt.topic + "/" + sender;
|
||||
pubSub.publish(topic.c_str(), frame.c_str());
|
||||
}
|
||||
|
||||
void publishBeacon(const String &line) {
|
||||
if (!started || !pubSub.connected() || !Config.mqtt.beaconOverMqtt) return;
|
||||
String topic = Config.mqtt.topic + "/" + Config.callsign;
|
||||
pubSub.publish(topic.c_str(), line.c_str());
|
||||
}
|
||||
|
||||
} // namespace Mqtt
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// MQTT bridge for the RP2350 iGate (PubSubClient over EthernetClient; replaces
|
||||
// the ESP32 mqtt_utils' WiFiClient). When Config.mqtt.active:
|
||||
// - publishes each received RF packet to "<topic>/<sender>"
|
||||
// - subscribes to "<topic>/<callsign>/#"; payloads are transmitted over RF
|
||||
// - optionally publishes our own beacon to "<topic>/<callsign>" (beaconOverMqtt)
|
||||
// netTask only (W5500 owner); RF downlink goes through enqueueRfFrame().
|
||||
namespace Mqtt {
|
||||
void setup(); // configure broker + callback if active
|
||||
void loop(); // (re)connect + pubSub.loop(); call each net loop
|
||||
void publishRx(const String &frame); // a received RF frame -> MQTT
|
||||
void publishBeacon(const String &line); // own beacon -> MQTT (if beaconOverMqtt)
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* RP2350 SNTP client over EthernetUDP (W5500). Non-blocking request/reply; keeps
|
||||
* a (baseEpoch, baseMillis) pair so nowEpoch() interpolates with millis() between
|
||||
* syncs. Local time = UTC + Config.ntp.gmtCorrection hours. netTask only.
|
||||
*
|
||||
* The UDP socket is only held from the request to the reply (or its timeout):
|
||||
* the W5100S has 4 sockets, and one kept open here for good left the web server
|
||||
* a single one, so a browser loading the page got connections refused.
|
||||
*/
|
||||
#include "ntp_rp2350.h"
|
||||
#include <Ethernet.h>
|
||||
#include <EthernetUdp.h>
|
||||
#include <Dns.h>
|
||||
#include "configuration.h"
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
static EthernetUDP udp;
|
||||
static bool isSynced = false;
|
||||
static uint32_t baseEpoch = 0; // local unix epoch at last sync
|
||||
static uint32_t baseMillis = 0; // millis() at last sync
|
||||
static uint32_t lastAttempt = 0;
|
||||
static bool pending = false;
|
||||
static uint32_t sentAt = 0;
|
||||
|
||||
static const uint16_t LOCAL_PORT = 2390;
|
||||
static const uint32_t SYNC_INTERVAL = 15UL * 60UL * 1000UL; // resync every 15 min
|
||||
static const uint32_t RETRY_INTERVAL = 5UL * 1000UL; // retry quickly while unsynced (DNS may not be ready at boot)
|
||||
static const uint32_t RESYNC_RETRY = 60UL * 1000UL; // a failed resync is retried this often, not on every poll
|
||||
static const uint32_t NTP_UNIX_DELTA = 2208988800UL; // seconds 1900 -> 1970
|
||||
|
||||
namespace Ntp {
|
||||
|
||||
static void sendRequest() {
|
||||
// Resolve BEFORE taking our socket: the DNS lookup needs a socket of its own.
|
||||
IPAddress server;
|
||||
if (!server.fromString(Config.ntp.server)) {
|
||||
DNSClient dns;
|
||||
dns.begin(Ethernet.dnsServerIP());
|
||||
if (dns.getHostByName(Config.ntp.server.c_str(), server) != 1) return;
|
||||
}
|
||||
if (udp.begin(LOCAL_PORT) != 1) return; // no free socket now: try again later
|
||||
byte pkt[48] = {0};
|
||||
pkt[0] = 0x1B; // LI=0, VN=3, Mode=3 (client)
|
||||
if (udp.beginPacket(server, 123) == 1) {
|
||||
udp.write(pkt, 48);
|
||||
udp.endPacket();
|
||||
pending = true;
|
||||
sentAt = millis();
|
||||
} else {
|
||||
udp.stop();
|
||||
}
|
||||
}
|
||||
|
||||
void poll() {
|
||||
uint32_t now = millis();
|
||||
|
||||
bool due = !isSynced ? (lastAttempt == 0 || now - lastAttempt > RETRY_INTERVAL)
|
||||
: (now - baseMillis > SYNC_INTERVAL && now - lastAttempt > RESYNC_RETRY);
|
||||
if (!pending && due) { lastAttempt = now; sendRequest(); }
|
||||
|
||||
if (pending) {
|
||||
if (udp.parsePacket() >= 48) {
|
||||
byte buf[48];
|
||||
udp.read(buf, 48);
|
||||
uint32_t secs1900 = ((uint32_t)buf[40] << 24) | ((uint32_t)buf[41] << 16) |
|
||||
((uint32_t)buf[42] << 8) | (uint32_t)buf[43];
|
||||
baseEpoch = (secs1900 - NTP_UNIX_DELTA) + (int32_t)(Config.ntp.gmtCorrection * 3600.0f);
|
||||
baseMillis = millis();
|
||||
isSynced = true;
|
||||
pending = false;
|
||||
udp.stop();
|
||||
Serial.println("[ntp] synced " + hms(baseEpoch) + " (" + Config.ntp.server + ")");
|
||||
} else if (millis() - sentAt > 3000) {
|
||||
// timeout — retry next interval. Not `now - sentAt`: sentAt is stamped after
|
||||
// `now`, past the DNS lookup, so that difference wrapped and every request
|
||||
// timed out in the same poll it was sent, before the reply could arrive.
|
||||
pending = false;
|
||||
udp.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool synced() { return isSynced; }
|
||||
|
||||
uint32_t nowEpoch() {
|
||||
if (!isSynced) return 0;
|
||||
return baseEpoch + (millis() - baseMillis) / 1000;
|
||||
}
|
||||
|
||||
String hms(uint32_t epoch) {
|
||||
uint32_t d = epoch % 86400UL;
|
||||
char b[9];
|
||||
snprintf(b, sizeof(b), "%02u:%02u:%02u",
|
||||
(unsigned)(d / 3600), (unsigned)((d % 3600) / 60), (unsigned)(d % 60));
|
||||
return String(b);
|
||||
}
|
||||
|
||||
String ymd(uint32_t epoch) {
|
||||
// days since 1970-01-01 -> civil date (Howard Hinnant's civil_from_days)
|
||||
int32_t z = (int32_t)(epoch / 86400UL) + 719468;
|
||||
int32_t era = z / 146097;
|
||||
uint32_t doe = (uint32_t)(z - era * 146097);
|
||||
uint32_t yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
|
||||
uint32_t doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
|
||||
uint32_t mp = (5 * doy + 2) / 153;
|
||||
uint32_t d = doy - (153 * mp + 2) / 5 + 1;
|
||||
uint32_t m = mp < 10 ? mp + 3 : mp - 9;
|
||||
int32_t y = (int32_t)yoe + era * 400 + (m <= 2 ? 1 : 0);
|
||||
char b[32];
|
||||
snprintf(b, sizeof(b), "%04d-%02u-%02u", (int)y, (unsigned)m, (unsigned)d);
|
||||
return String(b);
|
||||
}
|
||||
|
||||
} // namespace Ntp
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Lean SNTP client over the W5500 (EthernetUDP) — replaces the ESP32 ntp_utils
|
||||
// (NTPClient + WiFiUDP). Non-blocking: poll() fires a request and picks up the
|
||||
// reply on a later call. Time is local (Config.ntp.gmtCorrection applied). Used
|
||||
// for real timestamps in the web views / heartbeat. netTask only (W5500 owner).
|
||||
namespace Ntp {
|
||||
void poll(); // sync periodically (~15 min); call each net loop
|
||||
bool synced(); // true once a reply has been received
|
||||
uint32_t nowEpoch(); // current LOCAL unix epoch, 0 if not synced
|
||||
String hms(uint32_t epoch); // "HH:MM:SS" from a local epoch
|
||||
String ymd(uint32_t epoch); // "YYYY-MM-DD" from a local epoch
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* RP2350 network OTA. Streams the posted raw firmware.bin into the arduino-pico
|
||||
* Updater (Update.begin/write/end); Update.end(true) stages it via picoOTA for
|
||||
* the bootloader, which copies it on the next reboot. netTask only (W5500 owner;
|
||||
* the transfer blocks the net loop for a few seconds — acceptable).
|
||||
*/
|
||||
#include "ota_rp2350.h"
|
||||
#include <Updater.h>
|
||||
#include "configuration.h"
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
namespace {
|
||||
|
||||
String base64(const String &data) {
|
||||
static const char *T = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
String r;
|
||||
int v = 0, c = 0;
|
||||
for (size_t i = 0; i < data.length(); i++) {
|
||||
v = (v << 8) | (uint8_t)data[i];
|
||||
c += 8;
|
||||
while (c >= 6) { c -= 6; r += T[(v >> c) & 0x3F]; }
|
||||
}
|
||||
if (c > 0) r += T[(v << (6 - c)) & 0x3F];
|
||||
while (r.length() % 4) r += '=';
|
||||
return r;
|
||||
}
|
||||
|
||||
// No credentials configured -> open. Otherwise require "Basic <base64(user:pass)>".
|
||||
bool authOk(const String &authHeader) {
|
||||
if (Config.ota.username.length() == 0 && Config.ota.password.length() == 0) return true;
|
||||
if (!authHeader.startsWith("Basic ")) return false;
|
||||
String token = authHeader.substring(6);
|
||||
token.trim();
|
||||
return token == base64(Config.ota.username + ":" + Config.ota.password);
|
||||
}
|
||||
|
||||
void reply(EthernetClient &c, int code, const char *reason, const char *msg) {
|
||||
c.print("HTTP/1.1 "); c.print(code); c.print(' '); c.print(reason); c.print("\r\n");
|
||||
c.print("Connection: close\r\nContent-Type: text/plain\r\nContent-Length: ");
|
||||
c.print((int)strlen(msg)); c.print("\r\n\r\n"); c.print(msg);
|
||||
c.flush();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace Ota {
|
||||
|
||||
void handleUpdate(EthernetClient &c, const String &authHeader, long contentLength) {
|
||||
if (!authOk(authHeader)) {
|
||||
c.print("HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm=\"iGate OTA\"\r\n"
|
||||
"Connection: close\r\nContent-Length: 0\r\n\r\n");
|
||||
c.flush();
|
||||
Serial.println("[ota] auth failed");
|
||||
return;
|
||||
}
|
||||
if (contentLength <= 0) { reply(c, 400, "Bad Request", "need Content-Length"); return; }
|
||||
|
||||
Serial.printf("[ota] starting update, %ld bytes\n", contentLength);
|
||||
if (!Update.begin((size_t)contentLength)) {
|
||||
Serial.printf("[ota] Update.begin failed err=%u\n", Update.getError());
|
||||
reply(c, 500, "Internal Server Error", "begin failed (not enough space?)");
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t buf[1024];
|
||||
long remaining = contentLength;
|
||||
uint32_t lastActivity = millis();
|
||||
while (remaining > 0) {
|
||||
if (!c.connected()) { Serial.println("[ota] client disconnected"); Update.end(false); return; }
|
||||
int avail = c.available();
|
||||
if (avail <= 0) {
|
||||
if (millis() - lastActivity > 10000) {
|
||||
Serial.println("[ota] timeout");
|
||||
Update.end(false);
|
||||
reply(c, 408, "Request Timeout", "timeout");
|
||||
return;
|
||||
}
|
||||
delay(1);
|
||||
continue;
|
||||
}
|
||||
size_t cap = sizeof(buf);
|
||||
if ((long)cap > remaining) cap = (size_t)remaining;
|
||||
if ((size_t)avail < cap) cap = (size_t)avail;
|
||||
int got = c.read(buf, cap);
|
||||
if (got <= 0) continue;
|
||||
if (Update.write(buf, (size_t)got) != (size_t)got) {
|
||||
Serial.printf("[ota] write failed err=%u\n", Update.getError());
|
||||
Update.end(false);
|
||||
reply(c, 500, "Internal Server Error", "write failed");
|
||||
return;
|
||||
}
|
||||
remaining -= got;
|
||||
lastActivity = millis();
|
||||
}
|
||||
|
||||
if (!Update.end(true)) {
|
||||
Serial.printf("[ota] end failed err=%u\n", Update.getError());
|
||||
reply(c, 500, "Internal Server Error", "finalize failed");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("[ota] update staged OK, rebooting...");
|
||||
reply(c, 200, "OK", "update ok, rebooting");
|
||||
delay(400);
|
||||
rp2040.restart();
|
||||
}
|
||||
|
||||
} // namespace Ota
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <Ethernet.h>
|
||||
|
||||
// Network firmware update for the RP2350 iGate. Replaces the ESP32 ota_utils
|
||||
// (ElegantOTA + ESPAsyncWebServer) with the arduino-pico Updater: the raw
|
||||
// firmware.bin is streamed into flash and staged for the bootloader, which
|
||||
// applies it on the next reboot. Served at POST /update over the W5500
|
||||
// (netTask). HTTP Basic auth against Config.ota.username/password (when set).
|
||||
//
|
||||
// curl -u user:pass --data-binary @firmware.bin http://<ip>/update
|
||||
namespace Ota {
|
||||
void handleUpdate(EthernetClient &c, const String &authHeader, long contentLength);
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* RP2350 query responder — lean port of QUERY_Utils (src/query_utils.cpp).
|
||||
* Answers RF-borne APRS message queries directed at our callsign. Replies/acks
|
||||
* go through the Station anti-collision output buffer. loraTask context only.
|
||||
*/
|
||||
#include "query_rp2350.h"
|
||||
#include "configuration.h"
|
||||
#include "station_rp2350.h"
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
// Signal stats of the last RX, set by lora_utils_rp2350.cpp.
|
||||
extern int rssi;
|
||||
extern float snr;
|
||||
extern int freqError;
|
||||
|
||||
// Records an incoming APRS message addressed to us (main.cpp -> netTask store,
|
||||
// served at GET /messages.json). Called from loraTask.
|
||||
extern void onIncomingMessage(const String &from, const String &text);
|
||||
|
||||
static const char *IGATE_VERSION = "RP2350 LoRa iGate v0.1";
|
||||
|
||||
namespace {
|
||||
|
||||
// Build the APRS message envelope addressed back to `station`:
|
||||
// CALL>APLRG1,RFONLY[,PATH]::STATION : (9-char padded addressee, RFONLY so
|
||||
// the reply is not gated). Caller appends the message body.
|
||||
// `gateable` drops the RFONLY tag so a neighbouring iGate may put the reply on
|
||||
// APRS-IS: used for third-party traffic, whose originator is not on our RF
|
||||
// (same rule as upstream's APRS_IS_Utils::processReceivedLoRaMessage).
|
||||
String envelope(const String& station, bool gateable = false) {
|
||||
String s = Config.callsign;
|
||||
s += ">APLRG1";
|
||||
if (!gateable) s += ",RFONLY";
|
||||
if (Config.beacon.path.length()) { s += ','; s += Config.beacon.path; }
|
||||
s += "::";
|
||||
String padded = station;
|
||||
for (int i = station.length(); i < 9; i++) padded += ' ';
|
||||
s += padded;
|
||||
s += ':';
|
||||
return s;
|
||||
}
|
||||
|
||||
// Compose the answer text for a query, or "" if unsupported. Manager-only remote
|
||||
// management commands (Config.remoteManagement managers) are honored when `sender`
|
||||
// is a manager. Our queries arrive over RF only, so rfOnly is always satisfied.
|
||||
String answerFor(const String& query, const String& sender) {
|
||||
String q = query;
|
||||
q.toUpperCase();
|
||||
// --- public queries ---
|
||||
if (q == "?APRS?" || q == "?" || q == "HELP")
|
||||
return "?APRSV ?APRSP ?APRSL ?APRSSR";
|
||||
if (q == "?APRSV")
|
||||
return String(IGATE_VERSION);
|
||||
if (q == "?APRSP")
|
||||
return "iGate QTH: " + String(Config.beacon.latitude, 2) + " " + String(Config.beacon.longitude, 2);
|
||||
if (q == "?APRSL") {
|
||||
String list = Station::heardListString();
|
||||
if (list.length() == 0)
|
||||
return "No Station Listened in the last " + String(Config.rememberStationTime) + " min.";
|
||||
return list;
|
||||
}
|
||||
if (q == "?APRSSR") {
|
||||
char buf[40];
|
||||
snprintf(buf, sizeof(buf), " %ddBm / %.2fdB / %dHz", rssi, (double)snr, freqError);
|
||||
return String(buf);
|
||||
}
|
||||
// --- manager-only remote management ---
|
||||
if (Station::isManager(sender)) {
|
||||
if (q.startsWith("?TX=ON")) {
|
||||
if (Config.loramodule.txActive) return "TX was ON";
|
||||
Config.loramodule.txActive = true;
|
||||
return "TX=ON";
|
||||
}
|
||||
if (q.startsWith("?TX=OFF")) {
|
||||
if (!Config.loramodule.txActive) return "TX was OFF";
|
||||
Config.loramodule.txActive = false;
|
||||
return "TX=OFF";
|
||||
}
|
||||
if (q.startsWith("?TX=?"))
|
||||
return Config.loramodule.txActive ? "TX=ON" : "TX=OFF";
|
||||
if (q.startsWith("?COMMIT")) {
|
||||
Config.writeFile();
|
||||
return "New Config Saved";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace Query {
|
||||
|
||||
bool handleMessage(const String& body, const String& sender) {
|
||||
// Third-party packet ("GATE>PATH:}ORIGINAL>PATH,TCPIP,GATE*::ADDRESSEE:text"):
|
||||
// a message another iGate pulled off APRS-IS and re-transmitted on RF. Unwrap
|
||||
// it so the message is credited to the ORIGINAL sender instead of the station
|
||||
// that repeated it (same detection as DIGI_Utils::processLoRaPacket upstream).
|
||||
String packet = body;
|
||||
String from = sender;
|
||||
bool thirdParty = false;
|
||||
int fc = body.indexOf(':');
|
||||
if (fc > 5 && fc < (int)body.length() - 1 && body[fc + 1] == '}' && body.indexOf("TCPIP") > 0) {
|
||||
thirdParty = true;
|
||||
packet = body.substring(body.indexOf(":}") + 2);
|
||||
int gt = packet.indexOf('>');
|
||||
if (gt <= 0) return false;
|
||||
from = packet.substring(0, gt);
|
||||
}
|
||||
|
||||
int dc = packet.indexOf("::");
|
||||
if (dc <= 10) return false; // not an APRS message
|
||||
|
||||
String addresseeAndMsg = packet.substring(dc + 2);
|
||||
int firstColon = addresseeAndMsg.indexOf(':');
|
||||
if (firstColon < 0) return false;
|
||||
String addressee = addresseeAndMsg.substring(0, firstColon);
|
||||
addressee.trim();
|
||||
if (addressee != Config.callsign) return false; // not for us
|
||||
|
||||
// Our own message handed back by an APRS-IS gateway: consume it (so it is
|
||||
// neither gated nor digipeated again) but don't log it or ack ourselves.
|
||||
if (from == Config.callsign) return true;
|
||||
|
||||
String text = addresseeAndMsg.substring(firstColon + 1); // message text (+ optional {msgid})
|
||||
|
||||
// ack any message that carries a {msgid}
|
||||
int brace = text.indexOf('{');
|
||||
String msgText = (brace > 0) ? text.substring(0, brace) : text;
|
||||
|
||||
onIncomingMessage(from, msgText); // log it for the web UI
|
||||
// ack id = text after the LAST '{' ("hola{MM}AA" -> "MM}AA", APRS 1.2c reply-acks);
|
||||
// an empty id means no ack was requested (upstream's generateAckMessage)
|
||||
String ackId = (brace > 0) ? text.substring(text.lastIndexOf('{') + 1) : "";
|
||||
ackId.trim();
|
||||
if (ackId.length()) {
|
||||
String ack = envelope(from, thirdParty);
|
||||
ack += "ack";
|
||||
ack += ackId;
|
||||
Station::enqueueTx(ack, false);
|
||||
Serial.println("[query] ack -> " + from + (thirdParty ? " (3rd party, " : " (") + ackId + ")");
|
||||
}
|
||||
|
||||
String upperText = msgText;
|
||||
upperText.toUpperCase();
|
||||
if (msgText.startsWith("?") || upperText == "HELP") { // it's a query ("HELP" needs no '?')
|
||||
String answer = answerFor(msgText, from);
|
||||
answer.trim();
|
||||
if (answer.length()) {
|
||||
String reply = envelope(from, thirdParty);
|
||||
reply += answer;
|
||||
reply += " *"; // random 2-char tag (matches upstream)
|
||||
reply += char(random(97, 123));
|
||||
reply += char(random(97, 123));
|
||||
reply += '*';
|
||||
Station::enqueueTx(reply, false);
|
||||
Serial.println("[query] " + msgText + " -> " + from + ": " + answer);
|
||||
}
|
||||
return true; // query handled: don't gate/digipeat
|
||||
}
|
||||
// Plain message addressed to us: consumed locally (recorded + acked above).
|
||||
// Return true so it is NOT gated to APRS-IS nor digipeated — a message "for
|
||||
// me" is not pass-through traffic. Messages to OTHER stations still gate/digi
|
||||
// normally (this function returns false early for them). To put a message on
|
||||
// APRS-IS, the sender uses the "Send via APRS-IS (TCP)" path explicitly.
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Query
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Lean port of QUERY_Utils (src/query_utils.cpp) for the RP2350 iGate. Answers
|
||||
// APRS message queries directed at our callsign, received over RF. Supported
|
||||
// public queries: ?APRS?/H/HELP/? (help), ?APRSV (version), ?APRSP (position),
|
||||
// ?APRSL (last-heard list), ?APRSSR (signal report of the last RX). Manager-only
|
||||
// remote control (?EM=/?TX=/?COMMIT) is NOT ported (EcoMode/txActive gating not
|
||||
// in the RP2350 feature set).
|
||||
//
|
||||
// Replies and acks are enqueued into the Station RF output buffer (anti-collision).
|
||||
// Call from loraTask only.
|
||||
namespace Query {
|
||||
// If `body` (headerless "SENDER>PATH::ADDRESSEE :text") is an APRS message
|
||||
// addressed to our callsign: send an ack (when it carries a {msgid}) and, if
|
||||
// the text is a query, enqueue the reply over RF. Returns true when it was a
|
||||
// query for us (caller should NOT gate/digipeat it). A non-query message for
|
||||
// us is acked but returns false (let the caller gate it as usual).
|
||||
bool handleMessage(const String& body, const String& sender);
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* RP2350 station services — lean port of STATION_Utils (src/station_utils.cpp).
|
||||
* Blacklist/managers, last-heard tracking, 25 s dedup, and an anti-collision RF
|
||||
* output buffer. All called from loraTask (single-threaded -> no locks).
|
||||
*/
|
||||
#include "station_rp2350.h"
|
||||
#include "configuration.h"
|
||||
#include "lora_utils.h"
|
||||
#include <vector>
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint32_t SECS_TO_WAIT = 3; // s between TX, and after an RX, before TXing
|
||||
constexpr uint32_t DEDUP_WINDOW = 25UL * 1000;
|
||||
|
||||
struct LastHeard { uint32_t when; String station; };
|
||||
struct OutPacket { String packet; bool isBeacon; };
|
||||
struct DedupEntry { uint32_t when; uint32_t hash; };
|
||||
|
||||
std::vector<String> blacklist;
|
||||
std::vector<String> managers;
|
||||
std::vector<LastHeard> lastHeard;
|
||||
std::vector<OutPacket> outBuffer;
|
||||
std::vector<DedupEntry> dedup;
|
||||
|
||||
uint32_t lastRxTime = 0;
|
||||
uint32_t lastTxTime = 0;
|
||||
volatile size_t activeStations = 0;
|
||||
volatile uint32_t rxCounter = 0; // RX packets since last telemetry (benign cross-task read-reset)
|
||||
|
||||
std::vector<String> loadCallsignList(const String& list) {
|
||||
std::vector<String> out;
|
||||
int start = 0, n = list.length();
|
||||
while (start < n) {
|
||||
while (start < n && list[start] == ' ') start++;
|
||||
if (start >= n) break;
|
||||
int end = start;
|
||||
while (end < n && list[end] != ' ') end++;
|
||||
out.emplace_back(list.substring(start, end));
|
||||
start = end + 1;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// matches a callsign against a list with trailing-wildcard support ("EA4*")
|
||||
bool inList(const std::vector<String>& list, const String& callsign) {
|
||||
for (const String& entry : list) {
|
||||
int star = entry.indexOf('*');
|
||||
if (star >= 0) {
|
||||
if (star >= 2 && (int)callsign.length() >= star &&
|
||||
strncmp(callsign.c_str(), entry.c_str(), star) == 0)
|
||||
return true;
|
||||
} else if (entry == callsign) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t djb2(const String& station, const String& payload) {
|
||||
uint32_t h = 5381;
|
||||
for (size_t i = 0; i < station.length(); i++) h = ((h << 5) + h) + (uint8_t)station[i];
|
||||
for (size_t i = 0; i < payload.length(); i++) h = ((h << 5) + h) + (uint8_t)payload[i];
|
||||
return h;
|
||||
}
|
||||
|
||||
void deleteNotHeard() {
|
||||
uint32_t now = millis();
|
||||
uint32_t timeout = (uint32_t)Config.rememberStationTime * 60UL * 1000UL;
|
||||
for (int i = (int)lastHeard.size() - 1; i >= 0; i--)
|
||||
if (now - lastHeard[i].when >= timeout) lastHeard.erase(lastHeard.begin() + i);
|
||||
activeStations = lastHeard.size();
|
||||
}
|
||||
|
||||
void cleanDedup() {
|
||||
uint32_t now = millis();
|
||||
for (int i = (int)dedup.size() - 1; i >= 0; i--)
|
||||
if (now - dedup[i].when > DEDUP_WINDOW) dedup.erase(dedup.begin() + i);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace Station {
|
||||
|
||||
void setup() {
|
||||
blacklist = loadCallsignList(Config.blacklist);
|
||||
managers = loadCallsignList(Config.remoteManagement.managers);
|
||||
Serial.printf("[station] blacklist=%u managers=%u\n",
|
||||
(unsigned)blacklist.size(), (unsigned)managers.size());
|
||||
}
|
||||
|
||||
bool isBlacklisted(const String& callsign) { return inList(blacklist, callsign); }
|
||||
bool isManager(const String& callsign) { return inList(managers, callsign); }
|
||||
|
||||
// Verbatim copy of Utils::callsignIsValid (src/utils.cpp), which is not built for
|
||||
// the RP2350. Keep the two in step.
|
||||
bool callsignIsValid(const String& callsign) {
|
||||
if (callsign == "WLNK-1") return true;
|
||||
int totalCallsignLength = callsign.length();
|
||||
if (totalCallsignLength < 4) return false;
|
||||
|
||||
int hyphenIndex = callsign.indexOf("-");
|
||||
int baseCallsignLength = (hyphenIndex > 0) ? hyphenIndex : totalCallsignLength;
|
||||
|
||||
if (hyphenIndex > 0) { // SSID Validation
|
||||
if (hyphenIndex < 4) return false; // base Callsign must have at least 4 characters
|
||||
int ssidStart = hyphenIndex + 1;
|
||||
int ssidLength = totalCallsignLength - ssidStart;
|
||||
if (ssidLength == 0 || ssidLength > 2) return false;
|
||||
if (callsign.indexOf('-', ssidStart) != -1) return false; // avoid another "-" in ssid
|
||||
if (ssidLength == 2 && callsign[ssidStart] == '0') return false; // ssid can't start with "0"
|
||||
for (int i = ssidStart; i < totalCallsignLength; i++) {
|
||||
if (!isDigit(callsign[i])) return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (baseCallsignLength < 4 || baseCallsignLength > 6) return false;
|
||||
|
||||
bool padded = false; // Callsigns with 4 characters like A0AA are padded into 5 characters for further analisis : A0AA --> _A0AA
|
||||
if (baseCallsignLength == 4 && isAlpha(callsign[0]) && isDigit(callsign[1]) && isAlpha(callsign[2]) && isAlpha(callsign[3])) padded = true;
|
||||
char c0, c1, c2, c3;
|
||||
if (padded) {
|
||||
c0 = ' ';
|
||||
c1 = callsign[0];
|
||||
c2 = callsign[1];
|
||||
c3 = callsign[2];
|
||||
} else {
|
||||
c0 = callsign[0];
|
||||
c1 = callsign[1];
|
||||
c2 = callsign[2];
|
||||
c3 = callsign[3];
|
||||
}
|
||||
if (!isDigit(c2) || !isAlpha(c3)) { // __0A__ must be validated
|
||||
if (c0 != 'R' && !isDigit(c1) && !isAlpha(c2)) return false; // to accepto R0A___
|
||||
}
|
||||
|
||||
bool isValid =
|
||||
((isAlphaNumeric(c0) || c0 == ' ') && isAlpha(c1)) || // AA0A (+A+A) + _A0AA (+A) + 0A0A (+A+A)
|
||||
(isAlpha(c0) && isDigit(c1)) || // A00A (+A+A)
|
||||
(c0 == 'R' && baseCallsignLength == 6 && isDigit(c1) && isAlpha(c2) && isAlpha(c3) && isAlpha(callsign[4])); // R0AA (+A+A)
|
||||
if (!isValid) return false; // also 00__ avoided
|
||||
|
||||
if (baseCallsignLength > 4 ) { // to validate ____AA
|
||||
for (int i = 4; i < baseCallsignLength; i++) {
|
||||
if (!isAlpha(callsign[i])) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void updateLastHeard(const String& station) {
|
||||
deleteNotHeard();
|
||||
uint32_t now = millis();
|
||||
for (auto& s : lastHeard) {
|
||||
if (s.station == station) { s.when = now; return; }
|
||||
}
|
||||
lastHeard.push_back({now, station});
|
||||
activeStations = lastHeard.size();
|
||||
}
|
||||
|
||||
bool wasHeard(const String& station) {
|
||||
deleteNotHeard();
|
||||
for (const auto& s : lastHeard)
|
||||
if (s.station == station) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t activeCount() { return activeStations; }
|
||||
|
||||
String heardListString() {
|
||||
deleteNotHeard();
|
||||
String out;
|
||||
for (const auto& s : lastHeard) { out += s.station; out += ' '; }
|
||||
out.trim();
|
||||
return out;
|
||||
}
|
||||
|
||||
bool isDuplicate(const String& station, const String& payload) {
|
||||
cleanDedup();
|
||||
uint32_t h = djb2(station, payload);
|
||||
for (const auto& d : dedup)
|
||||
if (d.hash == h) return true;
|
||||
dedup.push_back({millis(), h});
|
||||
return false;
|
||||
}
|
||||
|
||||
void enqueueTx(const String& packet, bool isBeacon) {
|
||||
if (packet.length() == 0) return; // never queue an empty packet
|
||||
outBuffer.push_back({packet, isBeacon});
|
||||
}
|
||||
|
||||
void noteRx() { lastRxTime = millis(); rxCounter++; }
|
||||
|
||||
uint32_t takeRxCount() { uint32_t n = rxCounter; rxCounter = 0; return n; }
|
||||
|
||||
size_t txPending() { return outBuffer.size(); }
|
||||
|
||||
void processTxBuffer() {
|
||||
if (outBuffer.empty()) return;
|
||||
uint32_t now = millis();
|
||||
uint32_t window = SECS_TO_WAIT * 1000;
|
||||
if ((now - lastTxTime) <= window || (now - lastRxTime) <= window) return; // let the channel settle
|
||||
LoRa_Utils::sendNewPacket(outBuffer.front().packet);
|
||||
outBuffer.erase(outBuffer.begin());
|
||||
lastTxTime = millis();
|
||||
}
|
||||
|
||||
} // namespace Station
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Lean port of STATION_Utils (src/station_utils.cpp) for the RP2350 iGate.
|
||||
// Provides the shared packet-policy services: blacklist/managers, last-heard
|
||||
// tracking, a 25 s duplicate filter, and an anti-collision RF output buffer.
|
||||
//
|
||||
// CONCURRENCY: every function here is meant to be called from loraTask only (the
|
||||
// owner of the radio). All state is therefore single-threaded — no locks. The
|
||||
// one exception is activeCount(), which reads a volatile snapshot so netTask can
|
||||
// print it in the heartbeat. Dropped from the original: display hooks, EcoMode /
|
||||
// low-voltage sleep, and config-write-on-TX (not in the RP2350 feature set).
|
||||
namespace Station {
|
||||
void setup(); // load blacklist/managers from Config (call at boot)
|
||||
|
||||
bool isBlacklisted(const String& callsign);
|
||||
bool isManager(const String& callsign);
|
||||
bool callsignIsValid(const String& callsign); // port of Utils::callsignIsValid; pure, safe from any task
|
||||
|
||||
void updateLastHeard(const String& station); // record/refresh a heard station
|
||||
bool wasHeard(const String& station); // heard within rememberStationTime?
|
||||
size_t activeCount(); // # stations currently tracked (volatile snapshot)
|
||||
String heardListString(); // space-separated heard callsigns (for ?APRSL)
|
||||
|
||||
// 25 s duplicate filter on (station, payload). True if the same packet was
|
||||
// seen within the window (caller should neither gate nor digipeat it).
|
||||
bool isDuplicate(const String& station, const String& payload);
|
||||
|
||||
// RF output buffer (anti-collision TX scheduling). Enqueue digipeats/beacons
|
||||
// from loraTask; processTxBuffer() sends at most one packet per call once the
|
||||
// channel has been idle (no RX/TX) for SECS_TO_WAIT seconds.
|
||||
void enqueueTx(const String& packet, bool isBeacon = false);
|
||||
void noteRx(); // call on every RX (feeds the TX backoff)
|
||||
uint32_t takeRxCount(); // RX packets since last call, then resets (for telemetry)
|
||||
void processTxBuffer(); // call each loraTask iteration
|
||||
size_t txPending();
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* RP2350 remote syslog (RFC5424 / UDP over EthernetUDP). The server IP is
|
||||
* resolved once at setup (literal or one DNS lookup) and cached; logging is
|
||||
* fire-and-forget UDP to that IP — never a per-call DNS lookup (the per-LOG
|
||||
* DNS/ARP block is what reboot-looped the W5500 boards). netTask only.
|
||||
*/
|
||||
#include "syslog_rp2350.h"
|
||||
#include <Ethernet.h>
|
||||
#include <EthernetUdp.h>
|
||||
#include <Dns.h>
|
||||
#include "configuration.h"
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
static EthernetUDP udp;
|
||||
static IPAddress serverIp;
|
||||
static bool ready = false;
|
||||
|
||||
static void send(const String &message) {
|
||||
if (!ready) return;
|
||||
String pkt = "<165>1 - ";
|
||||
pkt += Config.callsign;
|
||||
pkt += " RP2350iGate - - - ";
|
||||
pkt += message;
|
||||
udp.beginPacket(serverIp, Config.syslog.port); // resolved IP -> no DNS
|
||||
udp.write((const uint8_t *)pkt.c_str(), pkt.length());
|
||||
udp.endPacket();
|
||||
}
|
||||
|
||||
namespace Syslog {
|
||||
|
||||
void setup() {
|
||||
if (!Config.syslog.active) return;
|
||||
udp.begin(0);
|
||||
if (serverIp.fromString(Config.syslog.server)) { // literal IP
|
||||
ready = true;
|
||||
} else { // resolve hostname once
|
||||
DNSClient dns;
|
||||
dns.begin(Ethernet.dnsServerIP());
|
||||
IPAddress ip;
|
||||
if (dns.getHostByName(Config.syslog.server.c_str(), ip) == 1) { serverIp = ip; ready = true; }
|
||||
}
|
||||
if (ready)
|
||||
Serial.printf("[syslog] -> %d.%d.%d.%d:%d\n", serverIp[0], serverIp[1], serverIp[2], serverIp[3],
|
||||
Config.syslog.port);
|
||||
else
|
||||
Serial.println("[syslog] could not resolve server " + Config.syslog.server);
|
||||
}
|
||||
|
||||
void logRx(const String &frame, int rssi, float snr) {
|
||||
if (!ready) return;
|
||||
int gt = frame.indexOf('>');
|
||||
int colon = frame.indexOf(':');
|
||||
String sender = (gt > 0) ? frame.substring(0, gt) : "?";
|
||||
String payload = (colon >= 0) ? frame.substring(colon + 1) : frame;
|
||||
char sig[40];
|
||||
snprintf(sig, sizeof(sig), " / %ddBm / %.2fdB", rssi, (double)snr);
|
||||
send("RX / " + sender + " ---> " + payload + sig);
|
||||
}
|
||||
|
||||
void logTx(const String &info) {
|
||||
send(info);
|
||||
}
|
||||
|
||||
} // namespace Syslog
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Remote syslog (RFC5424 over UDP) for the RP2350 iGate. Replaces the ESP32
|
||||
// syslog_utils (WiFiUDP) with EthernetUDP. The server is resolved ONCE at setup
|
||||
// (literal IP or a single DNS lookup) and cached, so logging never does per-call
|
||||
// DNS — that blocking-per-LOG behaviour is what reboot-looped the W5500 boards.
|
||||
// netTask only (W5500 owner); fire-and-forget UDP.
|
||||
namespace Syslog {
|
||||
void setup(); // resolve server once + begin UDP
|
||||
void logRx(const String &frame, int rssi, float snr); // a received RF packet
|
||||
void logTx(const String &info); // a TX / APRS-IS event line
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* RP2350 APRS structured telemetry — classic "T#seq,a1..a5,bits" data packets
|
||||
* plus EQNS/UNIT/PARM definitions addressed to self. Operational channels
|
||||
* (RxPkts/Heard/RSSI/SNR). netTask only (reads netTask-owned counters + the
|
||||
* APRS-IS socket via AprsIs). Values are 3-digit 0..255 with the EQNS below
|
||||
* mapping them back to engineering units.
|
||||
*/
|
||||
#include "telemetry_rp2350.h"
|
||||
#include "configuration.h"
|
||||
#include "station_rp2350.h"
|
||||
#include "aprsis_rp2350.h"
|
||||
#include "battery_rp2350.h"
|
||||
|
||||
extern Configuration Config;
|
||||
extern int rssi; // last RX signal stats (lora_utils_rp2350.cpp)
|
||||
extern float snr;
|
||||
|
||||
namespace {
|
||||
|
||||
uint16_t sequence = 0; // 000..999
|
||||
uint32_t lastDefs = 0; // millis() of last EQNS/UNIT/PARM (0 = never)
|
||||
|
||||
int clamp255(long v) { return v < 0 ? 0 : (v > 255 ? 255 : (int)v); }
|
||||
|
||||
String pad3(int v) {
|
||||
char b[4];
|
||||
snprintf(b, sizeof(b), "%03d", clamp255(v));
|
||||
return String(b);
|
||||
}
|
||||
|
||||
String selfCall() {
|
||||
return Config.tacticalCallsign.length() ? Config.tacticalCallsign : Config.callsign;
|
||||
}
|
||||
|
||||
// self-addressed message envelope for EQNS/UNIT/PARM (TCPIP*: the server adds qAC)
|
||||
String defEnvelope(const String &call, const String &payload) {
|
||||
String s = call;
|
||||
s += ">APLRG1,TCPIP*::";
|
||||
String padded = call;
|
||||
for (int i = call.length(); i < 9; i++) padded += ' ';
|
||||
s += padded;
|
||||
s += ':';
|
||||
s += payload;
|
||||
return s;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace Telemetry {
|
||||
|
||||
String dataPacket() {
|
||||
int a1 = clamp255(Station::takeRxCount()); // RxPkts EQNS 0,1,0
|
||||
int a2 = clamp255(Station::activeCount()); // Heard EQNS 0,1,0
|
||||
int a3 = clamp255(rssi + 150); // RSSI EQNS 0,1,-150 -> dBm
|
||||
int a4 = clamp255((long)((snr + 20.0f) * 5.0f)); // SNR EQNS 0,0.2,-20 -> dB
|
||||
int a5 = Config.battery.sendVoltageAsTelemetry // Vbat EQNS 0,0.1,0 -> V (VSYS)
|
||||
? clamp255((long)(Battery::vsys() * 10.0f)) : 0;
|
||||
|
||||
char seq[6];
|
||||
snprintf(seq, sizeof(seq), "%03u", sequence);
|
||||
sequence = (sequence + 1) % 1000;
|
||||
|
||||
String line = selfCall();
|
||||
line += ">APLRG1,TCPIP*:T#";
|
||||
line += seq; line += ',';
|
||||
line += pad3(a1); line += ',';
|
||||
line += pad3(a2); line += ',';
|
||||
line += pad3(a3); line += ',';
|
||||
line += pad3(a4); line += ',';
|
||||
line += pad3(a5); line += ",00000000";
|
||||
return line;
|
||||
}
|
||||
|
||||
bool dueDefinitions() {
|
||||
return lastDefs == 0 || (millis() - lastDefs) > 24UL * 60UL * 60UL * 1000UL;
|
||||
}
|
||||
|
||||
void sendDefinitions() {
|
||||
String call = selfCall();
|
||||
AprsIs::send(defEnvelope(call, "PARM.RxPkts,Heard,RSSI,SNR,Vbat"));
|
||||
AprsIs::send(defEnvelope(call, "UNIT.Pkt,Stn,dBm,dB,V"));
|
||||
AprsIs::send(defEnvelope(call, "EQNS.0,1,0,0,1,0,0,1,-150,0,0.2,-20,0,0.1,0"));
|
||||
lastDefs = millis() ? millis() : 1;
|
||||
Serial.println("[telemetry] sent EQNS/UNIT/PARM definitions");
|
||||
}
|
||||
|
||||
} // namespace Telemetry
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// APRS structured telemetry for the RP2350 iGate, classic "T#" data packets
|
||||
// (universally parsed by aprs.fi; the Base91 "|...|"-in-comment form did not
|
||||
// register there). Operational channels (no battery — this board has none):
|
||||
// A1 RxPkts RF packets since last report A2 Heard stations heard
|
||||
// A3 RSSI last RX dBm A4 SNR last RX dB (A5 spare)
|
||||
// Sent as its own packet alongside the APRS-IS beacon; EQNS./UNIT./PARM. define
|
||||
// the channels (sent to self at boot + ~daily). netTask only.
|
||||
namespace Telemetry {
|
||||
String dataPacket(); // "CALL>APLRG1,TCPIP,qAC:T#nnn,a1..a5,bits"; advances seq
|
||||
bool dueDefinitions(); // true at boot and every ~24 h
|
||||
void sendDefinitions(); // AprsIs::send the EQNS./UNIT./PARM. messages
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* RP2350 TNC server — replaces the ESP32 tnc_utils.cpp (WiFiServer/mDNS) with an
|
||||
* EthernetServer on the W5500. Speaks KISS (codec reused as-is from
|
||||
* src/kiss_utils.cpp) or, with tnc.kissProtocol = false, plain TNC2 text lines
|
||||
* terminated by CR LF, as tnc_utils.cpp does. Runs entirely in netTask (W5500
|
||||
* owner); frames bound for RF are handed to loraTask via enqueueRfFrame()
|
||||
* (txMsgQueue -> Station buffer).
|
||||
*/
|
||||
#include "tnc_rp2350.h"
|
||||
#include <Ethernet.h>
|
||||
#include "configuration.h"
|
||||
#include "kiss_utils.h"
|
||||
#include "kiss_protocol.h"
|
||||
#include "aprsis_rp2350.h"
|
||||
|
||||
extern Configuration Config;
|
||||
extern void enqueueRfFrame(const String &frame); // main.cpp: push to txMsgQueue -> loraTask
|
||||
|
||||
#define TNC_PORT 8001
|
||||
#define TNC_MAX_CLIENTS 2
|
||||
#define TNC_MAX_BUF 512
|
||||
|
||||
static EthernetServer tncServer(TNC_PORT);
|
||||
static EthernetClient tncClients[TNC_MAX_CLIENTS];
|
||||
static String tncBuf[TNC_MAX_CLIENTS];
|
||||
static bool tncStarted = false;
|
||||
|
||||
namespace {
|
||||
|
||||
const char *protocolLabel() {
|
||||
return Config.tnc.kissProtocol ? "KISS" : "TNC2";
|
||||
}
|
||||
|
||||
// Act on one complete TNC2 frame from a client: TX over RF (honoring acceptOwn /
|
||||
// txActive) and optionally bridge to APRS-IS.
|
||||
void processFrame(const String &frame) {
|
||||
int gt = frame.indexOf('>');
|
||||
String sender = (gt > 0) ? frame.substring(0, gt) : "";
|
||||
if (!Config.tnc.acceptOwn && sender == Config.callsign) {
|
||||
Serial.printf("[tnc] ignored own frame from %s client\n", protocolLabel());
|
||||
return;
|
||||
}
|
||||
Serial.printf("[tnc] <- (%s) ", protocolLabel());
|
||||
Serial.println(frame);
|
||||
if (Config.loramodule.txActive) enqueueRfFrame(frame); // -> loraTask -> RF
|
||||
|
||||
if (Config.tnc.aprsBridgeActive && Config.aprs_is.active && AprsIs::connected()) {
|
||||
int colon = frame.indexOf(':');
|
||||
if (gt > 0 && colon > gt) { // SENDER>PATH,qAO,IGATE:payload
|
||||
String line = frame.substring(0, colon);
|
||||
line += ",qAO,";
|
||||
line += Config.callsign;
|
||||
line += frame.substring(colon);
|
||||
AprsIs::send(line);
|
||||
Serial.println("[tnc] -> APRS-IS: " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// KISS: collect bytes between FENDs, then decode.
|
||||
void handleByteKISS(int idx, char ch) {
|
||||
String &buf = tncBuf[idx];
|
||||
if (buf.length() == 0 && ch != (char)FEND) return; // wait for a frame start
|
||||
buf += ch;
|
||||
|
||||
if (ch == (char)FEND && buf.length() > 3) {
|
||||
bool isData = false;
|
||||
String frame = decodeKISS(buf, isData);
|
||||
buf = "";
|
||||
if (isData && frame.length() > 0) processFrame(frame);
|
||||
}
|
||||
if (buf.length() > TNC_MAX_BUF) buf = "";
|
||||
}
|
||||
|
||||
// TNC2: one frame per line; CR is ignored, LF ends it. Lines that are not
|
||||
// SENDER>PATH:payload are dropped, as tnc_utils.cpp does.
|
||||
void handleByteTNC2(int idx, char ch) {
|
||||
String &buf = tncBuf[idx];
|
||||
if (ch == '\r') return;
|
||||
|
||||
if (ch == '\n') {
|
||||
String frame = buf;
|
||||
frame.trim();
|
||||
buf = "";
|
||||
if (frame.length() > 0 && frame.indexOf(':') != -1 && frame.indexOf('>') != -1) processFrame(frame);
|
||||
return;
|
||||
}
|
||||
|
||||
buf += ch;
|
||||
if (buf.length() > TNC_MAX_BUF) buf = "";
|
||||
}
|
||||
|
||||
void handleByte(int idx, char ch) {
|
||||
if (Config.tnc.kissProtocol) handleByteKISS(idx, ch);
|
||||
else handleByteTNC2(idx, ch);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace Tnc {
|
||||
|
||||
void setup() {
|
||||
if (!Config.tnc.enableServer) return;
|
||||
tncServer.begin();
|
||||
tncStarted = true;
|
||||
Serial.printf("[tnc] %s server on :%d\n", protocolLabel(), TNC_PORT);
|
||||
}
|
||||
|
||||
void poll() {
|
||||
if (!tncStarted) return;
|
||||
|
||||
EthernetClient nc = tncServer.accept();
|
||||
if (nc) {
|
||||
bool placed = false;
|
||||
for (int i = 0; i < TNC_MAX_CLIENTS; i++) {
|
||||
if (!tncClients[i] || !tncClients[i].connected()) {
|
||||
tncClients[i].stop();
|
||||
tncClients[i] = nc;
|
||||
tncBuf[i] = "";
|
||||
placed = true;
|
||||
Serial.printf("[tnc] client %d connected\n", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!placed) { Serial.println("[tnc] no free slots, refused"); nc.stop(); }
|
||||
}
|
||||
|
||||
for (int i = 0; i < TNC_MAX_CLIENTS; i++) {
|
||||
if (tncClients[i] && tncClients[i].connected()) {
|
||||
while (tncClients[i].available() > 0) handleByte(i, (char)tncClients[i].read());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void broadcast(const String &tnc2frame) {
|
||||
if (!tncStarted || tnc2frame.length() == 0) return;
|
||||
String encoded = Config.tnc.kissProtocol ? encodeKISS(tnc2frame) : (tnc2frame + "\r\n");
|
||||
for (int i = 0; i < TNC_MAX_CLIENTS; i++) {
|
||||
if (tncClients[i] && tncClients[i].connected()) {
|
||||
tncClients[i].print(encoded);
|
||||
tncClients[i].flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Tnc
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// KISS TNC server for the RP2350 iGate (TCP :8001 over the W5500). Lets external
|
||||
// APRS clients (APRSdroid, Xastir, YAAC, ...) use the iGate's LoRa radio:
|
||||
// client -> KISS frame -> decode -> RF TX (and optional APRS-IS bridge)
|
||||
// RF RX -> KISS-encode -> all connected clients
|
||||
// Reuses the validated KISS codec (src/kiss_utils.cpp). All calls run from
|
||||
// netTask (the W5500 owner); RF TX is handed to loraTask via enqueueRfFrame().
|
||||
namespace Tnc {
|
||||
void setup(); // start the server if Config.tnc.enableServer
|
||||
void poll(); // accept clients + read their KISS frames
|
||||
void broadcast(const String& tnc2frame); // a received RF frame -> KISS clients
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
#include "wx_rp2350.h"
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_BMP280.h>
|
||||
#include <Adafruit_BME680.h>
|
||||
#include "configuration.h"
|
||||
#include "board_pinout.h" // PIN_WX_SDA / PIN_WX_SCL
|
||||
|
||||
extern Configuration Config;
|
||||
|
||||
// Which I2C peripheral the weather sensor hangs off. arduino-pico: Wire = I2C0
|
||||
// (GP4/GP5 by default), Wire1 = I2C1 (GP6/GP7 etc.). Select with -D WX_USE_WIRE1.
|
||||
#ifdef WX_USE_WIRE1
|
||||
#define WX_WIRE Wire1
|
||||
#else
|
||||
#define WX_WIRE Wire
|
||||
#endif
|
||||
|
||||
#ifndef PIN_WX_SDA
|
||||
#define PIN_WX_SDA 4 // I2C0 default SDA on arduino-pico (GP4)
|
||||
#endif
|
||||
#ifndef PIN_WX_SCL
|
||||
#define PIN_WX_SCL 5 // I2C0 default SCL on arduino-pico (GP5)
|
||||
#endif
|
||||
|
||||
#define WX_CORRECTION_FACTOR 8.2296f // metres -> hPa (matches wx_utils.cpp)
|
||||
|
||||
namespace Wx {
|
||||
|
||||
static Adafruit_BMP280 bmp280(&WX_WIRE);
|
||||
static Adafruit_BME680 bme680(&WX_WIRE);
|
||||
static bool bmpPresent = false; // BMP280: temperature + barometric pressure
|
||||
static bool bme680Present = false; // BME680: temp + humidity + pressure + gas/VOC
|
||||
static bool shtPresent = false; // SHT40: temperature + relative humidity
|
||||
static uint8_t sht40Addr = 0; // 0x44 (AD1B) or 0x45 (BD1B)
|
||||
|
||||
// --- APRS field formatters (byte-for-byte the ESP32 wx_utils.cpp output) ---
|
||||
static String tempString(float degF) { // temperature in Fahrenheit, 3 digits
|
||||
String s = String((int)degF);
|
||||
switch (s.length()) {
|
||||
case 1: return "00" + s;
|
||||
case 2: return "0" + s;
|
||||
case 3: return s;
|
||||
default: return "-999";
|
||||
}
|
||||
}
|
||||
|
||||
static String presString(float hPa) { // pressure x10 (0.1 hPa), 5 digits
|
||||
String whole = String((int)hPa);
|
||||
String dec = String(int((hPa - int(hPa)) * 10));
|
||||
switch (whole.length()) {
|
||||
case 1: return "000" + whole + dec;
|
||||
case 2: return "00" + whole + dec;
|
||||
case 3: return "0" + whole + dec;
|
||||
case 4: return whole + dec;
|
||||
case 5: return whole;
|
||||
default: return "-99999";
|
||||
}
|
||||
}
|
||||
|
||||
static String humString(float rh) { // relative humidity, 2 digits (h00 == 100%)
|
||||
long h = lround(rh);
|
||||
if (h >= 100) return "00"; // APRS encodes 100% as "00"
|
||||
if (h < 0) h = 0;
|
||||
char b[3];
|
||||
snprintf(b, sizeof(b), "%02ld", h);
|
||||
return String(b);
|
||||
}
|
||||
|
||||
// SHT40: write 0xFD (measure, high precision), wait, read 6 bytes
|
||||
// [tMSB tLSB tCRC hMSB hLSB hCRC]. Datasheet conversions. CRC not checked (lean).
|
||||
static bool sht40Read(float &tC, float &rh) {
|
||||
WX_WIRE.beginTransmission(sht40Addr);
|
||||
WX_WIRE.write(0xFD);
|
||||
if (WX_WIRE.endTransmission() != 0) return false;
|
||||
delay(10); // high-precision conversion ~8.2 ms
|
||||
if (WX_WIRE.requestFrom(sht40Addr, (uint8_t)6) != 6) return false;
|
||||
uint8_t d[6];
|
||||
for (int i = 0; i < 6; i++) d[i] = WX_WIRE.read();
|
||||
uint16_t rawT = ((uint16_t)d[0] << 8) | d[1];
|
||||
uint16_t rawH = ((uint16_t)d[3] << 8) | d[4];
|
||||
tC = -45.0f + 175.0f * ((float)rawT / 65535.0f);
|
||||
rh = -6.0f + 125.0f * ((float)rawH / 65535.0f);
|
||||
if (rh < 0.0f) rh = 0.0f;
|
||||
if (rh > 100.0f) rh = 100.0f;
|
||||
return true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
WX_WIRE.setSDA(PIN_WX_SDA);
|
||||
WX_WIRE.setSCL(PIN_WX_SCL);
|
||||
WX_WIRE.begin();
|
||||
// The board carries dedicated 4.7k external I2C pull-ups, so no internal
|
||||
// pull-ups are enabled here.
|
||||
|
||||
// I2C scan (diagnostic): list everything answering on PIN_WX_SDA/SCL.
|
||||
Serial.printf("[wx] I2C scan on SDA=%d SCL=%d:", PIN_WX_SDA, PIN_WX_SCL);
|
||||
int found = 0;
|
||||
for (uint8_t a = 0x08; a < 0x78; a++) {
|
||||
WX_WIRE.beginTransmission(a);
|
||||
if (WX_WIRE.endTransmission() == 0) { Serial.printf(" 0x%02X", a); found++; }
|
||||
}
|
||||
Serial.println(found ? "" : " (none)");
|
||||
|
||||
// 0x76/0x77 (SDO strap) hosts either a BMP280 (temp + pressure) or a BME680
|
||||
// (temp + humidity + pressure + gas/VOC) — they share the address. Each
|
||||
// Adafruit .begin() validates its own chip ID (BMP280 = 0x58, BME680 = 0x61),
|
||||
// so probe the BME680 first and fall back to the BMP280: no false positives.
|
||||
if (bme680.begin(0x76) || bme680.begin(0x77)) {
|
||||
bme680.setTemperatureOversampling(BME680_OS_8X);
|
||||
bme680.setHumidityOversampling(BME680_OS_2X);
|
||||
bme680.setPressureOversampling(BME680_OS_4X);
|
||||
bme680.setIIRFilterSize(BME680_FILTER_SIZE_3);
|
||||
bme680.setGasHeater(320, 150); // 320 C for 150 ms -> gas resistance
|
||||
bme680Present = true;
|
||||
Serial.println("[wx] BME680 found (temp + humidity + pressure + gas)");
|
||||
} else if (bmp280.begin(0x76) || bmp280.begin(0x77)) {
|
||||
bmp280.setSampling(Adafruit_BMP280::MODE_FORCED,
|
||||
Adafruit_BMP280::SAMPLING_X2, // temperature
|
||||
Adafruit_BMP280::SAMPLING_X16, // pressure
|
||||
Adafruit_BMP280::FILTER_X16,
|
||||
Adafruit_BMP280::STANDBY_MS_500);
|
||||
bmpPresent = true;
|
||||
Serial.println("[wx] BMP280 found (temp + pressure)");
|
||||
}
|
||||
|
||||
// SHT40 at 0x44 or 0x45 (temp + humidity). Detected by an ACK on the bus.
|
||||
for (uint8_t a = 0x44; a <= 0x45; a++) {
|
||||
WX_WIRE.beginTransmission(a);
|
||||
if (WX_WIRE.endTransmission() == 0) {
|
||||
sht40Addr = a;
|
||||
shtPresent = true;
|
||||
Serial.printf("[wx] SHT40 found at 0x%02X (temp + humidity)\n", a);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bmpPresent && !bme680Present && !shtPresent)
|
||||
Serial.println("[wx] no BME680/BMP280/SHT40 on I2C (weather disabled)");
|
||||
}
|
||||
|
||||
bool present() { return bmpPresent || bme680Present || shtPresent; }
|
||||
|
||||
// APRS weather payload: ".../...g...t<TTT>[h<HH>][b<PPPPP>]". Temperature comes
|
||||
// from whichever sensor is present (SHT40 preferred); humidity from the SHT40 or
|
||||
// BME680, pressure from the BME680 or BMP280. A BME680 also appends its gas/VOC
|
||||
// resistance ("Gas: <k>Kohms", matching the ESP32 wx_utils.cpp). Absent fields
|
||||
// are omitted.
|
||||
String readAprs() {
|
||||
if (!bmpPresent && !bme680Present && !shtPresent) return "";
|
||||
|
||||
float tC = NAN, rh = NAN, p = NAN, gasKohm = NAN;
|
||||
|
||||
if (shtPresent) {
|
||||
float t, h;
|
||||
if (sht40Read(t, h)) { tC = t; rh = h; }
|
||||
}
|
||||
if (bme680Present) {
|
||||
if (bme680.performReading()) { // blocking read (temp/hum/pres/gas)
|
||||
p = bme680.pressure / 100.0f; // hPa
|
||||
gasKohm = bme680.gas_resistance / 1000.0f; // kOhms
|
||||
if (isnan(tC)) tC = bme680.temperature; // SHT40 temp preferred if present
|
||||
if (isnan(rh)) rh = bme680.humidity; // SHT40 humidity preferred if present
|
||||
}
|
||||
} else if (bmpPresent) {
|
||||
bmp280.takeForcedMeasurement();
|
||||
float bt = bmp280.readTemperature(); // degC
|
||||
float bp = bmp280.readPressure() / 100.0f; // hPa
|
||||
if (!isnan(bp)) p = bp;
|
||||
if (isnan(tC) && !isnan(bt)) tC = bt; // fall back to BMP280 temp
|
||||
}
|
||||
|
||||
if (isnan(tC)) return ".../...g...t...";
|
||||
|
||||
String wx = ".../...g...t";
|
||||
wx += tempString((tC + Config.wxsensor.temperatureCorrection) * 1.8f + 32.0f);
|
||||
wx += "h";
|
||||
wx += isnan(rh) ? String("..") : humString(rh);
|
||||
if (!isnan(p)) {
|
||||
wx += "b";
|
||||
wx += presString(p + Config.wxsensor.heightCorrection / WX_CORRECTION_FACTOR);
|
||||
}
|
||||
if (bme680Present && !isnan(gasKohm)) {
|
||||
wx += "Gas: ";
|
||||
wx += String(gasKohm);
|
||||
wx += "Kohms";
|
||||
}
|
||||
return wx;
|
||||
}
|
||||
|
||||
} // namespace Wx
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Lean weather module for the RP2350 iGate on I2C0 (Wire). Auto-detects a
|
||||
// BMP280 (0x76/0x77 -> temperature + barometric pressure) and/or an SHT40
|
||||
// (0x44 -> temperature + relative humidity), and builds the APRS weather field
|
||||
// from whatever is present.
|
||||
namespace Wx {
|
||||
// Probe the BMP280 and SHT40 on Wire (PIN_WX_SDA/PIN_WX_SCL). Safe to call
|
||||
// when no sensor is present — readAprs() then returns "". Call from setup().
|
||||
void setup();
|
||||
|
||||
// True once a BMP280 or SHT40 answered on the bus at setup().
|
||||
bool present();
|
||||
|
||||
// APRS weather payload: ".../...g...t<TTT>[h<HH>][b<PPPPP>]" (temp degF,
|
||||
// humidity %, pressure 0.1 hPa; absent fields omitted). Returns "" if no
|
||||
// sensor was detected. Call from netTask only (single Wire owner).
|
||||
String readAprs();
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "sleep_utils.h"
|
||||
#include "digi_utils.h"
|
||||
#include "lora_utils.h"
|
||||
#include "thermal_utils.h"
|
||||
|
||||
|
||||
extern Configuration Config;
|
||||
@@ -75,6 +76,9 @@ namespace SLEEP_Utils {
|
||||
Serial.print("(Sleeping : "); Serial.print(timeToSleep); Serial.println("seconds)");
|
||||
delay(100);
|
||||
LoRa_Utils::wakeRadio();
|
||||
#ifdef FAN_CTRL_PIN
|
||||
THERMAL_Utils::turnOffFan(); // GPIOs keep their level in light sleep
|
||||
#endif
|
||||
esp_light_sleep_start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +234,7 @@ namespace STATION_Utils {
|
||||
}
|
||||
|
||||
void addToOutputPacketBuffer(const String& packet, bool flag) {
|
||||
if (packet == "") return; // never queue an empty packet
|
||||
outputPacketBuffer.emplace_back(OutputPacketBuffer{packet, flag});
|
||||
}
|
||||
|
||||
|
||||
@@ -71,8 +71,9 @@ namespace TELEMETRY_Utils {
|
||||
void sendBaseTelemetryPacket(const String& prefix, const std::vector<String>& values) {
|
||||
String packet = prefix + joinWithCommas(values);
|
||||
String currentCallsign = (Config.tacticalCallsign != "") ? Config.tacticalCallsign : Config.callsign;
|
||||
String baseRFTelemetryPacket = APRSPacketLib::generateMessagePacket(currentCallsign, "APLRG1", Config.beacon.path, currentCallsign, packet);
|
||||
if (Config.beacon.sendViaAPRSIS) {
|
||||
String baseAPRSISTelemetryPacket = APRSPacketLib::generateMessagePacket(currentCallsign, "APLRG1", "TCPIP,qAC", currentCallsign, packet);
|
||||
String baseAPRSISTelemetryPacket = APRSPacketLib::generateAPRSISPacket(baseRFTelemetryPacket);
|
||||
#ifdef HAS_A7670
|
||||
A7670_Utils::uploadToAPRSIS(baseAPRSISTelemetryPacket);
|
||||
#else
|
||||
@@ -80,7 +81,6 @@ namespace TELEMETRY_Utils {
|
||||
#endif
|
||||
delay(300);
|
||||
} else if (Config.beacon.sendViaRF) {
|
||||
String baseRFTelemetryPacket = APRSPacketLib::generateMessagePacket(currentCallsign, "APLRG1", Config.beacon.path, currentCallsign, packet);
|
||||
LoRa_Utils::sendNewPacket(baseRFTelemetryPacket);
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/* Copyright (C) 2026 Ricardo Guzman - CA2RXU
|
||||
*
|
||||
* This file is part of LoRa APRS iGate.
|
||||
*
|
||||
* LoRa APRS iGate is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LoRa APRS iGate is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Fan / thermal control adapted from KJ7NYE's LoRa_FieldOps_APRS_Tracker (GPLv3)
|
||||
// NTC circuit (T-Beam 1W V1.0 schematic): 3V3 -> NCP18XH103F03RB -> TEMP_PIN -> 10K -> GND
|
||||
|
||||
#include "board_pinout.h"
|
||||
|
||||
#ifdef FAN_CTRL_PIN
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <math.h>
|
||||
#include "thermal_utils.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define NTC_B 3380.0f // B25/50 (K)
|
||||
#define NTC_R25 10000.0f // NTC resistance at 25C (ohm)
|
||||
#define NTC_T0 298.15f // 25C in Kelvin
|
||||
#define NTC_R_FIXED 10000.0f // pull-down resistor (ohm)
|
||||
#define NTC_VCC_MV 3300.0f
|
||||
#define NTC_MIN_VALID_MV 100 // below this the sample is a failed ADC2 read (100mV = ~-45C)
|
||||
|
||||
#define FAN_ON_TEMP 50.0f // fan on at or above
|
||||
#define FAN_OFF_TEMP 42.0f // fan off below (hysteresis)
|
||||
#define TEMP_WARNING 75.0f
|
||||
#define TEMP_TX_BLOCK 85.0f // Tx blocked at or above
|
||||
#define TEMP_TX_UNBLOCK 75.0f // Tx allowed again below (hysteresis)
|
||||
#define TX_COOLDOWN_MS 30000 // fan kept on after TX
|
||||
#define TEMP_SAMPLE_MS 30000
|
||||
|
||||
static float currentTemperature = 25.0f;
|
||||
static bool fanOn = false;
|
||||
static bool txBlocked = false;
|
||||
static bool txCooldownActive = false;
|
||||
static uint32_t txEndTime = 0;
|
||||
static uint32_t lastTempSample = 0;
|
||||
static bool firstTempSample = true;
|
||||
|
||||
|
||||
namespace THERMAL_Utils {
|
||||
|
||||
float readTemperature() { // TEMP_PIN is on ADC2: reads fail (return 0) while Wi-Fi holds the ADC2 arbiter
|
||||
analogReadMilliVolts(TEMP_PIN); // dummy read to settle the ADC
|
||||
delay(1);
|
||||
uint32_t sum = 0;
|
||||
int validSamples = 0;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
uint32_t sample = analogReadMilliVolts(TEMP_PIN);
|
||||
if (sample > NTC_MIN_VALID_MV) {
|
||||
sum += sample;
|
||||
validSamples++;
|
||||
}
|
||||
delay(3);
|
||||
}
|
||||
if (validSamples == 0) return NAN;
|
||||
float mv = (float)sum / validSamples;
|
||||
if (mv >= NTC_VCC_MV) return NAN;
|
||||
float ntcResistance = NTC_R_FIXED * (NTC_VCC_MV - mv) / mv;
|
||||
float kelvin = 1.0f / (1.0f / NTC_T0 + (1.0f / NTC_B) * logf(ntcResistance / NTC_R25));
|
||||
return kelvin - 273.15f;
|
||||
}
|
||||
|
||||
void setFan(bool on, const String& reason) {
|
||||
if (fanOn == on) return;
|
||||
fanOn = on;
|
||||
digitalWrite(FAN_CTRL_PIN, on ? HIGH : LOW);
|
||||
Utils::println("Thermal: Fan " + String(on ? "ON" : "OFF") + " (" + reason + ", " + String(currentTemperature, 1) + " C)");
|
||||
}
|
||||
|
||||
void updateFan() {
|
||||
if (!fanOn) {
|
||||
if (txCooldownActive) {
|
||||
setFan(true, "TX cooldown");
|
||||
} else if (currentTemperature >= FAN_ON_TEMP) {
|
||||
setFan(true, "temperature");
|
||||
}
|
||||
} else if (!txCooldownActive && currentTemperature < FAN_OFF_TEMP) {
|
||||
setFan(false, "cooled down");
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(TEMP_PIN, INPUT);
|
||||
analogSetPinAttenuation(TEMP_PIN, ADC_11db);
|
||||
pinMode(FAN_CTRL_PIN, OUTPUT);
|
||||
digitalWrite(FAN_CTRL_PIN, LOW);
|
||||
fanOn = false;
|
||||
firstTempSample = true; // first monitor() call samples immediately
|
||||
}
|
||||
|
||||
void monitor() {
|
||||
uint32_t now = millis();
|
||||
|
||||
if (txCooldownActive && (now - txEndTime >= TX_COOLDOWN_MS)) {
|
||||
txCooldownActive = false;
|
||||
updateFan();
|
||||
}
|
||||
|
||||
if (!firstTempSample && (now - lastTempSample < TEMP_SAMPLE_MS)) return;
|
||||
firstTempSample = false;
|
||||
lastTempSample = now;
|
||||
|
||||
float temperature = readTemperature();
|
||||
if (!isnan(temperature)) currentTemperature = temperature;
|
||||
|
||||
if (!txBlocked && currentTemperature >= TEMP_TX_BLOCK) {
|
||||
txBlocked = true;
|
||||
Utils::println("Thermal: Over-temperature at " + String(currentTemperature, 1) + " C, Tx blocked");
|
||||
} else if (txBlocked && currentTemperature < TEMP_TX_UNBLOCK) {
|
||||
txBlocked = false;
|
||||
Utils::println("Thermal: Temperature back to " + String(currentTemperature, 1) + " C, Tx allowed");
|
||||
} else if (!txBlocked && currentTemperature >= TEMP_WARNING) {
|
||||
Utils::println("Thermal: High temperature: " + String(currentTemperature, 1) + " C");
|
||||
}
|
||||
updateFan();
|
||||
}
|
||||
|
||||
void onTxStart() {
|
||||
txCooldownActive = false;
|
||||
setFan(true, "TX");
|
||||
}
|
||||
|
||||
void onTxEnd() {
|
||||
txCooldownActive = true;
|
||||
txEndTime = millis();
|
||||
}
|
||||
|
||||
void turnOffFan() { // before sleeping: no Tx while asleep, so the PA doesn't heat up
|
||||
txCooldownActive = false;
|
||||
setFan(false, "sleep");
|
||||
}
|
||||
|
||||
bool isTxBlocked() {
|
||||
return txBlocked;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+56
-59
@@ -27,6 +27,7 @@
|
||||
#include "board_pinout.h"
|
||||
#include "power_utils.h"
|
||||
#include "syslog_utils.h"
|
||||
#include "thermal_utils.h"
|
||||
#include "A7670_utils.h"
|
||||
#include "lora_utils.h"
|
||||
#include "wifi_utils.h"
|
||||
@@ -48,7 +49,7 @@ extern String fourthLine;
|
||||
extern String fifthLine;
|
||||
extern String sixthLine;
|
||||
extern String seventhLine;
|
||||
extern String iGateBeaconPacket;
|
||||
extern String iGateAPRSISBeaconPacket;
|
||||
extern String iGateLoRaBeaconPacket;
|
||||
extern int rssi;
|
||||
extern float snr;
|
||||
@@ -69,8 +70,7 @@ uint32_t lastBeaconTx = 0;
|
||||
uint32_t lastScreenOn = millis();
|
||||
uint32_t lastStatusTx = 0;
|
||||
bool stationCallsignIsValid = false;
|
||||
String beaconPacket;
|
||||
String secondaryBeaconPacket;
|
||||
uint32_t rfBeaconCounter = 0;
|
||||
|
||||
|
||||
namespace Utils {
|
||||
@@ -84,13 +84,13 @@ namespace Utils {
|
||||
return;
|
||||
}
|
||||
|
||||
String statusPacket = APRSPacketLib::generateBasePacket(Config.callsign, "APLRG1", Config.beacon.path);
|
||||
statusPacket += sendOverAPRSIS ? ",qAC:>" : ":>";
|
||||
statusPacket += Config.beacon.statusPacket;
|
||||
String statusCallsign = (Config.tacticalCallsign == "") ? Config.callsign : Config.tacticalCallsign;
|
||||
String statusPacket = APRSPacketLib::generateStatusPacket(statusCallsign, "APLRG1", Config.beacon.path, Config.beacon.statusPacket);
|
||||
|
||||
if (sendOverAPRSIS) {
|
||||
APRS_IS_Utils::upload(statusPacket);
|
||||
SYSLOG_Utils::logAPRSISTx(statusPacket);
|
||||
String aprsisStatusPacket = APRSPacketLib::generateAPRSISPacket(statusPacket);
|
||||
APRS_IS_Utils::upload(aprsisStatusPacket);
|
||||
SYSLOG_Utils::logAPRSISTx(aprsisStatusPacket);
|
||||
} else {
|
||||
STATION_Utils::addToOutputPacketBuffer(statusPacket, true); // treated also as beacon on Tx Freq
|
||||
}
|
||||
@@ -187,48 +187,42 @@ namespace Utils {
|
||||
|
||||
showActiveStations();
|
||||
|
||||
beaconPacket = iGateBeaconPacket;
|
||||
secondaryBeaconPacket = iGateLoRaBeaconPacket;
|
||||
String aprsisBeaconPacket = iGateAPRSISBeaconPacket;
|
||||
String loraBeaconPacket = iGateLoRaBeaconPacket;
|
||||
#ifdef HAS_GPS
|
||||
if (Config.beacon.gpsActive && Config.digi.ecoMode == 0) {
|
||||
GPS_Utils::getData();
|
||||
if (gps.location.isUpdated() && gps.location.lat() != 0.0 && gps.location.lng() != 0.0) {
|
||||
String basePacket = APRSPacketLib::generateBasePacket(Config.callsign, "APLRG1", Config.beacon.path);
|
||||
String encodedGPS = APRSPacketLib::encodeGPSIntoBase91(gps.location.lat(),gps.location.lng(), 0, 0, Config.beacon.symbol, false, 0, true, Config.beacon.ambiguityLevel);
|
||||
String beaconCallsign = (stationCallsignIsValid && Config.tacticalCallsign != "") ? Config.tacticalCallsign : Config.callsign;
|
||||
String encodedGPS = APRSPacketLib::encodeGPSIntoBase91(gps.location.lat(),gps.location.lng(), 0, 0, Config.beacon.symbol, false, 0, true, Config.beacon.ambiguityLevel);
|
||||
|
||||
beaconPacket = basePacket;
|
||||
beaconPacket += ",qAC:!";
|
||||
beaconPacket += Config.beacon.overlay;
|
||||
beaconPacket += encodedGPS;
|
||||
|
||||
secondaryBeaconPacket = basePacket;
|
||||
secondaryBeaconPacket += ":=";
|
||||
secondaryBeaconPacket += Config.beacon.overlay;
|
||||
secondaryBeaconPacket += encodedGPS;
|
||||
loraBeaconPacket = APRSPacketLib::generateBase91GPSBeaconPacket(beaconCallsign, "APLRG1", Config.beacon.path, Config.beacon.overlay, encodedGPS);
|
||||
aprsisBeaconPacket = APRSPacketLib::generateAPRSISPacket(loraBeaconPacket);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (Config.wxsensor.active) {
|
||||
String sensorData = (wxModuleType == 0) ? ".../...g...t..." : WX_Utils::readDataSensor();
|
||||
beaconPacket += sensorData;
|
||||
secondaryBeaconPacket += sensorData;
|
||||
aprsisBeaconPacket += sensorData;
|
||||
loraBeaconPacket += sensorData;
|
||||
}
|
||||
beaconPacket += Config.beacon.comment;
|
||||
secondaryBeaconPacket += Config.beacon.comment;
|
||||
aprsisBeaconPacket += Config.beacon.comment; // APRS-IS beacon always carries the comment
|
||||
int commentEveryX = max(1, Config.beacon.rfCommentEveryXBeacons); // safety: 0 or negative behaves as "every beacon"
|
||||
if (rfBeaconCounter % commentEveryX == 0) loraBeaconPacket += Config.beacon.comment;
|
||||
if (stationCallsignIsValid && Config.tacticalCallsign != "") {
|
||||
beaconPacket += " de ";
|
||||
beaconPacket += Config.callsign;
|
||||
secondaryBeaconPacket += " de ";
|
||||
secondaryBeaconPacket += Config.callsign;
|
||||
aprsisBeaconPacket += " de ";
|
||||
aprsisBeaconPacket += Config.callsign;
|
||||
loraBeaconPacket += " de ";
|
||||
loraBeaconPacket += Config.callsign;
|
||||
}
|
||||
|
||||
#if defined(BATTERY_PIN) || defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||
if (Config.battery.sendInternalVoltage || Config.battery.monitorInternalVoltage) {
|
||||
float internalVoltage = BATTERY_Utils::checkInternalVoltage();
|
||||
if (Config.battery.monitorInternalVoltage && internalVoltage < Config.battery.internalSleepVoltage) {
|
||||
beaconPacket += " **IntBatWarning:SLEEP**";
|
||||
secondaryBeaconPacket += " **IntBatWarning:SLEEP**";
|
||||
aprsisBeaconPacket += " **IntBattWarning:SLEEP**";
|
||||
loraBeaconPacket += " **IntBattWarning:SLEEP**";
|
||||
shouldSleepLowVoltage = true;
|
||||
}
|
||||
|
||||
@@ -241,10 +235,10 @@ namespace Utils {
|
||||
sixthLine = sixthLineBuffer;
|
||||
|
||||
if (!Config.battery.sendVoltageAsTelemetry) {
|
||||
beaconPacket += " Batt=";
|
||||
beaconPacket += internalVoltageInfo;
|
||||
secondaryBeaconPacket += " Batt=";
|
||||
secondaryBeaconPacket += internalVoltageInfo;
|
||||
aprsisBeaconPacket += " Batt=";
|
||||
aprsisBeaconPacket += internalVoltageInfo;
|
||||
loraBeaconPacket += " Batt=";
|
||||
loraBeaconPacket += internalVoltageInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,8 +248,8 @@ namespace Utils {
|
||||
if (Config.battery.sendExternalVoltage || Config.battery.monitorExternalVoltage) {
|
||||
float externalVoltage = BATTERY_Utils::checkExternalVoltage();
|
||||
if (Config.battery.monitorExternalVoltage && externalVoltage < Config.battery.externalSleepVoltage) {
|
||||
beaconPacket += " **ExtBatWarning:SLEEP**";
|
||||
secondaryBeaconPacket += " **ExtBatWarning:SLEEP**";
|
||||
aprsisBeaconPacket += " **ExtBattWarning:SLEEP**";
|
||||
loraBeaconPacket += " **ExtBattWarning:SLEEP**";
|
||||
shouldSleepLowVoltage = true;
|
||||
}
|
||||
|
||||
@@ -268,10 +262,10 @@ namespace Utils {
|
||||
sixthLine = sixthLineBuffer;
|
||||
|
||||
if (!Config.battery.sendVoltageAsTelemetry) {
|
||||
beaconPacket += " Ext=";
|
||||
beaconPacket += externalVoltageInfo;
|
||||
secondaryBeaconPacket += " Ext=";
|
||||
secondaryBeaconPacket += externalVoltageInfo;
|
||||
aprsisBeaconPacket += " Ext=";
|
||||
aprsisBeaconPacket += externalVoltageInfo;
|
||||
loraBeaconPacket += " Ext=";
|
||||
loraBeaconPacket += externalVoltageInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -279,8 +273,8 @@ namespace Utils {
|
||||
|
||||
if (Config.battery.sendVoltageAsTelemetry && !Config.wxsensor.active && (Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage)){
|
||||
String encodedTelemetry = TELEMETRY_Utils::generateEncodedTelemetry();
|
||||
beaconPacket += encodedTelemetry;
|
||||
secondaryBeaconPacket += encodedTelemetry;
|
||||
aprsisBeaconPacket += encodedTelemetry;
|
||||
loraBeaconPacket += encodedTelemetry;
|
||||
}
|
||||
|
||||
if (Config.beacon.sendViaAPRSIS && Config.aprs_is.active && passcodeValid && !backupDigiMode) {
|
||||
@@ -288,18 +282,19 @@ namespace Utils {
|
||||
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING IGATE BEACON", 0);
|
||||
seventhLine = " listening...";
|
||||
#ifdef HAS_A7670
|
||||
A7670_Utils::uploadToAPRSIS(beaconPacket);
|
||||
A7670_Utils::uploadToAPRSIS(aprsisBeaconPacket);
|
||||
#else
|
||||
APRS_IS_Utils::upload(beaconPacket);
|
||||
APRS_IS_Utils::upload(aprsisBeaconPacket);
|
||||
#endif
|
||||
if (Config.syslog.logBeaconOverTCPIP) SYSLOG_Utils::logAPRSISTx(beaconPacket);
|
||||
if (Config.syslog.logBeaconOverTCPIP) SYSLOG_Utils::logAPRSISTx(aprsisBeaconPacket);
|
||||
}
|
||||
|
||||
if (Config.beacon.sendViaRF || backupDigiMode) {
|
||||
Utils::println("-- Sending Beacon to RF --");
|
||||
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING DIGI BEACON", 0);
|
||||
seventhLine = " listening...";
|
||||
STATION_Utils::addToOutputPacketBuffer(secondaryBeaconPacket, true);
|
||||
STATION_Utils::addToOutputPacketBuffer(loraBeaconPacket, true);
|
||||
rfBeaconCounter++;
|
||||
}
|
||||
|
||||
lastBeaconTx = millis();
|
||||
@@ -329,6 +324,12 @@ namespace Utils {
|
||||
}
|
||||
}
|
||||
|
||||
String padForDisplay(const String& text) { // left-aligned, 9 chars wide (callsign column on screen)
|
||||
char buffer[10];
|
||||
snprintf(buffer, sizeof(buffer), "%-9s", text.c_str());
|
||||
return String(buffer);
|
||||
}
|
||||
|
||||
void updateLoRaPacketDisplayInfo(APRSPacket& aprsPacket, const uint8_t packetType) {
|
||||
switch (packetType) {
|
||||
case 0: // LoRa-APRS
|
||||
@@ -339,11 +340,7 @@ namespace Utils {
|
||||
break;
|
||||
}
|
||||
|
||||
String sender = aprsPacket.sender;
|
||||
for (int i = sender.length(); i < 9; i++) {
|
||||
sender += " ";
|
||||
}
|
||||
sixthLine = sender;
|
||||
sixthLine = padForDisplay(aprsPacket.sender);
|
||||
|
||||
switch (aprsPacket.type) {
|
||||
case 1: // MESSAGE
|
||||
@@ -389,11 +386,7 @@ namespace Utils {
|
||||
void updateAPRSISPacketDisplayInfo(const String& packet) {
|
||||
fifthLine = "APRS-IS ----> LoRa Tx";
|
||||
|
||||
String sender = packet.substring(0,packet.indexOf(">"));
|
||||
for (int i = sender.length(); i < 9; i++) {
|
||||
sender += " ";
|
||||
}
|
||||
sixthLine = sender;
|
||||
sixthLine = padForDisplay(packet.substring(0,packet.indexOf(">")));
|
||||
|
||||
if (packet.indexOf("::") > 0) {
|
||||
sixthLine += "> MESSAGE";
|
||||
@@ -435,15 +428,19 @@ namespace Utils {
|
||||
if (mode == 0) { // at startup
|
||||
delay(3000);
|
||||
}
|
||||
Serial.println("\n\n*** Sleeping Low Battey Voltage ***\n\n");
|
||||
Serial.println("\n\n*** Sleeping Low Battery Voltage ***\n\n");
|
||||
esp_sleep_enable_timer_wakeup(30 * 60 * 1000000); // sleep 30 min
|
||||
if (mode == 1) { // low voltage detected after a while
|
||||
displayToggle(false);
|
||||
}
|
||||
#ifdef VEXT_CTRL_PIN
|
||||
digitalWrite(VEXT_CTRL_PIN, !VEXT_CTRL_ON_STATE); // VEXT off before deep sleep (always, regardless of ecoMode)
|
||||
POWER_Utils::vext_ctrl_OFF(); // VEXT off before deep sleep (always, regardless of ecoMode)
|
||||
#endif
|
||||
#ifdef FAN_CTRL_PIN
|
||||
THERMAL_Utils::turnOffFan();
|
||||
#endif
|
||||
LoRa_Utils::sleepRadio();
|
||||
POWER_Utils::deactivateGPS(); // GPS rail off (AXP boards), otherwise it keeps draining the low battery while sleeping
|
||||
#ifdef RADIO_VCC_PIN
|
||||
digitalWrite(RADIO_VCC_PIN, LOW); // cut LoRa module power (QRP Labs LightGateway) so it draws nothing while sleeping
|
||||
#endif
|
||||
|
||||
+4
-1
@@ -19,6 +19,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include "network_manager.h"
|
||||
#include "configuration.h"
|
||||
#include "lora_utils.h"
|
||||
#include "ota_utils.h"
|
||||
#include "web_utils.h"
|
||||
#include "map_utils.h"
|
||||
@@ -233,6 +234,7 @@ namespace WEB_Utils {
|
||||
if (Config.aprs_is.active) {
|
||||
Config.aprs_is.messagesToRF = request->hasParam("aprs_is.messagesToRF", true);
|
||||
Config.aprs_is.objectsToRF = request->hasParam("aprs_is.objectsToRF", true);
|
||||
Config.aprs_is.is2Metadata = request->hasParam("aprs_is.is2Metadata", true);
|
||||
Config.aprs_is.server = getParamStringSafe("aprs_is.server", Config.aprs_is.server);
|
||||
Config.aprs_is.passcode = getParamStringSafe("aprs_is.passcode", Config.aprs_is.passcode);
|
||||
Config.aprs_is.port = getParamIntSafe("aprs_is.port", Config.aprs_is.port);
|
||||
@@ -246,6 +248,7 @@ namespace WEB_Utils {
|
||||
Config.beacon.latitude = getParamDoubleSafe("beacon.latitude", Config.beacon.latitude);
|
||||
Config.beacon.longitude = getParamDoubleSafe("beacon.longitude", Config.beacon.longitude);
|
||||
Config.beacon.comment = getParamStringSafe("beacon.comment", Config.beacon.comment);
|
||||
Config.beacon.rfCommentEveryXBeacons = getParamIntSafe("beacon.rfCommentEveryXBeacons", Config.beacon.rfCommentEveryXBeacons);
|
||||
Config.beacon.overlay = getParamStringSafe("beacon.overlay", Config.beacon.overlay);
|
||||
Config.beacon.symbol = getParamStringSafe("beacon.symbol", Config.beacon.symbol);
|
||||
Config.beacon.path = getParamStringSafe("beacon.path", Config.beacon.path);
|
||||
@@ -276,7 +279,7 @@ namespace WEB_Utils {
|
||||
Config.loramodule.txSpreadingFactor = getParamIntSafe("lora.txSpreadingFactor", Config.loramodule.txSpreadingFactor);
|
||||
Config.loramodule.txCodingRate4 = getParamIntSafe("lora.txCodingRate4", Config.loramodule.txCodingRate4);
|
||||
Config.loramodule.txSignalBandwidth = getParamIntSafe("lora.txSignalBandwidth", Config.loramodule.txSignalBandwidth);
|
||||
Config.loramodule.power = getParamIntSafe("lora.power", Config.loramodule.power);
|
||||
Config.loramodule.power = LoRa_Utils::validPower(getParamIntSafe("lora.power", Config.loramodule.power)); // saved as the power the radio chip really uses
|
||||
if (Config.loramodule.txActive)
|
||||
Config.loramodule.cadActive = request->hasParam("lora.cadActive", true);
|
||||
|
||||
|
||||
+4
-4
@@ -49,12 +49,12 @@ namespace WIFI_Utils {
|
||||
uint32_t currentTime = millis();
|
||||
|
||||
if (backupDigiMode) {
|
||||
if (!networkManager->isWiFiConnected() && ((currentTime - lastBackupDigiTime) >= 15 * 60 * 1000)) {
|
||||
Serial.println("*** Stopping BackUp Digi Mode ***");
|
||||
if (lastServerCheck > lastBackupDigiTime) { // APRS-IS server spoke after entering backup (with or without a WiFi drop)
|
||||
Serial.println("*** APRS-IS Server Back (Stopping Backup Digi Mode) ***");
|
||||
backupDigiMode = false;
|
||||
wifiCounter = 0;
|
||||
} else if (networkManager->isWiFiConnected()) {
|
||||
Serial.println("*** WiFi Reconnect Success (Stopping Backup Digi Mode) ***");
|
||||
} else if (!networkManager->isWiFiConnected() && ((currentTime - lastBackupDigiTime) >= 15 * 60 * 1000)) {
|
||||
Serial.println("*** Stopping BackUp Digi Mode ***"); // no WiFi for 15 min: leave backup to retry WiFi
|
||||
backupDigiMode = false;
|
||||
wifiCounter = 0;
|
||||
}
|
||||
|
||||
+13
-10
@@ -35,16 +35,19 @@ files = [
|
||||
]
|
||||
|
||||
string_to_find_str = "String"
|
||||
string_to_find_ver = "versionDate"
|
||||
|
||||
with open('src/LoRa_APRS_iGate.cpp', encoding='utf-8') as cpp_file:
|
||||
for line in cpp_file:
|
||||
if string_to_find_str in line and string_to_find_ver in line:
|
||||
start = line.find('"') + 1
|
||||
end = line.find('"', start)
|
||||
if start > 0 and end > start:
|
||||
versionDate = line[start:end]
|
||||
break
|
||||
def find_string_value(variable_name):
|
||||
with open('src/LoRa_APRS_iGate.cpp', encoding='utf-8') as cpp_file:
|
||||
for line in cpp_file:
|
||||
if string_to_find_str in line and variable_name in line:
|
||||
start = line.find('"') + 1
|
||||
end = line.find('"', start)
|
||||
if start > 0 and end > start:
|
||||
return line[start:end]
|
||||
return ""
|
||||
|
||||
versionDate = find_string_value("versionDate")
|
||||
versionNumber = find_string_value("versionNumber")
|
||||
|
||||
for src in files:
|
||||
out = src + ".gz"
|
||||
@@ -54,7 +57,7 @@ for src in files:
|
||||
content = f.read()
|
||||
|
||||
if src == 'data_embed/index.html':
|
||||
env_vars = env["BOARD"] + "<br>" + ','.join(env["BUILD_FLAGS"]).replace('-Werror -Wall,', '').replace(',-DELEGANTOTA_USE_ASYNC_WEBSERVER=1', '') + "<br>" + "Version date: " + versionDate
|
||||
env_vars = env["BOARD"] + "<br>" + ','.join(env["BUILD_FLAGS"]).replace('-Werror -Wall,', '').replace(',-DELEGANTOTA_USE_ASYNC_WEBSERVER=1', '') + "<br>" + "Version: " + versionNumber + "<br>" + "Version date: " + versionDate
|
||||
current_date = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') + " UTC"
|
||||
build_info = f'{env_vars}<br>Build date: {current_date}'.encode()
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env python3
|
||||
# Generates web_assets.h from data_embed/* for the RP2350 iGate build: each SPA
|
||||
# asset is gzipped and embedded as a byte array that eth_web.cpp serves with
|
||||
# Content-Encoding: gzip.
|
||||
#
|
||||
# It is the RP2350 counterpart of tools/compress.py and runs the same way, as a
|
||||
# PlatformIO pre: script of every RP2350 env, so the web is rebuilt from
|
||||
# data_embed/* on every build. The header goes to the build directory, never to
|
||||
# src/. Run by hand it only writes a preview to .pio/web_assets_preview/:
|
||||
#
|
||||
# python tools/gen_web_assets_rp2350.py
|
||||
|
||||
import base64
|
||||
import gzip
|
||||
import os
|
||||
import datetime
|
||||
import re
|
||||
|
||||
# The page and everything it loads at start-up go out as ONE response: the
|
||||
# stylesheets, scripts and favicon index.html links are inlined into it. The
|
||||
# W5100S has 4 sockets and APRS-IS and syslog keep two of them open (NTP takes a
|
||||
# third while it syncs), so the web server can only take a connection or two at
|
||||
# a time; the six parallel requests a
|
||||
# browser fires for separate .css/.js files got reset (ERR_CONNECTION_REFUSED),
|
||||
# and a lost script.js left the bare page with no settings loaded until a reload.
|
||||
INLINE_CSS = ["bootstrap.css", "style.css", "leaflet.css"]
|
||||
INLINE_JS = ["bootstrap.js", "leaflet.js", "script.js"]
|
||||
FAVICON = "favicon.png"
|
||||
|
||||
# (url path, source file, C array name, content-type)
|
||||
ASSETS = [
|
||||
("/", "index.html", "asset_index_html", "text/html"),
|
||||
("/aprs-symbols-24-0.png", "aprs-symbols-24-0.png", "asset_sym24_0", "image/png"),
|
||||
("/aprs-symbols-24-1.png", "aprs-symbols-24-1.png", "asset_sym24_1", "image/png"),
|
||||
("/aprs-symbols-24-2.png", "aprs-symbols-24-2.png", "asset_sym24_2", "image/png"),
|
||||
]
|
||||
|
||||
def build_info():
|
||||
when = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S") + " UTC"
|
||||
return f"RP2350 LoRa iGate — Build date: {when}"
|
||||
|
||||
def read_embed(fname):
|
||||
with open(os.path.join(ROOT, "data_embed", fname), "rb") as f:
|
||||
return f.read()
|
||||
|
||||
def strip_source_map(content):
|
||||
# the .map files are not embedded: drop the reference so devtools don't 404 on it
|
||||
return re.sub(rb"\n?/[/*]# sourceMappingURL=[^\n]*", b"", content)
|
||||
|
||||
def replace_once(html, old, new):
|
||||
if html.count(old) != 1:
|
||||
raise SystemExit(f"index.html: expected exactly one {old.decode()!r}")
|
||||
return html.replace(old, new)
|
||||
|
||||
def inline_page(html):
|
||||
for fname in INLINE_CSS:
|
||||
css = strip_source_map(read_embed(fname))
|
||||
if b"</style" in css.lower():
|
||||
raise SystemExit(f"{fname}: contains </style, cannot be inlined")
|
||||
html = replace_once(html, f'<link rel="stylesheet" href="/{fname}" />'.encode(),
|
||||
b"<style>\n" + css + b"\n</style>")
|
||||
for fname in INLINE_JS:
|
||||
js = strip_source_map(read_embed(fname))
|
||||
if b"</script" in js.lower() or b"<!--" in js: # would end / confuse the inline <script>
|
||||
raise SystemExit(f"{fname}: contains </script or <!--, cannot be inlined")
|
||||
html = replace_once(html, f'<script src="/{fname}"></script>'.encode(),
|
||||
b"<script>\n" + js + b"\n</script>")
|
||||
icon = base64.b64encode(read_embed(FAVICON))
|
||||
html = replace_once(html, f'<link rel="icon" href="/{FAVICON}" type="image/x-icon">'.encode(),
|
||||
b'<link rel="icon" href="data:image/png;base64,' + icon + b'" type="image/png">')
|
||||
return html
|
||||
|
||||
def main(out):
|
||||
lines = [
|
||||
"#pragma once",
|
||||
"// AUTO-GENERATED at build time from data_embed/* by tools/gen_web_assets_rp2350.py — do not edit.",
|
||||
"// Gzipped SPA assets embedded in flash; served with Content-Encoding: gzip.",
|
||||
"#include <Arduino.h>",
|
||||
"#include <stddef.h>",
|
||||
"",
|
||||
]
|
||||
for _, fname, arr, _ctype in ASSETS:
|
||||
content = read_embed(fname)
|
||||
if fname == "index.html":
|
||||
content = content.replace(b"%BUILD_INFO%", build_info().encode())
|
||||
content = inline_page(content)
|
||||
gz = gzip.compress(content, compresslevel=9, mtime=0)
|
||||
body = ",".join(str(b) for b in gz)
|
||||
lines.append(f"static const uint8_t {arr}[] = {{{body}}};")
|
||||
print(f" {fname:16s} {len(content):7d} -> {len(gz):7d} B gz")
|
||||
lines.append("")
|
||||
lines.append("struct WebAsset { const char *path; const uint8_t *data; size_t len; const char *ctype; };")
|
||||
lines.append("static const WebAsset WEB_ASSETS[] = {")
|
||||
for path, _f, arr, ctype in ASSETS:
|
||||
lines.append(f' {{ "{path}", {arr}, sizeof({arr}), "{ctype}" }},')
|
||||
lines.append("};")
|
||||
lines.append("static const size_t WEB_ASSETS_N = sizeof(WEB_ASSETS)/sizeof(WEB_ASSETS[0]);")
|
||||
lines.append("")
|
||||
|
||||
os.makedirs(os.path.dirname(out), exist_ok=True)
|
||||
with open(out, "w", encoding="utf-8", newline="\n") as f:
|
||||
f.write("\n".join(lines))
|
||||
print(f"wrote {out} ({os.path.getsize(out)} bytes)")
|
||||
|
||||
try:
|
||||
Import("env") # run by PlatformIO (extra_scripts = pre:...)
|
||||
except NameError:
|
||||
env = None
|
||||
|
||||
if env is not None:
|
||||
# PlatformIO does not set __file__ for extra scripts: take the paths from the env
|
||||
ROOT = env.subst("$PROJECT_DIR")
|
||||
out_dir = os.path.join(env.subst("$BUILD_DIR"), "web_assets")
|
||||
env.Append(CPPPATH=[out_dir])
|
||||
main(os.path.join(out_dir, "web_assets.h"))
|
||||
elif __name__ == "__main__":
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
main(os.path.join(ROOT, ".pio", "web_assets_preview", "web_assets.h"))
|
||||
@@ -9,4 +9,4 @@ build_flags =
|
||||
lib_deps =
|
||||
${common.lib_deps}
|
||||
${common.display_libs}
|
||||
adafruit/Adafruit SH110X @ 2.1.10
|
||||
adafruit/Adafruit SH110X @ 2.1.15
|
||||
@@ -11,4 +11,4 @@ build_flags =
|
||||
lib_deps =
|
||||
${common.lib_deps}
|
||||
${common.display_libs}
|
||||
adafruit/Adafruit SHTC3 Library @ 1.0.1
|
||||
adafruit/Adafruit SHTC3 Library @ 1.0.2
|
||||
@@ -0,0 +1,61 @@
|
||||
/* Copyright (C) 2026 Ricardo Guzman - CA2RXU
|
||||
*
|
||||
* This file is part of LoRa APRS iGate.
|
||||
*
|
||||
* LoRa APRS iGate is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LoRa APRS iGate is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BOARD_PINOUT_H_
|
||||
#define BOARD_PINOUT_H_
|
||||
|
||||
// Raspberry Pi Pico 2 + W5500 Ethernet module + Ebyte E22 / E22P
|
||||
// Hardware: https://github.com/cvaldess/Pico2_W5500_E22
|
||||
// pico2_w5500_e22, wiznet_5500_evb_pico2_e22p and wiznet_5100s_evb_pico2_e22p
|
||||
// share this pinout: only the Ethernet chip and where it sits change.
|
||||
|
||||
// LoRa Radio: E22 / E22P, 433 or 868/915 MHz (SX1268 or SX1262, detected at boot)
|
||||
#define HAS_SX1262
|
||||
#define HAS_1W_LORA
|
||||
#define HAS_TCXO
|
||||
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
|
||||
#define RADIO_SCLK_PIN 10
|
||||
#define RADIO_MOSI_PIN 11
|
||||
#define RADIO_MISO_PIN 12
|
||||
#define RADIO_CS_PIN 13
|
||||
#define RADIO_DIO1_PIN 14
|
||||
#define RADIO_RST_PIN 15
|
||||
#define RADIO_BUSY_PIN 2
|
||||
#define RADIO_RXEN 3 // RF enable, held HIGH while the radio is active
|
||||
|
||||
// TXEN: the DIO2-TXEN jumper ships fitted, so DIO2 keys the PA and no GPIO is
|
||||
// needed. With the jumper moved, TXEN is on GPIO6: build with -D RADIO_TXEN=6.
|
||||
#ifndef RADIO_TXEN
|
||||
#define RADIO_TXEN -1
|
||||
#endif
|
||||
|
||||
// Ethernet (SPI0)
|
||||
#define PIN_ETH_MISO 16
|
||||
#define PIN_ETH_CS 17
|
||||
#define PIN_ETH_SCK 18
|
||||
#define PIN_ETH_MOSI 19
|
||||
#define PIN_ETH_RST 20
|
||||
|
||||
// I2C: WX sensors (SHT40 on the carrier, STEMMA QT connector)
|
||||
#define PIN_WX_SDA 4
|
||||
#define PIN_WX_SCL 5
|
||||
|
||||
// VSYS monitor (GP29 = VSYS/3): this board's divider reads low
|
||||
#define VSYS_CAL 1.69f
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
; Raspberry Pi Pico 2 + W5500 Ethernet module + Ebyte E22 / E22P
|
||||
; Hardware: https://github.com/cvaldess/Pico2_W5500_E22
|
||||
; RP2350 boards build src/rp2350/ plus the sources they share with the ESP32
|
||||
; boards (configuration, KISS, map). Library versions as in common_settings.ini.
|
||||
[env:pico2_w5500_e22]
|
||||
platform = https://github.com/maxgerhardt/platform-raspberrypi.git#4e22a0dcdd94eead72fdf56ea59a3d7c8aa2f379
|
||||
board = rpipico2
|
||||
board_build.core = earlephilhower
|
||||
board_build.filesystem_size = 0.75m ; also the OTA ceiling: arduino-pico stages the new image in LittleFS
|
||||
board_build.embed_files =
|
||||
board_build.partitions =
|
||||
extra_scripts = pre:tools/gen_web_assets_rp2350.py
|
||||
build_src_filter = -<*> +<rp2350/> +<configuration.cpp> +<kiss_utils.cpp> +<map_utils.cpp>
|
||||
build_flags =
|
||||
${common.build_flags}
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_FREERTOS
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_EXCEPTIONS
|
||||
-D RADIOLIB_LOW_LEVEL=1 ; getMod() for the SX126x RX-sensitivity patch
|
||||
-D PICO2_W5500_E22
|
||||
build_unflags =
|
||||
-Werror ; arduino-pico's GCC flags sign-compare in shared sources that the ESP32 one accepts
|
||||
lib_deps =
|
||||
arduino-libraries/Ethernet @ 2.0.2
|
||||
bblanchon/ArduinoJson @ 7.4.3
|
||||
jgromes/RadioLib @ 7.6.0
|
||||
knolleary/PubSubClient @ 2.8
|
||||
mikalhart/TinyGPSPlus @ 1.1.0
|
||||
richonguzman/APRSPacketLib @ 1.0.10
|
||||
adafruit/Adafruit Unified Sensor @ 1.1.15
|
||||
adafruit/Adafruit BMP280 Library @ 3.0.0
|
||||
adafruit/Adafruit BME680 Library @ 2.0.6
|
||||
debug_tool = cmsis-dap
|
||||
@@ -0,0 +1,65 @@
|
||||
/* Copyright (C) 2026 Ricardo Guzman - CA2RXU
|
||||
*
|
||||
* This file is part of LoRa APRS iGate.
|
||||
*
|
||||
* LoRa APRS iGate is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LoRa APRS iGate is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BOARD_PINOUT_H_
|
||||
#define BOARD_PINOUT_H_
|
||||
|
||||
// LoRa Radio
|
||||
#define HAS_SX1262
|
||||
#define HAS_1W_LORA
|
||||
#define HAS_TCXO
|
||||
#define RADIO_VCC_PIN 40 // (RADIO_LDO_EN_PIN) HIGH = turn on the radio, LOW = turns off the radio
|
||||
#define RADIO_SCLK_PIN 13
|
||||
#define RADIO_MISO_PIN 12
|
||||
#define RADIO_MOSI_PIN 11
|
||||
#define RADIO_CS_PIN 15
|
||||
#define RADIO_RST_PIN 3
|
||||
#define RADIO_DIO1_PIN 1
|
||||
#define RADIO_BUSY_PIN 38
|
||||
#define RADIO_RXEN 21 // (RADIO_CTRL_PIN) HIGH = LNA on (Rx), LOW = LNA off (Tx)
|
||||
#define RADIO_WAKEUP_PIN RADIO_DIO1_PIN
|
||||
#define GPIO_WAKEUP_PIN GPIO_SEL_1
|
||||
|
||||
// I2C
|
||||
#define USE_WIRE_WITH_OLED_PINS
|
||||
|
||||
// Display
|
||||
#define HAS_DISPLAY
|
||||
#define HAS_SH1106
|
||||
|
||||
#undef OLED_SDA
|
||||
#undef OLED_SCL
|
||||
#undef OLED_RST
|
||||
|
||||
#define OLED_SDA 8
|
||||
#define OLED_SCL 9
|
||||
#define OLED_RST -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||
|
||||
// Aditional Config
|
||||
#define BATTERY_PIN 4
|
||||
#define BATTERY_CELLS 2 // 7.4V 2S battery
|
||||
#define BUTTON_PIN 0
|
||||
#define TEMP_PIN 14 // NTC Temperature sensor
|
||||
#define FAN_CTRL_PIN 41
|
||||
|
||||
// GPS
|
||||
#define HAS_GPS
|
||||
#define GPS_RX 6
|
||||
#define GPS_TX 5
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
[env:ttgo-t-beam-1W]
|
||||
board = esp32-s3-devkitm-1
|
||||
board_build.mcu = esp32s3
|
||||
board_build.flash_size = 16MB
|
||||
board_build.flash_mode = qio
|
||||
board_build.arduino.memory_type = qio_opi
|
||||
board_upload.flash_size = 16MB
|
||||
board_upload.maximum_size = 16777216
|
||||
board_build.psram_type = opi
|
||||
build_flags =
|
||||
${common.build_flags}
|
||||
${common.usb_flags}
|
||||
-D RADIOLIB_EXCLUDE_LR11X0=1
|
||||
-D RADIOLIB_EXCLUDE_SX127X=1
|
||||
-D RADIOLIB_EXCLUDE_SX128X=1
|
||||
-D TTGO_T_BEAM_1W
|
||||
-D BOARD_HAS_PSRAM
|
||||
lib_deps =
|
||||
${common.lib_deps}
|
||||
${common.display_libs}
|
||||
adafruit/Adafruit SH110X @ 2.1.15
|
||||
@@ -12,4 +12,4 @@ lib_deps =
|
||||
${common.lib_deps}
|
||||
${common.display_libs}
|
||||
lewisxhe/XPowersLib @ 0.2.4
|
||||
adafruit/Adafruit SH110X @ 2.1.10
|
||||
adafruit/Adafruit SH110X @ 2.1.15
|
||||
@@ -0,0 +1,58 @@
|
||||
/* Copyright (C) 2026 Ricardo Guzman - CA2RXU
|
||||
*
|
||||
* This file is part of LoRa APRS iGate.
|
||||
*
|
||||
* LoRa APRS iGate is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LoRa APRS iGate is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BOARD_PINOUT_H_
|
||||
#define BOARD_PINOUT_H_
|
||||
|
||||
// WIZnet W5100S-EVB-Pico2 (RP2350 + W5100S on board) + Ebyte E22 / E22P carrier
|
||||
// Hardware: https://github.com/cvaldess/Wiznet_5500_EVB_Pico2_E22P
|
||||
// pico2_w5500_e22, wiznet_5500_evb_pico2_e22p and wiznet_5100s_evb_pico2_e22p
|
||||
// share this pinout: only the Ethernet chip and where it sits change.
|
||||
|
||||
// LoRa Radio: E22 / E22P, 433 or 868/915 MHz (SX1268 or SX1262, detected at boot)
|
||||
#define HAS_SX1262
|
||||
#define HAS_1W_LORA
|
||||
#define HAS_TCXO
|
||||
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
|
||||
#define RADIO_SCLK_PIN 10
|
||||
#define RADIO_MOSI_PIN 11
|
||||
#define RADIO_MISO_PIN 12
|
||||
#define RADIO_CS_PIN 13
|
||||
#define RADIO_DIO1_PIN 14
|
||||
#define RADIO_RST_PIN 15
|
||||
#define RADIO_BUSY_PIN 2
|
||||
#define RADIO_RXEN 3 // RF enable, held HIGH while the radio is active
|
||||
|
||||
// TXEN: the DIO2-TXEN jumper ships fitted, so DIO2 keys the PA and no GPIO is
|
||||
// needed. With the jumper moved, TXEN is on GPIO6: build with -D RADIO_TXEN=6.
|
||||
#ifndef RADIO_TXEN
|
||||
#define RADIO_TXEN -1
|
||||
#endif
|
||||
|
||||
// Ethernet (SPI0)
|
||||
#define PIN_ETH_MISO 16
|
||||
#define PIN_ETH_CS 17
|
||||
#define PIN_ETH_SCK 18
|
||||
#define PIN_ETH_MOSI 19
|
||||
#define PIN_ETH_RST 20
|
||||
|
||||
// I2C: WX sensors (SHT40 on the carrier, STEMMA QT connector)
|
||||
#define PIN_WX_SDA 4
|
||||
#define PIN_WX_SCL 5
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
; WIZnet W5100S-EVB-Pico2 (RP2350 + W5100S on board) + Ebyte E22 / E22P carrier
|
||||
; Hardware: https://github.com/cvaldess/Wiznet_5500_EVB_Pico2_E22P
|
||||
; RP2350 boards build src/rp2350/ plus the sources they share with the ESP32
|
||||
; boards (configuration, KISS, map). Library versions as in common_settings.ini.
|
||||
[env:wiznet_5100s_evb_pico2_e22p]
|
||||
platform = https://github.com/maxgerhardt/platform-raspberrypi.git#4e22a0dcdd94eead72fdf56ea59a3d7c8aa2f379
|
||||
board = wiznet_5100s_evb_pico2
|
||||
board_build.core = earlephilhower
|
||||
board_build.filesystem_size = 0.75m ; also the OTA ceiling: arduino-pico stages the new image in LittleFS
|
||||
board_build.embed_files =
|
||||
board_build.partitions =
|
||||
extra_scripts = pre:tools/gen_web_assets_rp2350.py
|
||||
build_src_filter = -<*> +<rp2350/> +<configuration.cpp> +<kiss_utils.cpp> +<map_utils.cpp>
|
||||
build_flags =
|
||||
${common.build_flags}
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_FREERTOS
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_EXCEPTIONS
|
||||
-D RADIOLIB_LOW_LEVEL=1 ; getMod() for the SX126x RX-sensitivity patch
|
||||
-D WIZNET_5100S_EVB_PICO2_E22P
|
||||
-D USE_W5100S ; RAK13800-W5100S driver (same Ethernet API)
|
||||
-I src/rp2350/compat_w5100s ; <Ethernet.h> shim that pulls that driver
|
||||
build_unflags =
|
||||
-Werror ; arduino-pico's GCC flags sign-compare in shared sources that the ESP32 one accepts
|
||||
lib_deps =
|
||||
https://github.com/RAKWireless/RAK13800-W5100S/archive/1.0.2.zip
|
||||
bblanchon/ArduinoJson @ 7.4.3
|
||||
jgromes/RadioLib @ 7.6.0
|
||||
knolleary/PubSubClient @ 2.8
|
||||
mikalhart/TinyGPSPlus @ 1.1.0
|
||||
richonguzman/APRSPacketLib @ 1.0.10
|
||||
adafruit/Adafruit Unified Sensor @ 1.1.15
|
||||
adafruit/Adafruit BMP280 Library @ 3.0.0
|
||||
adafruit/Adafruit BME680 Library @ 2.0.6
|
||||
debug_tool = cmsis-dap
|
||||
@@ -0,0 +1,58 @@
|
||||
/* Copyright (C) 2026 Ricardo Guzman - CA2RXU
|
||||
*
|
||||
* This file is part of LoRa APRS iGate.
|
||||
*
|
||||
* LoRa APRS iGate is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LoRa APRS iGate is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BOARD_PINOUT_H_
|
||||
#define BOARD_PINOUT_H_
|
||||
|
||||
// WIZnet W5500-EVB-Pico2 (RP2350 + W5500 on board) + Ebyte E22 / E22P carrier
|
||||
// Hardware: https://github.com/cvaldess/Wiznet_5500_EVB_Pico2_E22P
|
||||
// pico2_w5500_e22, wiznet_5500_evb_pico2_e22p and wiznet_5100s_evb_pico2_e22p
|
||||
// share this pinout: only the Ethernet chip and where it sits change.
|
||||
|
||||
// LoRa Radio: E22 / E22P, 433 or 868/915 MHz (SX1268 or SX1262, detected at boot)
|
||||
#define HAS_SX1262
|
||||
#define HAS_1W_LORA
|
||||
#define HAS_TCXO
|
||||
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
|
||||
#define RADIO_SCLK_PIN 10
|
||||
#define RADIO_MOSI_PIN 11
|
||||
#define RADIO_MISO_PIN 12
|
||||
#define RADIO_CS_PIN 13
|
||||
#define RADIO_DIO1_PIN 14
|
||||
#define RADIO_RST_PIN 15
|
||||
#define RADIO_BUSY_PIN 2
|
||||
#define RADIO_RXEN 3 // RF enable, held HIGH while the radio is active
|
||||
|
||||
// TXEN: the DIO2-TXEN jumper ships fitted, so DIO2 keys the PA and no GPIO is
|
||||
// needed. With the jumper moved, TXEN is on GPIO6: build with -D RADIO_TXEN=6.
|
||||
#ifndef RADIO_TXEN
|
||||
#define RADIO_TXEN -1
|
||||
#endif
|
||||
|
||||
// Ethernet (SPI0)
|
||||
#define PIN_ETH_MISO 16
|
||||
#define PIN_ETH_CS 17
|
||||
#define PIN_ETH_SCK 18
|
||||
#define PIN_ETH_MOSI 19
|
||||
#define PIN_ETH_RST 20
|
||||
|
||||
// I2C: WX sensors (SHT40 on the carrier, STEMMA QT connector)
|
||||
#define PIN_WX_SDA 4
|
||||
#define PIN_WX_SCL 5
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
; WIZnet W5500-EVB-Pico2 (RP2350 + W5500 on board) + Ebyte E22 / E22P carrier
|
||||
; Hardware: https://github.com/cvaldess/Wiznet_5500_EVB_Pico2_E22P
|
||||
; RP2350 boards build src/rp2350/ plus the sources they share with the ESP32
|
||||
; boards (configuration, KISS, map). Library versions as in common_settings.ini.
|
||||
[env:wiznet_5500_evb_pico2_e22p]
|
||||
platform = https://github.com/maxgerhardt/platform-raspberrypi.git#4e22a0dcdd94eead72fdf56ea59a3d7c8aa2f379
|
||||
board = wiznet_5500_evb_pico2
|
||||
board_build.core = earlephilhower
|
||||
board_build.filesystem_size = 0.75m ; also the OTA ceiling: arduino-pico stages the new image in LittleFS
|
||||
board_build.embed_files =
|
||||
board_build.partitions =
|
||||
extra_scripts = pre:tools/gen_web_assets_rp2350.py
|
||||
build_src_filter = -<*> +<rp2350/> +<configuration.cpp> +<kiss_utils.cpp> +<map_utils.cpp>
|
||||
build_flags =
|
||||
${common.build_flags}
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_FREERTOS
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_EXCEPTIONS
|
||||
-D RADIOLIB_LOW_LEVEL=1 ; getMod() for the SX126x RX-sensitivity patch
|
||||
-D WIZNET_5500_EVB_PICO2_E22P
|
||||
build_unflags =
|
||||
-Werror ; arduino-pico's GCC flags sign-compare in shared sources that the ESP32 one accepts
|
||||
lib_deps =
|
||||
arduino-libraries/Ethernet @ 2.0.2
|
||||
bblanchon/ArduinoJson @ 7.4.3
|
||||
jgromes/RadioLib @ 7.6.0
|
||||
knolleary/PubSubClient @ 2.8
|
||||
mikalhart/TinyGPSPlus @ 1.1.0
|
||||
richonguzman/APRSPacketLib @ 1.0.10
|
||||
adafruit/Adafruit Unified Sensor @ 1.1.15
|
||||
adafruit/Adafruit BMP280 Library @ 3.0.0
|
||||
adafruit/Adafruit BME680 Library @ 2.0.6
|
||||
debug_tool = cmsis-dap
|
||||
Reference in new issue
Block a user