Compare commits
113 Commits
meshcore-e
...
pr-1338
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f3442c13e | ||
|
|
69ee28491a | ||
|
|
179d66cb95 | ||
|
|
d0f9a5b4e1 | ||
|
|
26a004a89b | ||
|
|
9929d4e9dc | ||
|
|
5684b4f1b8 | ||
|
|
e233346bf0 | ||
|
|
3031deb980 | ||
|
|
dc9e7abacc | ||
|
|
044c66e261 | ||
|
|
3e5522fcde | ||
|
|
c0c9c17cf5 | ||
|
|
780720c117 | ||
|
|
90fcd1043f | ||
|
|
cdd3d5f34e | ||
|
|
7c594ebc50 | ||
|
|
ba3d9e264e | ||
|
|
d7ad89046b | ||
|
|
67779aded8 | ||
|
|
bbd621ba85 | ||
|
|
6431cd2d47 | ||
|
|
1d190ad944 | ||
|
|
2cb08775c0 | ||
|
|
c016db86d5 | ||
|
|
00566741f6 | ||
|
|
8a9a0dca5f | ||
|
|
59d9770ab9 | ||
|
|
9bae9d0ed2 | ||
|
|
85f764a114 | ||
|
|
f54948e06d | ||
|
|
b2032e11b6 | ||
|
|
9106ab46e1 | ||
|
|
a2dc2eb50c | ||
|
|
f81ec4b14c | ||
|
|
49d8313501 | ||
|
|
5a5568ed56 | ||
|
|
ac2aa03b09 | ||
|
|
70f1ad4aeb | ||
|
|
d9e67222f5 | ||
|
|
2bb6f636a4 | ||
|
|
329e408197 | ||
|
|
06ab9f7f6b | ||
|
|
8ad17d1022 | ||
|
|
eee42c5099 | ||
|
|
b67decfba0 | ||
|
|
ca81f645ed | ||
|
|
5280433098 | ||
|
|
def01889aa | ||
|
|
8737c64fdb | ||
|
|
e6e87fb8ca | ||
|
|
15cce12efd | ||
|
|
f4748a7f9d | ||
|
|
b777a7c635 | ||
|
|
b14879ce2d | ||
|
|
b43319d1a4 | ||
|
|
f7c8cf1146 | ||
|
|
9f4eeeeceb | ||
|
|
9d5c4865c3 | ||
|
|
213d085012 | ||
|
|
45564bad9b | ||
|
|
5b0884ad2d | ||
|
|
e52d57c065 | ||
|
|
a66773bac0 | ||
|
|
05e7b682b9 | ||
|
|
9c318561da | ||
|
|
2e0fa3ec46 | ||
|
|
8ee4867397 | ||
|
|
5a885bffe4 | ||
|
|
011edd3c99 | ||
|
|
3dc14976a0 | ||
|
|
3e76161e9c | ||
|
|
d05d6abab8 | ||
|
|
c2abe894c9 | ||
|
|
13d0dff918 | ||
|
|
44b80d00c2 | ||
|
|
f6603fe7a5 | ||
|
|
39fb2902ec | ||
|
|
063f5056f2 | ||
|
|
1500a5a9cb | ||
|
|
ffc9815e9a | ||
|
|
8e404e9aea | ||
|
|
bbc5f0c11a | ||
|
|
2e00298128 | ||
|
|
5de3e1bf32 | ||
|
|
a073ba4707 | ||
|
|
3e53df5082 | ||
|
|
0770618ee2 | ||
|
|
bf9c6cb50f | ||
|
|
87c78a98bd | ||
|
|
e8785dd9b0 | ||
|
|
2005977403 | ||
|
|
cafc212bb2 | ||
|
|
e2571accbe | ||
|
|
88452c412e | ||
|
|
2220eca4f3 | ||
|
|
a6e741e30e | ||
|
|
0abac35744 | ||
|
|
564a19d125 | ||
|
|
5df139f3d6 | ||
|
|
77675ab496 | ||
|
|
5ccae4bddc | ||
|
|
fb025fb67e | ||
|
|
beff18c53b | ||
|
|
f720338c03 | ||
|
|
e33d93dc7f | ||
|
|
8db42146d1 | ||
|
|
e418b0c0ab | ||
|
|
d11d8ea626 | ||
|
|
810fd561d2 | ||
|
|
23b4baa066 | ||
|
|
2b754d4295 | ||
|
|
9e61b56e70 |
43
.github/workflows/pr-build-check.yml
vendored
Normal file
43
.github/workflows/pr-build-check.yml
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
name: PR Build Check
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [main, dev]
|
||||||
|
paths:
|
||||||
|
- 'src/**'
|
||||||
|
- 'examples/**'
|
||||||
|
- 'variants/**'
|
||||||
|
- 'platformio.ini'
|
||||||
|
- '.github/workflows/pr-build-check.yml'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
environment:
|
||||||
|
# ESP32-S3 (most common platform)
|
||||||
|
- Heltec_v3_companion_radio_ble
|
||||||
|
- Heltec_v3_repeater
|
||||||
|
- Heltec_v3_room_server
|
||||||
|
# nRF52
|
||||||
|
- RAK_4631_companion_radio_ble
|
||||||
|
- RAK_4631_repeater
|
||||||
|
- RAK_4631_room_server
|
||||||
|
# RP2040
|
||||||
|
- PicoW_repeater
|
||||||
|
# STM32
|
||||||
|
- wio-e5-mini_repeater
|
||||||
|
# ESP32-C6
|
||||||
|
- LilyGo_Tlora_C6_repeater_
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Clone Repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Build Environment
|
||||||
|
uses: ./.github/actions/setup-build-environment
|
||||||
|
|
||||||
|
- name: Build ${{ matrix.environment }}
|
||||||
|
run: pio run -e ${{ matrix.environment }}
|
||||||
15
README.md
15
README.md
@@ -99,10 +99,10 @@ Here are some general principals you should try to adhere to:
|
|||||||
|
|
||||||
There are a number of fairly major features in the pipeline, with no particular time-frames attached yet. In very rough chronological order:
|
There are a number of fairly major features in the pipeline, with no particular time-frames attached yet. In very rough chronological order:
|
||||||
- [X] Companion radio: UI redesign
|
- [X] Companion radio: UI redesign
|
||||||
- [X] Repeater + Room Server: add ACL's (like Sensor Node has)
|
- [ ] Repeater + Room Server: add ACL's (like Sensor Node has)
|
||||||
- [X] Standardise Bridge mode for repeaters
|
- [ ] Standardise Bridge mode for repeaters
|
||||||
- [ ] Repeater/Bridge: Standardise the Transport Codes for zoning/filtering
|
- [ ] Repeater/Bridge: Standardise the Transport Codes for zoning/filtering
|
||||||
- [X] Core + Repeater: enhanced zero-hop neighbour discovery
|
- [ ] Core + Repeater: enhanced zero-hop neighbour discovery
|
||||||
- [ ] Core: round-trip manual path support
|
- [ ] Core: round-trip manual path support
|
||||||
- [ ] Companion + Apps: support for multiple sub-meshes (and 'off-grid' client repeat mode)
|
- [ ] Companion + Apps: support for multiple sub-meshes (and 'off-grid' client repeat mode)
|
||||||
- [ ] Core + Apps: support for LZW message compression
|
- [ ] Core + Apps: support for LZW message compression
|
||||||
@@ -115,3 +115,12 @@ There are a number of fairly major features in the pipeline, with no particular
|
|||||||
- Report bugs and request features on the [GitHub Issues](https://github.com/ripplebiz/MeshCore/issues) page.
|
- Report bugs and request features on the [GitHub Issues](https://github.com/ripplebiz/MeshCore/issues) page.
|
||||||
- Find additional guides and components on [my site](https://buymeacoffee.com/ripplebiz).
|
- Find additional guides and components on [my site](https://buymeacoffee.com/ripplebiz).
|
||||||
- Join [MeshCore Discord](https://discord.gg/BMwCtwHj5V) to chat with the developers and get help from the community.
|
- Join [MeshCore Discord](https://discord.gg/BMwCtwHj5V) to chat with the developers and get help from the community.
|
||||||
|
|
||||||
|
## RAK Wireless Board Support in PlatformIO
|
||||||
|
|
||||||
|
Before building/flashing the RAK4631 targets in this project, there is, unfortunately, some patching you have to do to your platformIO packages to make it work. There is a guide here on the process:
|
||||||
|
[RAK Wireless: How to Perform Installation of Board Support Package in PlatformIO](https://learn.rakwireless.com/hc/en-us/articles/26687276346775-How-To-Perform-Installation-of-Board-Support-Package-in-PlatformIO)
|
||||||
|
|
||||||
|
After building, you will need to convert the output firmware.hex file into a .uf2 file you can copy over to your RAK4631 device (after doing a full erase) by using the command `uf2conv.py -f 0xADA52840 -c firmware.hex` with the python script available from:
|
||||||
|
[GitHub: Microsoft - uf2](https://github.com/Microsoft/uf2/blob/master/utils/uf2conv.py)
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
"name": "LilyGo T-Beam supreme (8MB Flash 8MB PSRAM)",
|
"name": "LilyGo T-Beam supreme (8MB Flash 8MB PSRAM)",
|
||||||
"upload": {
|
"upload": {
|
||||||
"flash_size": "8MB",
|
"flash_size": "8MB",
|
||||||
"maximum_ram_size": 327680,
|
"maximum_ram_size": 8388608,
|
||||||
"maximum_size": 8388608,
|
"maximum_size": 8388608,
|
||||||
"require_upload_port": true,
|
"require_upload_port": true,
|
||||||
"speed": 460800
|
"speed": 460800
|
||||||
|
|||||||
55
build.sh
55
build.sh
@@ -64,6 +64,8 @@ case $1 in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# cache project config json for use in get_platform_for_env()
|
||||||
|
PIO_CONFIG_JSON=$(pio project config --json-output)
|
||||||
|
|
||||||
# $1 should be the string to find (case insensitive)
|
# $1 should be the string to find (case insensitive)
|
||||||
get_pio_envs_containing_string() {
|
get_pio_envs_containing_string() {
|
||||||
@@ -87,6 +89,25 @@ get_pio_envs_ending_with_string() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# get platform flag for a given environment
|
||||||
|
# $1 should be the environment name
|
||||||
|
get_platform_for_env() {
|
||||||
|
local env_name=$1
|
||||||
|
echo "$PIO_CONFIG_JSON" | python3 -c "
|
||||||
|
import sys, json, re
|
||||||
|
data = json.load(sys.stdin)
|
||||||
|
for section, options in data:
|
||||||
|
if section == 'env:$env_name':
|
||||||
|
for key, value in options:
|
||||||
|
if key == 'build_flags':
|
||||||
|
for flag in value:
|
||||||
|
match = re.search(r'(ESP32_PLATFORM|NRF52_PLATFORM|STM32_PLATFORM|RP2040_PLATFORM)', flag)
|
||||||
|
if match:
|
||||||
|
print(match.group(1))
|
||||||
|
sys.exit(0)
|
||||||
|
"
|
||||||
|
}
|
||||||
|
|
||||||
# disable all debug logging flags if DISABLE_DEBUG=1 is set
|
# disable all debug logging flags if DISABLE_DEBUG=1 is set
|
||||||
disable_debug_flags() {
|
disable_debug_flags() {
|
||||||
if [ "$DISABLE_DEBUG" == "1" ]; then
|
if [ "$DISABLE_DEBUG" == "1" ]; then
|
||||||
@@ -96,6 +117,8 @@ disable_debug_flags() {
|
|||||||
|
|
||||||
# build firmware for the provided pio env in $1
|
# build firmware for the provided pio env in $1
|
||||||
build_firmware() {
|
build_firmware() {
|
||||||
|
# get env platform for post build actions
|
||||||
|
ENV_PLATFORM=($(get_platform_for_env $1))
|
||||||
|
|
||||||
# get git commit sha
|
# get git commit sha
|
||||||
COMMIT_HASH=$(git rev-parse --short HEAD)
|
COMMIT_HASH=$(git rev-parse --short HEAD)
|
||||||
@@ -126,27 +149,31 @@ build_firmware() {
|
|||||||
# build firmware target
|
# build firmware target
|
||||||
pio run -e $1
|
pio run -e $1
|
||||||
|
|
||||||
# build merge-bin for esp32 fresh install
|
# build merge-bin for esp32 fresh install, copy .bins to out folder (e.g: Heltec_v3_room_server-v1.0.0-SHA.bin)
|
||||||
if [ -f .pio/build/$1/firmware.bin ]; then
|
if [ "$ENV_PLATFORM" == "ESP32_PLATFORM" ]; then
|
||||||
pio run -t mergebin -e $1
|
pio run -t mergebin -e $1
|
||||||
|
cp .pio/build/$1/firmware.bin out/${FIRMWARE_FILENAME}.bin 2>/dev/null || true
|
||||||
|
cp .pio/build/$1/firmware-merged.bin out/${FIRMWARE_FILENAME}-merged.bin 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# build .uf2 for nrf52 boards
|
# build .uf2 for nrf52 boards, copy .uf2 and .zip to out folder (e.g: RAK_4631_Repeater-v1.0.0-SHA.uf2)
|
||||||
if [[ -f .pio/build/$1/firmware.zip && -f .pio/build/$1/firmware.hex ]]; then
|
if [ "$ENV_PLATFORM" == "NRF52_PLATFORM" ]; then
|
||||||
python3 bin/uf2conv/uf2conv.py .pio/build/$1/firmware.hex -c -o .pio/build/$1/firmware.uf2 -f 0xADA52840
|
python3 bin/uf2conv/uf2conv.py .pio/build/$1/firmware.hex -c -o .pio/build/$1/firmware.uf2 -f 0xADA52840
|
||||||
|
cp .pio/build/$1/firmware.uf2 out/${FIRMWARE_FILENAME}.uf2 2>/dev/null || true
|
||||||
|
cp .pio/build/$1/firmware.zip out/${FIRMWARE_FILENAME}.zip 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# copy .bin, .uf2, and .zip to out folder
|
# for stm32, copy .bin and .hex to out folder
|
||||||
# e.g: Heltec_v3_room_server-v1.0.0-SHA.bin
|
if [ "$ENV_PLATFORM" == "STM32_PLATFORM" ]; then
|
||||||
# e.g: RAK_4631_Repeater-v1.0.0-SHA.uf2
|
cp .pio/build/$1/firmware.bin out/${FIRMWARE_FILENAME}.bin 2>/dev/null || true
|
||||||
|
cp .pio/build/$1/firmware.hex out/${FIRMWARE_FILENAME}.hex 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
# copy .bin for esp32 boards
|
# for rp2040, copy .bin and .uf2 to out folder
|
||||||
cp .pio/build/$1/firmware.bin out/${FIRMWARE_FILENAME}.bin 2>/dev/null || true
|
if [ "$ENV_PLATFORM" == "RP2040_PLATFORM" ]; then
|
||||||
cp .pio/build/$1/firmware-merged.bin out/${FIRMWARE_FILENAME}-merged.bin 2>/dev/null || true
|
cp .pio/build/$1/firmware.bin out/${FIRMWARE_FILENAME}.bin 2>/dev/null || true
|
||||||
|
cp .pio/build/$1/firmware.uf2 out/${FIRMWARE_FILENAME}.uf2 2>/dev/null || true
|
||||||
# copy .zip and .uf2 of nrf52 boards
|
fi
|
||||||
cp .pio/build/$1/firmware.uf2 out/${FIRMWARE_FILENAME}.uf2 2>/dev/null || true
|
|
||||||
cp .pio/build/$1/firmware.zip out/${FIRMWARE_FILENAME}.zip 2>/dev/null || true
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
- `time <epoch_seconds>`
|
- `time <epoch_seconds>`
|
||||||
|
|
||||||
**Parameters:**
|
**Parameters:**
|
||||||
- `epoc_seconds`: Unix epoc time
|
- `epoch_seconds`: Unix epoch time
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### End capture of rx log to node sotrage
|
### End capture of rx log to node storage
|
||||||
**Usage:** `log stop`
|
**Usage:** `log stop`
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -198,7 +198,7 @@
|
|||||||
|
|
||||||
**Default:** Varies by board
|
**Default:** Varies by board
|
||||||
|
|
||||||
**Notes:** This setting only controls the power level of the LoRa chip. Some nodes have an additional power amplifier stage which increases the total output. Referr to the node's manual for the correct setting to use. **Setting a value too high may violate the laws in your country.**
|
**Notes:** This setting only controls the power level of the LoRa chip. Some nodes have an additional power amplifier stage which increases the total output. Refer to the node's manual for the correct setting to use. **Setting a value too high may violate the laws in your country.**
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -228,6 +228,7 @@
|
|||||||
**Default:** `869.525`
|
**Default:** `869.525`
|
||||||
|
|
||||||
**Note:** Requires reboot to apply
|
**Note:** Requires reboot to apply
|
||||||
|
**Serial Only:** `set freq <frequency>`
|
||||||
|
|
||||||
### System
|
### System
|
||||||
|
|
||||||
@@ -293,17 +294,16 @@
|
|||||||
|
|
||||||
#### View or change this node's admin password
|
#### View or change this node's admin password
|
||||||
**Usage:**
|
**Usage:**
|
||||||
- `get password`
|
- `password <new_password>`
|
||||||
- `set password <password>`
|
|
||||||
|
|
||||||
**Parameters:**
|
**Parameters:**
|
||||||
- `password`: Admin password
|
- `new_password`: New admin password
|
||||||
|
|
||||||
**Set by build flag:** `ADMIN_PASSWORD`
|
**Set by build flag:** `ADMIN_PASSWORD`
|
||||||
|
|
||||||
**Default:** `password`
|
**Default:** `password`
|
||||||
|
|
||||||
**Note:** Echoed back for confirmation
|
**Note:** Command reply echoes the updated password for confirmation.
|
||||||
|
|
||||||
**Note:** Any node using this password will be added to the admin ACL list.
|
**Note:** Any node using this password will be added to the admin ACL list.
|
||||||
|
|
||||||
@@ -642,7 +642,7 @@
|
|||||||
**Usage:**
|
**Usage:**
|
||||||
- `region`
|
- `region`
|
||||||
|
|
||||||
**Serial Only:** Yes
|
**Serial Only:** For firmware older than 1.12.0
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -768,7 +768,7 @@ region save
|
|||||||
- `gps advert <policy>`
|
- `gps advert <policy>`
|
||||||
|
|
||||||
**Parameters:**
|
**Parameters:**
|
||||||
- `policy`: `none`|`shared`|`prefs`
|
- `policy`: `none`|`share`|`prefs`
|
||||||
- `none`: don't include location in adverts
|
- `none`: don't include location in adverts
|
||||||
- `share`: share gps location (from SensorManager)
|
- `share`: share gps location (from SensorManager)
|
||||||
- `prefs`: location stored in node's lat and lon settings
|
- `prefs`: location stored in node's lat and lon settings
|
||||||
|
|||||||
163
docs/faq.md
163
docs/faq.md
@@ -26,10 +26,6 @@ author: https://github.com/LitBomb<!-- omit from toc -->
|
|||||||
- [3.2. Q: Do I need to set the location for a repeater?](#32-q-do-i-need-to-set-the-location-for-a-repeater)
|
- [3.2. Q: Do I need to set the location for a repeater?](#32-q-do-i-need-to-set-the-location-for-a-repeater)
|
||||||
- [3.3. Q: What is the password to administer a repeater or a room server?](#33-q-what-is-the-password-to-administer-a-repeater-or-a-room-server)
|
- [3.3. Q: What is the password to administer a repeater or a room server?](#33-q-what-is-the-password-to-administer-a-repeater-or-a-room-server)
|
||||||
- [3.4. Q: What is the password to join a room server?](#34-q-what-is-the-password-to-join-a-room-server)
|
- [3.4. Q: What is the password to join a room server?](#34-q-what-is-the-password-to-join-a-room-server)
|
||||||
- [3.5. Q: Can I retrieve a repeater's private key or set a repeater's private key?](#35-q-can-i-retrieve-a-repeaters-private-key-or-set-a-repeaters-private-key)
|
|
||||||
- [3.6. Q: The first byte of my repeater's public key collides with an exisitng repeater on the mesh. How do I get a new private key with a matching public key that has its first byte of my choosing?](#36-q-the-first-byte-of-my-repeaters-public-key-collides-with-an-exisitng-repeater-on-the-mesh--how-do-i-get-a-new-private-key-with-a-matching-public-key-that-has-its-first-byte-of-my-choosing)
|
|
||||||
- [3.7. Q: My repeater maybe suffering from deafness due to high power interference near my mesh's frequency, it is not hearing other in-range MeshCore radios. what can I do?](#37-q-my-repeater-maybe-suffering-from-deafness-due-to-high-power-interference-near-my-meshs-frequency-it-is-not-hearing-other-in-range-meshcore-radios--what-can-i-do)
|
|
||||||
- [3.8 Q: How do I make my repeater an observer on the mesh](#38-q-how-do-i-make-my-repeater-an-observer-on-the-mesh)
|
|
||||||
- [4. T-Deck Related](#4-t-deck-related)
|
- [4. T-Deck Related](#4-t-deck-related)
|
||||||
- [4.1. Q: Is there a user guide for T-Deck, T-Pager, T-Watch, or T-Display Pro?](#41-q-is-there-a-user-guide-for-t-deck-t-pager-t-watch-or-t-display-pro)
|
- [4.1. Q: Is there a user guide for T-Deck, T-Pager, T-Watch, or T-Display Pro?](#41-q-is-there-a-user-guide-for-t-deck-t-pager-t-watch-or-t-display-pro)
|
||||||
- [4.2. Q: What are the steps to get a T-Deck into DFU (Device Firmware Update) mode?](#42-q-what-are-the-steps-to-get-a-t-deck-into-dfu-device-firmware-update-mode)
|
- [4.2. Q: What are the steps to get a T-Deck into DFU (Device Firmware Update) mode?](#42-q-what-are-the-steps-to-get-a-t-deck-into-dfu-device-firmware-update-mode)
|
||||||
@@ -65,31 +61,22 @@ author: https://github.com/LitBomb<!-- omit from toc -->
|
|||||||
- [5.14.3. Python MeshCore](#5143-python-meshcore)
|
- [5.14.3. Python MeshCore](#5143-python-meshcore)
|
||||||
- [5.14.4. meshcore-cli](#5144-meshcore-cli)
|
- [5.14.4. meshcore-cli](#5144-meshcore-cli)
|
||||||
- [5.14.5. meshcore.js](#5145-meshcorejs)
|
- [5.14.5. meshcore.js](#5145-meshcorejs)
|
||||||
- [5.14.6. pyMC\_core](#5146-pymc_core)
|
|
||||||
- [5.14.7. MeshCore Packet Decoder](#5147-meshcore-packet-decoder)
|
|
||||||
- [5.14.8. meshcore-pi](#5148-meshcore-pi)
|
|
||||||
- [5.14.9. pyMC\_Repeater](#5149-pymc_repeater)
|
|
||||||
- [5.15. Q: Are there client applications for Windows or Mac?](#515-q-are-there-client-applications-for-windows-or-mac)
|
|
||||||
- [5.16. Q: Are there any resources that compare MeshCore to other LoRa systems?](#516-q-are-there-any-resources-that-compare-meshcore-to-other-lora-systems)
|
|
||||||
- [6. Troubleshooting](#6-troubleshooting)
|
- [6. Troubleshooting](#6-troubleshooting)
|
||||||
- [6.1. Q: My client says another client or a repeater or a room server was last seen many, many days ago.](#61-q-my-client-says-another-client-or-a-repeater-or-a-room-server-was-last-seen-many-many-days-ago)
|
- [6.1. Q: My client says another client or a repeater or a room server was last seen many, many days ago.](#61-q-my-client-says-another-client-or-a-repeater-or-a-room-server-was-last-seen-many-many-days-ago)
|
||||||
- [6.2. Q: A repeater or a client or a room server I expect to see on my discover list (on T-Deck) or contact list (on a smart device client) are not listed.](#62-q-a-repeater-or-a-client-or-a-room-server-i-expect-to-see-on-my-discover-list-on-t-deck-or-contact-list-on-a-smart-device-client-are-not-listed)
|
- [6.2. Q: A repeater or a client or a room server I expect to see on my discover list (on T-Deck) or contact list (on a smart device client) are not listed.](#62-q-a-repeater-or-a-client-or-a-room-server-i-expect-to-see-on-my-discover-list-on-t-deck-or-contact-list-on-a-smart-device-client-are-not-listed)
|
||||||
- [6.3. Q: How to connect to a repeater via BLE (Bluetooth)?](#63-q-how-to-connect-to-a-repeater-via-ble-bluetooth)
|
- [6.3. Q: How to connect to a repeater via BLE (Bluetooth)?](#63-q-how-to-connect-to-a-repeater-via-ble-bluetooth)
|
||||||
- [6.4. Q: My companion isn't showing up over Bluetooth?](#64-q-my-companion-isnt-showing-up-over-bluetooth)
|
- [6.4. Q: My companion isn't showing up over Bluetooth?](#64-q-my-companion-isnt-showing-up-over-bluetooth)
|
||||||
- [6.5. Q: I can't connect via Bluetooth, what is the Bluetooth pairing code?](#65-q-i-cant-connect-via-bluetooth-what-is-the-bluetooth-pairing-code)
|
- [6.5. Q: I can't connect via Bluetooth, what is the Bluetooth pairing code?](#64-q-i-cant-connect-via-bluetooth-what-is-the-bluetooth-pairing-code)
|
||||||
- [6.6. Q: My Heltec V3 keeps disconnecting from my smartphone. It can't hold a solid Bluetooth connection.](#66-q-my-heltec-v3-keeps-disconnecting-from-my-smartphone--it-cant-hold-a-solid-bluetooth-connection)
|
- [6.6. Q: My Heltec V3 keeps disconnecting from my smartphone. It can't hold a solid Bluetooth connection.](#65-q-my-heltec-v3-keeps-disconnecting-from-my-smartphone--it-cant-hold-a-solid-bluetooth-connection)
|
||||||
- [6.7. Q: My RAK/T1000-E/xiao\_nRF52 device seems to be corrupted, how do I wipe it clean to start fresh?](#67-q-my-rakt1000-exiao_nrf52-device-seems-to-be-corrupted-how-do-i-wipe-it-clean-to-start-fresh)
|
- [6.7. Q: My RAK/T1000-E/xiao\_nRF52 device seems to be corrupted, how do I wipe it clean to start fresh?](#66-q-my-rakt1000-exiao_nrf52-device-seems-to-be-corrupted-how-do-i-wipe-it-clean-to-start-fresh)
|
||||||
- [6.8. Q: WebFlasher fails on Linux with failed to open](#68-q-webflasher-fails-on-linux-with-failed-to-open)
|
- [6.8. Q: WebFlasher fails on Linux with failed to open](#67-q-webflasher-fails-on-linux-with-failed-to-open)
|
||||||
- [7. Other Questions:](#7-other-questions)
|
- [7. Other Questions:](#7-other-questions)
|
||||||
- [7.1. Q: How to update nRF (RAK, T114, Seed XIAO) repeater and room server firmware over the air using the new simpler DFU app?](#71-q-how-to-update-nrf-rak-t114-seed-xiao-repeater-and-room-server-firmware-over-the-air-using-the-new-simpler-dfu-app)
|
- [7.1. Q: How to update nRF (RAK, T114, Seed XIAO) repeater and room server firmware over the air using the new simpler DFU app?](#71-q-how-to-update-nrf-rak-t114-seed-xiao-repeater-and-room-server-firmware-over-the-air-using-the-new-simpler-dfu-app)
|
||||||
- [7.1.1 Q: Can I update Seeed Studio Wio Tracker L1 Pro using OTA?](#711-q-can-i-update-seeed-studio-wio-tracker-l1-pro-using-ota)
|
|
||||||
- [7.2. Q: How to update ESP32-based devices over the air?](#72-q-how-to-update-esp32-based-devices-over-the-air)
|
- [7.2. Q: How to update ESP32-based devices over the air?](#72-q-how-to-update-esp32-based-devices-over-the-air)
|
||||||
- [7.3. Q: Is there a way to lower the chance of a failed OTA device firmware update (DFU)?](#73-q-is-there-a-way-to-lower-the-chance-of-a-failed-ota-device-firmware-update-dfu)
|
- [7.3. Q: Is there a way to lower the chance of a failed OTA device firmware update (DFU)?](#73-q-is-there-a-way-to-lower-the-chance-of-a-failed-ota-device-firmware-update-dfu)
|
||||||
- [7.4. Q: are the MeshCore logo and font available?](#74-q-are-the-meshcore-logo-and-font-available)
|
- [7.4. Q: are the MeshCore logo and font available?](#74-q-are-the-meshcore-logo-and-font-available)
|
||||||
- [7.5. Q: What is the format of a contact or channel QR code?](#75-q-what-is-the-format-of-a-contact-or-channel-qr-code)
|
- [7.5. Q: What is the format of a contact or channel QR code?](#75-q-what-is-the-format-of-a-contact-or-channel-qr-code)
|
||||||
- [7.6. Q: How do I connect to the companion via WIFI, e.g. using a heltec v3?](#76-q-how-do-i-connect-to-the-companion-via-wifi-eg-using-a-heltec-v3)
|
- [7.6. Q: How do I connect to the companion via WIFI, e.g. using a heltec v3?](#76-q-how-do-i-connect-to-the-comnpanion-via-wifi-eg-using-a-heltec-v3)
|
||||||
- [7.7. Q: I have a Station G2, or a Heltec V4, or an Ikoka Stick, or a radio with a EByte E22-900M30S or a E22-900M33S module, what should their transmit power be set to?](#77-q-i-have-a-station-g2-or-a-heltec-v4-or-an-ikoka-stick-or-a-radio-with-a-ebyte-e22-900m30s-or-a-e22-900m33s-module-what-should-their-transmit-power-be-set-to)
|
|
||||||
- [| | High Output | 22 dBm | 28 dBm | |](#--high-output--22-dbm--28-dbm--)
|
|
||||||
|
|
||||||
## 1. Introduction
|
## 1. Introduction
|
||||||
|
|
||||||
@@ -193,17 +180,22 @@ The T-Deck firmware is free to download and most features are available without
|
|||||||
|
|
||||||
|
|
||||||
### 2.3. Q: What frequencies are supported by MeshCore?
|
### 2.3. Q: What frequencies are supported by MeshCore?
|
||||||
**A:** It supports the 868MHz range in the UK/EU and the 915MHz range in New Zealand, Australia, and the USA. Countries and regions in these two frequency ranges are also supported.
|
**A:** It supports the 868MHz range in the UK/EU and the 915MHz range in New Zealand, Australia, and the USA. Countries and regions in these two frequency ranges are also supported. The firmware and client allow users to set their preferred frequency.
|
||||||
|
- Australia and New Zealand are on **915.8MHz**
|
||||||
|
- UK and EU are on **869.525MHz**
|
||||||
|
- Canada and USA are on **910.525MHz**
|
||||||
|
- For other regions and countries, please check your local LoRa frequency
|
||||||
|
|
||||||
Use the smartphone client or the repeater setup feature on there web flasher to set your radios' RF settings by choosing the preset for your regions.
|
In UK and EU, 867.5MHz is not allowed to use 250kHz bandwidth and it only allows 2.5% duty cycle for clients. 869.525Mhz allows an airtime of 10%, 250KHz bandwidth, and a higher EIRP, therefore MeshCore nodes can send more often and with more power. That is why this frequency is chosen for UK and EU. This is also why Meshtastic also uses this frequency.
|
||||||
|
|
||||||
Recently, as of October 2025, many regions have moved to the "narrow" setting, aka using BW62.5 and a lower SF number (instead of the original SF11). For example, USA/Canada (Recommended) preset is 910.525MHz, SF7, BW62.5, CR5.
|
[Source](https://discord.com/channels/826570251612323860/1330643963501351004/1356540643853209641)
|
||||||
|
|
||||||
After extensive testing, many regions have switched or about to switch over to BW62.5 and SF7, 8, or 9. Narrower bandwidth setting and lower SF setting allow MeshCore's radio signals to fit between interference in the ISM band, provide for a lower noise floor, better SNR, and faster transmissions.
|
|
||||||
|
|
||||||
If you have consensus from your community in your region to update your region's preset recommendation, please post your update request on the [#meshcore-app](https://discord.com/channels/1343693475589263471/1391681655911088241) channel on the [MeshCore Discord server ](https://discord.gg/cYtQNYCCRK) to let Liam Cottle know.
|
|
||||||
|
|
||||||
|
the rest of the radio settings are the same for all frequencies:
|
||||||
|
- Spread Factor (SF): 11
|
||||||
|
- Coding Rate (CR): 5
|
||||||
|
- Bandwidth (BW): 250.00
|
||||||
|
|
||||||
|
(Originally MeshCore started with SF 10. recently (as of late April 2025) the community has advocated SF 11 also a viable option for longer range but a little slower transmission. Currently there are MeshCore meshes with SF 10 and SF 11. Liam Cottle's smartphone app's presets now recommend SF 10 for Australia and SF 11 for all other regions and countries. EU and UK has SF 10 and SF 11 presets. Work with your local meshers on deciding with SF number is best for your use cases. In the future, there may be bridge nodes that can bridge SF 10 and SF 11 (or even different frequencies) traffic.)
|
||||||
|
|
||||||
### 2.4. Q: What is an "advert" in MeshCore?
|
### 2.4. Q: What is an "advert" in MeshCore?
|
||||||
**A:**
|
**A:**
|
||||||
@@ -251,7 +243,7 @@ Repeater or room server can be administered with one of the options below:
|
|||||||
|
|
||||||
|
|
||||||
### 3.2. Q: Do I need to set the location for a repeater?
|
### 3.2. Q: Do I need to set the location for a repeater?
|
||||||
**A:** While not required, with location set for a repeater it will show up on the MeshCore map in the future. Set location with the following command:
|
**A:** With location set for a repeater, it can show up on a MeshCore map in the future. Set location with the following commands:
|
||||||
|
|
||||||
`set lat <GPS Lat> set long <GPS Lon>`
|
`set lat <GPS Lat> set long <GPS Lon>`
|
||||||
|
|
||||||
@@ -268,34 +260,6 @@ You can get the latitude and longitude from Google Maps by right-clicking the lo
|
|||||||
|
|
||||||
`set guest.password {guest-password}`
|
`set guest.password {guest-password}`
|
||||||
|
|
||||||
### 3.5. Q: Can I retrieve a repeater's private key or set a repeater's private key?
|
|
||||||
|
|
||||||
**A:** You can issue these commands to get or set a repeater's private key using a USB serial connection.
|
|
||||||
|
|
||||||
`get prv.key` to print a repeater's private key on the serial console
|
|
||||||
`set prv.key <hex>` to set a repeater's private key on the serial console
|
|
||||||
|
|
||||||
Reboot the repeater after `set prv.key <hex>` command for the new private key to take effect.
|
|
||||||
|
|
||||||
### 3.6. Q: The first byte of my repeater's public key collides with an exisitng repeater on the mesh. How do I get a new private key with a matching public key that has its first byte of my choosing?
|
|
||||||
|
|
||||||
**A:** You can generate a new private key and specific the first byte of its public key here: https://gessaman.com/mc-keygen/
|
|
||||||
|
|
||||||
|
|
||||||
### 3.7. Q: My repeater maybe suffering from deafness due to high power interference near my mesh's frequency, it is not hearing other in-range MeshCore radios. what can I do?
|
|
||||||
|
|
||||||
**A:** This may be due to the SX1262 radio's auto gain control feature. You can use this command to preiodically reset its AGC.
|
|
||||||
|
|
||||||
`set agc.reset.interval <number>`
|
|
||||||
|
|
||||||
The `<number>` unit is in seconds and is incremented by 4. `set agc.reset.interval 4` works well to cure deafness.
|
|
||||||
|
|
||||||
This is a very low cost operation. AGC reset is done by simply setting `state = STATE_IDLE;` in function `RadioLibWrapper::resetAGC()` in `RadioLibWrappers.cpp`
|
|
||||||
|
|
||||||
|
|
||||||
### 3.8 Q: How do I make my repeater an observer on the mesh
|
|
||||||
|
|
||||||
**A:** The observer instruction is available here: https://analyzer.letsme.sh/observer/onboard
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -333,9 +297,7 @@ GPS on T-Deck is always enabled. You can skip the "GPS clock sync" and the T-De
|
|||||||
**A:**
|
**A:**
|
||||||
T-Deck uses the same key the smartphone apps use but in base64
|
T-Deck uses the same key the smartphone apps use but in base64
|
||||||
`izOH6cXN6mrJ5e26oRXNcg==`
|
`izOH6cXN6mrJ5e26oRXNcg==`
|
||||||
|
The third character is the capital letter 'O', not zero `0`
|
||||||
There is no `=` key on the T-Deck's hardware keyboard. You can use the on-screen software keyboard to enter `=`. Tap the text box to enable the on-screen software keyboard.
|
|
||||||
The third character is the capital letter `O` (Oh), not zero `0`
|
|
||||||
|
|
||||||
The smartphone app key is in hex:
|
The smartphone app key is in hex:
|
||||||
` 8b3387e9c5cdea6ac9e5edbaa115cd72`
|
` 8b3387e9c5cdea6ac9e5edbaa115cd72`
|
||||||
@@ -414,23 +376,7 @@ https://github.com/meshcore-dev/MeshCore/blob/main/src/Packet.h#L19
|
|||||||
|
|
||||||
**SF is spreading factor** - how much should the communication spread in time
|
**SF is spreading factor** - how much should the communication spread in time
|
||||||
|
|
||||||
**CR is coding rate** - from: https://www.thethingsnetwork.org/docs/lorawan/fec-and-code-rate/
|
**CR is coding rate** - https://www.thethingsnetwork.org/docs/lorawan/fec-and-code-rate/
|
||||||
|
|
||||||
TL;DR: default CR to 5 for good stable links. If it is not a solid link and is intermittent, change to CR to 7 or 8.
|
|
||||||
|
|
||||||
Forward Error Correction is a process of adding redundant bits to the data to be transmitted. During the transmission, data may get corrupted by interference (changes from 0 to 1 / 1 to 0). These error correction bits are used at the receivers for restoring corrupted bits.
|
|
||||||
|
|
||||||
The Code Rate of a forward error correction expresses the proportion of bits in a data stream that actually carry useful information.
|
|
||||||
|
|
||||||
There are 4 code rates used in LoRaWAN:
|
|
||||||
|
|
||||||
4/5
|
|
||||||
4/6
|
|
||||||
5/7
|
|
||||||
4/8
|
|
||||||
|
|
||||||
For example, if the code rate is 5/7, for every 5 bits of useful information, the coder generates a total of 7 bits of data, of which 2 bits are redundant.
|
|
||||||
|
|
||||||
Making the bandwidth 2x wider (from BW125 to BW250) allows you to send 2x more bytes in the same time. Making the spreading factor 1 step lower (from SF10 to SF9) allows you to send 2x more bytes in the same time.
|
Making the bandwidth 2x wider (from BW125 to BW250) allows you to send 2x more bytes in the same time. Making the spreading factor 1 step lower (from SF10 to SF9) allows you to send 2x more bytes in the same time.
|
||||||
|
|
||||||
Lowering the spreading factor makes it more difficult for the gateway to receive a transmission, as it will be more sensitive to noise. You could compare this to two people taking in a noisy place (a bar for example). If you’re far from each other, you have to talk slow (SF10), but if you’re close, you can talk faster (SF7)
|
Lowering the spreading factor makes it more difficult for the gateway to receive a transmission, as it will be more sensitive to noise. You could compare this to two people taking in a noisy place (a bar for example). If you’re far from each other, you have to talk slow (SF10), but if you’re close, you can talk faster (SF7)
|
||||||
@@ -612,8 +558,7 @@ From here, reference repeater and room server command line commands on MeshCore
|
|||||||
**A:** Yes. See the following:
|
**A:** Yes. See the following:
|
||||||
|
|
||||||
#### 5.14.1. meshcoremqtt
|
#### 5.14.1. meshcoremqtt
|
||||||
A Python script to send meshcore debug and packet capture data to MQTT for analysis. Cisien's version is a fork of Andrew-a-g's and is being used to to collect data for https://map.w0z.is/messages and https://analyzer.letsme.sh/
|
A Python script to send meshore debug and packet capture data to MQTT for analysis
|
||||||
https://github.com/Cisien/meshcoretomqtt
|
|
||||||
https://github.com/Andrew-a-g/meshcoretomqtt
|
https://github.com/Andrew-a-g/meshcoretomqtt
|
||||||
|
|
||||||
#### 5.14.2. MeshCore for Home Assistant
|
#### 5.14.2. MeshCore for Home Assistant
|
||||||
@@ -632,40 +577,6 @@ CLI interface to MeshCore companion radio over BLE, TCP, or serial. Uses Python
|
|||||||
A JavaScript library for interacting with a MeshCore device running the companion radio firmware
|
A JavaScript library for interacting with a MeshCore device running the companion radio firmware
|
||||||
https://github.com/liamcottle/meshcore.js
|
https://github.com/liamcottle/meshcore.js
|
||||||
|
|
||||||
#### 5.14.6. pyMC_core
|
|
||||||
pyMC_Core is a Python port of MeshCore, designed for Raspberry Pi and similar hardware, it talks to LoRa modules over SPI.
|
|
||||||
https://github.com/rightup/pyMC_core
|
|
||||||
|
|
||||||
#### 5.14.7. MeshCore Packet Decoder
|
|
||||||
A TypeScript library for decoding MeshCore mesh networking packets with full cryptographic support. Uses WebAssembly (WASM) for Ed25519 key derivation through the orlp/ed25519 library. It powers the [MeshCore Packet Analyzer](https://analyzer.letsme.sh/packets).
|
|
||||||
https://github.com/michaelhart/meshcore-decoder
|
|
||||||
|
|
||||||
#### 5.14.8. meshcore-pi
|
|
||||||
meshcore-pi is another Python port of MeshCore, designed for Raspberry Pi and similar hardware, it talks to LoRa modules over SPI or GPIO.
|
|
||||||
https://github.com/brianwiddas/meshcore-pi
|
|
||||||
|
|
||||||
#### 5.14.9. pyMC_Repeater
|
|
||||||
pyMC_Repeater is a repeater daemon in Python built on top of the [`pymc_core`](#5146-pymc_core) library.
|
|
||||||
https://github.com/rightup/pyMC_Repeater
|
|
||||||
|
|
||||||
|
|
||||||
### 5.15. Q: Are there client applications for Windows or Mac?
|
|
||||||
**A:** Yes, the same iOS and Android client is also available for Windows and Intel Mac (sorry, not available for ARM-based Mac yet). You can find them together with the Android APK here:
|
|
||||||
https://files.liamcottle.net/MeshCore
|
|
||||||
|
|
||||||
Both the Windows and Intel Mac versions of the client app are fully unlocked and are free to use.
|
|
||||||
|
|
||||||
### 5.16. Q: Are there any resources that compare MeshCore to other LoRa systems?
|
|
||||||
|
|
||||||
**A:** Here is a list of MeshCore comparison resources:
|
|
||||||
The Comms Channel on YouTube:
|
|
||||||
https://www.youtube.com/watch?v=guDoKGs02Us
|
|
||||||
MeshCore Advantages by MCarper:
|
|
||||||
https://github.com/mikecarper/meshfirmware/blob/main/MeshCoreAdvantages.md
|
|
||||||
Meshcore vs Meshtastic by austinmesh.org
|
|
||||||
https://www.austinmesh.org/learn/meshcore-vs-meshtastic/
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 6. Troubleshooting
|
## 6. Troubleshooting
|
||||||
@@ -742,12 +653,6 @@ Allow the browser user on it:
|
|||||||
13. If it fails, try turning off and on Bluetooth on your phone. If that doesn't work, try rebooting your phone.
|
13. If it fails, try turning off and on Bluetooth on your phone. If that doesn't work, try rebooting your phone.
|
||||||
14. Wait for the update to complete. It can take a few minutes.
|
14. Wait for the update to complete. It can take a few minutes.
|
||||||
|
|
||||||
#### 7.1.1 Q: Can I update Seeed Studio Wio Tracker L1 Pro using OTA?
|
|
||||||
**A:** You can flash this safer bootloader to the Wio Tracker L1 Pro
|
|
||||||
https://github.com/oltaco/Adafruit_nRF52_Bootloader_OTAFIX
|
|
||||||
|
|
||||||
After this bootloader is flashed onto the device, you can trigger over the air update using bluetooth by holding the button next to the D-Pad and then click the reset button. The follow the same OTA update instructions above. You can skip pass the `start ota` instruction and start the update using the DFU app.
|
|
||||||
|
|
||||||
|
|
||||||
### 7.2. Q: How to update ESP32-based devices over the air?
|
### 7.2. Q: How to update ESP32-based devices over the air?
|
||||||
|
|
||||||
@@ -768,14 +673,10 @@ After this bootloader is flashed onto the device, you can trigger over the air u
|
|||||||
Refer to https://github.com/oltaco/Adafruit_nRF52_Bootloader_OTAFIX for the latest information.
|
Refer to https://github.com/oltaco/Adafruit_nRF52_Bootloader_OTAFIX for the latest information.
|
||||||
|
|
||||||
Currently, the following boards are supported:
|
Currently, the following boards are supported:
|
||||||
- Heltec Automation Mesh Node T114 / HT-nRF5262
|
- Nologo ProMicro
|
||||||
- Nologo ProMicro NRF52840 (aka SuperMini NRF52840)
|
|
||||||
- Seeed Studio SenseCAP Card Tracker T1000-E
|
|
||||||
- Seeed Studio Wio Tracker L1
|
|
||||||
- Seeed Studio XIAO nRF52840 BLE
|
- Seeed Studio XIAO nRF52840 BLE
|
||||||
- Seeed Studio XIAO nRF52840 BLE SENSE
|
- Seeed Studio XIAO nRF52840 BLE SENSE
|
||||||
- RAK 4631 (See note)
|
- RAK 4631
|
||||||
- RAK WisMesh Tag (new 28/11/2025)
|
|
||||||
|
|
||||||
### 7.4. Q: are the MeshCore logo and font available?
|
### 7.4. Q: are the MeshCore logo and font available?
|
||||||
|
|
||||||
@@ -802,22 +703,4 @@ where `&type` is:
|
|||||||
WiFi firmware requires you to compile it yourself, as you need to set the wifi ssid and password.
|
WiFi firmware requires you to compile it yourself, as you need to set the wifi ssid and password.
|
||||||
Edit WIFI_SSID and WIFI_PWD in `./variants/heltec_v3/platformio.ini` and then flash it to your device.
|
Edit WIFI_SSID and WIFI_PWD in `./variants/heltec_v3/platformio.ini` and then flash it to your device.
|
||||||
|
|
||||||
### 7.7. Q: I have a Station G2, or a Heltec V4, or an Ikoka Stick, or a radio with a EByte E22-900M30S or a E22-900M33S module, what should their transmit power be set to?
|
|
||||||
**A:**
|
|
||||||
For companion radios, you can set these radios' transmit power in the smartphone app. For repeater and room server radios, you can set their transmit power using the command line command `set tx`. You can get their current value using command line comand `get tx`
|
|
||||||
|
|
||||||
|
|
||||||
> ### ⚠️ **WARNING: Set these values at your own risk. Incorrect power settings can permanently damage your radio hardware.**
|
|
||||||
|
|
||||||
| Device / Model | Region / Description | In-App Setting (dBm) | Target Radio Output | Notes |
|
|
||||||
| :--- | :--- | :--- | :--- | :--- |
|
|
||||||
| **Station G2** <br> [Reference](https://wiki.uniteng.com/en/meshtastic/station-g2) | US915 Max Output | 19 dBm | 36.5 dBm (4.46W) | |
|
|
||||||
| | US915 Recommended Max | 16 dBm | 35 dBm (3.16W) | 1dB compression point |
|
|
||||||
| | EU868 Recommended Max | 15 dBm | 34.5 dBm (2.82W) | 1dB compression point |
|
|
||||||
| | US915 1W Output | 10 dBm | 1W | |
|
|
||||||
| | EU868 1W Output | 9 dBm | 1W | |
|
|
||||||
| **Ikoka Stick E22-900M30S** | 1W Model | 19 dBm | 1W | **DO NOT EXCEED** (Risk of burn out) |
|
|
||||||
| **Ikoka Stick E22-900M33S** | 2W Model | 9 dBm | 2W | **DO NOT EXCEED** (Risk of burn out) |
|
|
||||||
| **Heltec V4** | Standard Output | 10 dBm | 22 dBm | |
|
|
||||||
| | High Output | 22 dBm | 28 dBm | |
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
|
|||||||
file.read((uint8_t *)&_prefs.freq, sizeof(_prefs.freq)); // 56
|
file.read((uint8_t *)&_prefs.freq, sizeof(_prefs.freq)); // 56
|
||||||
file.read((uint8_t *)&_prefs.sf, sizeof(_prefs.sf)); // 60
|
file.read((uint8_t *)&_prefs.sf, sizeof(_prefs.sf)); // 60
|
||||||
file.read((uint8_t *)&_prefs.cr, sizeof(_prefs.cr)); // 61
|
file.read((uint8_t *)&_prefs.cr, sizeof(_prefs.cr)); // 61
|
||||||
file.read(pad, 1); // 62
|
file.read((uint8_t *)&_prefs.client_repeat, sizeof(_prefs.client_repeat)); // 62
|
||||||
file.read((uint8_t *)&_prefs.manual_add_contacts, sizeof(_prefs.manual_add_contacts)); // 63
|
file.read((uint8_t *)&_prefs.manual_add_contacts, sizeof(_prefs.manual_add_contacts)); // 63
|
||||||
file.read((uint8_t *)&_prefs.bw, sizeof(_prefs.bw)); // 64
|
file.read((uint8_t *)&_prefs.bw, sizeof(_prefs.bw)); // 64
|
||||||
file.read((uint8_t *)&_prefs.tx_power_dbm, sizeof(_prefs.tx_power_dbm)); // 68
|
file.read((uint8_t *)&_prefs.tx_power_dbm, sizeof(_prefs.tx_power_dbm)); // 68
|
||||||
@@ -222,12 +222,14 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
|
|||||||
file.read((uint8_t *)&_prefs.rx_delay_base, sizeof(_prefs.rx_delay_base)); // 72
|
file.read((uint8_t *)&_prefs.rx_delay_base, sizeof(_prefs.rx_delay_base)); // 72
|
||||||
file.read((uint8_t *)&_prefs.advert_loc_policy, sizeof(_prefs.advert_loc_policy)); // 76
|
file.read((uint8_t *)&_prefs.advert_loc_policy, sizeof(_prefs.advert_loc_policy)); // 76
|
||||||
file.read((uint8_t *)&_prefs.multi_acks, sizeof(_prefs.multi_acks)); // 77
|
file.read((uint8_t *)&_prefs.multi_acks, sizeof(_prefs.multi_acks)); // 77
|
||||||
file.read(pad, 2); // 78
|
file.read((uint8_t *)&_prefs.path_hash_mode, sizeof(_prefs.path_hash_mode)); // 78
|
||||||
|
file.read(pad, 1); // 79
|
||||||
file.read((uint8_t *)&_prefs.ble_pin, sizeof(_prefs.ble_pin)); // 80
|
file.read((uint8_t *)&_prefs.ble_pin, sizeof(_prefs.ble_pin)); // 80
|
||||||
file.read((uint8_t *)&_prefs.buzzer_quiet, sizeof(_prefs.buzzer_quiet)); // 84
|
file.read((uint8_t *)&_prefs.buzzer_quiet, sizeof(_prefs.buzzer_quiet)); // 84
|
||||||
file.read((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85
|
file.read((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85
|
||||||
file.read((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
|
file.read((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
|
||||||
file.read((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
|
file.read((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
|
||||||
|
file.read((uint8_t *)&_prefs.autoadd_max_hops, sizeof(_prefs.autoadd_max_hops)); // 88
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
@@ -247,7 +249,7 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
|
|||||||
file.write((uint8_t *)&_prefs.freq, sizeof(_prefs.freq)); // 56
|
file.write((uint8_t *)&_prefs.freq, sizeof(_prefs.freq)); // 56
|
||||||
file.write((uint8_t *)&_prefs.sf, sizeof(_prefs.sf)); // 60
|
file.write((uint8_t *)&_prefs.sf, sizeof(_prefs.sf)); // 60
|
||||||
file.write((uint8_t *)&_prefs.cr, sizeof(_prefs.cr)); // 61
|
file.write((uint8_t *)&_prefs.cr, sizeof(_prefs.cr)); // 61
|
||||||
file.write(pad, 1); // 62
|
file.write((uint8_t *)&_prefs.client_repeat, sizeof(_prefs.client_repeat)); // 62
|
||||||
file.write((uint8_t *)&_prefs.manual_add_contacts, sizeof(_prefs.manual_add_contacts)); // 63
|
file.write((uint8_t *)&_prefs.manual_add_contacts, sizeof(_prefs.manual_add_contacts)); // 63
|
||||||
file.write((uint8_t *)&_prefs.bw, sizeof(_prefs.bw)); // 64
|
file.write((uint8_t *)&_prefs.bw, sizeof(_prefs.bw)); // 64
|
||||||
file.write((uint8_t *)&_prefs.tx_power_dbm, sizeof(_prefs.tx_power_dbm)); // 68
|
file.write((uint8_t *)&_prefs.tx_power_dbm, sizeof(_prefs.tx_power_dbm)); // 68
|
||||||
@@ -257,12 +259,14 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
|
|||||||
file.write((uint8_t *)&_prefs.rx_delay_base, sizeof(_prefs.rx_delay_base)); // 72
|
file.write((uint8_t *)&_prefs.rx_delay_base, sizeof(_prefs.rx_delay_base)); // 72
|
||||||
file.write((uint8_t *)&_prefs.advert_loc_policy, sizeof(_prefs.advert_loc_policy)); // 76
|
file.write((uint8_t *)&_prefs.advert_loc_policy, sizeof(_prefs.advert_loc_policy)); // 76
|
||||||
file.write((uint8_t *)&_prefs.multi_acks, sizeof(_prefs.multi_acks)); // 77
|
file.write((uint8_t *)&_prefs.multi_acks, sizeof(_prefs.multi_acks)); // 77
|
||||||
file.write(pad, 2); // 78
|
file.write((uint8_t *)&_prefs.path_hash_mode, sizeof(_prefs.path_hash_mode)); // 78
|
||||||
|
file.write(pad, 1); // 79
|
||||||
file.write((uint8_t *)&_prefs.ble_pin, sizeof(_prefs.ble_pin)); // 80
|
file.write((uint8_t *)&_prefs.ble_pin, sizeof(_prefs.ble_pin)); // 80
|
||||||
file.write((uint8_t *)&_prefs.buzzer_quiet, sizeof(_prefs.buzzer_quiet)); // 84
|
file.write((uint8_t *)&_prefs.buzzer_quiet, sizeof(_prefs.buzzer_quiet)); // 84
|
||||||
file.write((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85
|
file.write((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85
|
||||||
file.write((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
|
file.write((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
|
||||||
file.write((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
|
file.write((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
|
||||||
|
file.write((uint8_t *)&_prefs.autoadd_max_hops, sizeof(_prefs.autoadd_max_hops)); // 88
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,8 @@
|
|||||||
#define CMD_SEND_ANON_REQ 57
|
#define CMD_SEND_ANON_REQ 57
|
||||||
#define CMD_SET_AUTOADD_CONFIG 58
|
#define CMD_SET_AUTOADD_CONFIG 58
|
||||||
#define CMD_GET_AUTOADD_CONFIG 59
|
#define CMD_GET_AUTOADD_CONFIG 59
|
||||||
|
#define CMD_GET_ALLOWED_REPEAT_FREQ 60
|
||||||
|
#define CMD_SET_PATH_HASH_MODE 61
|
||||||
|
|
||||||
// Stats sub-types for CMD_GET_STATS
|
// Stats sub-types for CMD_GET_STATS
|
||||||
#define STATS_TYPE_CORE 0
|
#define STATS_TYPE_CORE 0
|
||||||
@@ -88,6 +90,7 @@
|
|||||||
#define RESP_CODE_TUNING_PARAMS 23
|
#define RESP_CODE_TUNING_PARAMS 23
|
||||||
#define RESP_CODE_STATS 24 // v8+, second byte is stats type
|
#define RESP_CODE_STATS 24 // v8+, second byte is stats type
|
||||||
#define RESP_CODE_AUTOADD_CONFIG 25
|
#define RESP_CODE_AUTOADD_CONFIG 25
|
||||||
|
#define RESP_ALLOWED_REPEAT_FREQ 26
|
||||||
|
|
||||||
#define SEND_TIMEOUT_BASE_MILLIS 500
|
#define SEND_TIMEOUT_BASE_MILLIS 500
|
||||||
#define FLOOD_SEND_TIMEOUT_FACTOR 16.0f
|
#define FLOOD_SEND_TIMEOUT_FACTOR 16.0f
|
||||||
@@ -255,6 +258,15 @@ int MyMesh::calcRxDelay(float score, uint32_t air_time) const {
|
|||||||
return (int)((pow(_prefs.rx_delay_base, 0.85f - score) - 1.0) * air_time);
|
return (int)((pow(_prefs.rx_delay_base, 0.85f - score) - 1.0) * air_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) {
|
||||||
|
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * 0.5f);
|
||||||
|
return getRNG()->nextInt(0, 5*t + 1);
|
||||||
|
}
|
||||||
|
uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
|
||||||
|
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * 0.2f);
|
||||||
|
return getRNG()->nextInt(0, 5*t + 1);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t MyMesh::getExtraAckTransmitCount() const {
|
uint8_t MyMesh::getExtraAckTransmitCount() const {
|
||||||
return _prefs.multi_acks;
|
return _prefs.multi_acks;
|
||||||
}
|
}
|
||||||
@@ -306,6 +318,10 @@ bool MyMesh::shouldOverwriteWhenFull() const {
|
|||||||
return (_prefs.autoadd_config & AUTO_ADD_OVERWRITE_OLDEST) != 0;
|
return (_prefs.autoadd_config & AUTO_ADD_OVERWRITE_OLDEST) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t MyMesh::getAutoAddMaxHops() const {
|
||||||
|
return _prefs.autoadd_max_hops;
|
||||||
|
}
|
||||||
|
|
||||||
void MyMesh::onContactOverwrite(const uint8_t* pub_key) {
|
void MyMesh::onContactOverwrite(const uint8_t* pub_key) {
|
||||||
_store->deleteBlobByKey(pub_key, PUB_KEY_SIZE); // delete from storage
|
_store->deleteBlobByKey(pub_key, PUB_KEY_SIZE); // delete from storage
|
||||||
if (_serial->isConnected()) {
|
if (_serial->isConnected()) {
|
||||||
@@ -338,7 +354,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add inbound-path to mem cache
|
// add inbound-path to mem cache
|
||||||
if (path && path_len <= sizeof(AdvertPath::path)) { // check path is valid
|
if (path && mesh::Packet::isValidPathLen(path_len)) { // check path is valid
|
||||||
AdvertPath* p = advert_paths;
|
AdvertPath* p = advert_paths;
|
||||||
uint32_t oldest = 0xFFFFFFFF;
|
uint32_t oldest = 0xFFFFFFFF;
|
||||||
for (int i = 0; i < ADVERT_PATH_TABLE_SIZE; i++) { // check if already in table, otherwise evict oldest
|
for (int i = 0; i < ADVERT_PATH_TABLE_SIZE; i++) { // check if already in table, otherwise evict oldest
|
||||||
@@ -355,8 +371,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
|
|||||||
memcpy(p->pubkey_prefix, contact.id.pub_key, sizeof(p->pubkey_prefix));
|
memcpy(p->pubkey_prefix, contact.id.pub_key, sizeof(p->pubkey_prefix));
|
||||||
strcpy(p->name, contact.name);
|
strcpy(p->name, contact.name);
|
||||||
p->recv_timestamp = getRTCClock()->getCurrentTime();
|
p->recv_timestamp = getRTCClock()->getCurrentTime();
|
||||||
p->path_len = path_len;
|
p->path_len = mesh::Packet::copyPath(p->path, path, path_len);
|
||||||
memcpy(p->path, path, p->path_len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_new) dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); // only schedule lazy write for contacts that are in contacts[]
|
if (!is_new) dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); // only schedule lazy write for contacts that are in contacts[]
|
||||||
@@ -455,26 +470,30 @@ bool MyMesh::filterRecvFloodPacket(mesh::Packet* packet) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MyMesh::allowPacketForward(const mesh::Packet* packet) {
|
||||||
|
return _prefs.client_repeat != 0;
|
||||||
|
}
|
||||||
|
|
||||||
void MyMesh::sendFloodScoped(const ContactInfo& recipient, mesh::Packet* pkt, uint32_t delay_millis) {
|
void MyMesh::sendFloodScoped(const ContactInfo& recipient, mesh::Packet* pkt, uint32_t delay_millis) {
|
||||||
// TODO: dynamic send_scope, depending on recipient and current 'home' Region
|
// TODO: dynamic send_scope, depending on recipient and current 'home' Region
|
||||||
if (send_scope.isNull()) {
|
if (send_scope.isNull()) {
|
||||||
sendFlood(pkt, delay_millis);
|
sendFlood(pkt, delay_millis, _prefs.path_hash_mode + 1);
|
||||||
} else {
|
} else {
|
||||||
uint16_t codes[2];
|
uint16_t codes[2];
|
||||||
codes[0] = send_scope.calcTransportCode(pkt);
|
codes[0] = send_scope.calcTransportCode(pkt);
|
||||||
codes[1] = 0; // REVISIT: set to 'home' Region, for sender/return region?
|
codes[1] = 0; // REVISIT: set to 'home' Region, for sender/return region?
|
||||||
sendFlood(pkt, codes, delay_millis);
|
sendFlood(pkt, codes, delay_millis, _prefs.path_hash_mode + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MyMesh::sendFloodScoped(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t delay_millis) {
|
void MyMesh::sendFloodScoped(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t delay_millis) {
|
||||||
// TODO: have per-channel send_scope
|
// TODO: have per-channel send_scope
|
||||||
if (send_scope.isNull()) {
|
if (send_scope.isNull()) {
|
||||||
sendFlood(pkt, delay_millis);
|
sendFlood(pkt, delay_millis, _prefs.path_hash_mode + 1);
|
||||||
} else {
|
} else {
|
||||||
uint16_t codes[2];
|
uint16_t codes[2];
|
||||||
codes[0] = send_scope.calcTransportCode(pkt);
|
codes[0] = send_scope.calcTransportCode(pkt);
|
||||||
codes[1] = 0; // REVISIT: set to 'home' Region, for sender/return region?
|
codes[1] = 0; // REVISIT: set to 'home' Region, for sender/return region?
|
||||||
sendFlood(pkt, codes, delay_millis);
|
sendFlood(pkt, codes, delay_millis, _prefs.path_hash_mode + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -671,7 +690,7 @@ bool MyMesh::onContactPathRecv(ContactInfo& contact, uint8_t* in_path, uint8_t i
|
|||||||
if (tag == pending_discovery) { // check for matching response tag)
|
if (tag == pending_discovery) { // check for matching response tag)
|
||||||
pending_discovery = 0;
|
pending_discovery = 0;
|
||||||
|
|
||||||
if (in_path_len > MAX_PATH_SIZE || out_path_len > MAX_PATH_SIZE) {
|
if (!mesh::Packet::isValidPathLen(in_path_len) || !mesh::Packet::isValidPathLen(out_path_len)) {
|
||||||
MESH_DEBUG_PRINTLN("onContactPathRecv, invalid path sizes: %d, %d", in_path_len, out_path_len);
|
MESH_DEBUG_PRINTLN("onContactPathRecv, invalid path sizes: %d, %d", in_path_len, out_path_len);
|
||||||
} else {
|
} else {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -680,11 +699,9 @@ bool MyMesh::onContactPathRecv(ContactInfo& contact, uint8_t* in_path, uint8_t i
|
|||||||
memcpy(&out_frame[i], contact.id.pub_key, 6);
|
memcpy(&out_frame[i], contact.id.pub_key, 6);
|
||||||
i += 6; // pub_key_prefix
|
i += 6; // pub_key_prefix
|
||||||
out_frame[i++] = out_path_len;
|
out_frame[i++] = out_path_len;
|
||||||
memcpy(&out_frame[i], out_path, out_path_len);
|
i += mesh::Packet::writePath(&out_frame[i], out_path, out_path_len);
|
||||||
i += out_path_len;
|
|
||||||
out_frame[i++] = in_path_len;
|
out_frame[i++] = in_path_len;
|
||||||
memcpy(&out_frame[i], in_path, in_path_len);
|
i += mesh::Packet::writePath(&out_frame[i], in_path, in_path_len);
|
||||||
i += in_path_len;
|
|
||||||
// NOTE: telemetry data in 'extra' is discarded at present
|
// NOTE: telemetry data in 'extra' is discarded at present
|
||||||
|
|
||||||
_serial->writeFrame(out_frame, i);
|
_serial->writeFrame(out_frame, i);
|
||||||
@@ -770,9 +787,10 @@ uint32_t MyMesh::calcFloodTimeoutMillisFor(uint32_t pkt_airtime_millis) const {
|
|||||||
return SEND_TIMEOUT_BASE_MILLIS + (FLOOD_SEND_TIMEOUT_FACTOR * pkt_airtime_millis);
|
return SEND_TIMEOUT_BASE_MILLIS + (FLOOD_SEND_TIMEOUT_FACTOR * pkt_airtime_millis);
|
||||||
}
|
}
|
||||||
uint32_t MyMesh::calcDirectTimeoutMillisFor(uint32_t pkt_airtime_millis, uint8_t path_len) const {
|
uint32_t MyMesh::calcDirectTimeoutMillisFor(uint32_t pkt_airtime_millis, uint8_t path_len) const {
|
||||||
|
uint8_t path_hash_count = path_len & 63;
|
||||||
return SEND_TIMEOUT_BASE_MILLIS +
|
return SEND_TIMEOUT_BASE_MILLIS +
|
||||||
((pkt_airtime_millis * DIRECT_SEND_PERHOP_FACTOR + DIRECT_SEND_PERHOP_EXTRA_MILLIS) *
|
((pkt_airtime_millis * DIRECT_SEND_PERHOP_FACTOR + DIRECT_SEND_PERHOP_EXTRA_MILLIS) *
|
||||||
(path_len + 1));
|
(path_hash_count + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyMesh::onSendTimeout() {}
|
void MyMesh::onSendTimeout() {}
|
||||||
@@ -793,7 +811,7 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
|
|||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
memset(&_prefs, 0, sizeof(_prefs));
|
memset(&_prefs, 0, sizeof(_prefs));
|
||||||
_prefs.airtime_factor = 1.0;
|
_prefs.airtime_factor = 1.0; // one half
|
||||||
strcpy(_prefs.node_name, "NONAME");
|
strcpy(_prefs.node_name, "NONAME");
|
||||||
_prefs.freq = LORA_FREQ;
|
_prefs.freq = LORA_FREQ;
|
||||||
_prefs.sf = LORA_SF;
|
_prefs.sf = LORA_SF;
|
||||||
@@ -881,6 +899,24 @@ uint32_t MyMesh::getBLEPin() {
|
|||||||
return _active_ble_pin;
|
return _active_ble_pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct FreqRange {
|
||||||
|
uint32_t lower_freq, upper_freq;
|
||||||
|
};
|
||||||
|
|
||||||
|
static FreqRange repeat_freq_ranges[] = {
|
||||||
|
{ 433000, 433000 },
|
||||||
|
{ 869000, 869000 },
|
||||||
|
{ 918000, 918000 }
|
||||||
|
};
|
||||||
|
|
||||||
|
bool MyMesh::isValidClientRepeatFreq(uint32_t f) const {
|
||||||
|
for (int i = 0; i < sizeof(repeat_freq_ranges)/sizeof(repeat_freq_ranges[0]); i++) {
|
||||||
|
auto r = &repeat_freq_ranges[i];
|
||||||
|
if (f >= r->lower_freq && f <= r->upper_freq) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void MyMesh::startInterface(BaseSerialInterface &serial) {
|
void MyMesh::startInterface(BaseSerialInterface &serial) {
|
||||||
_serial = &serial;
|
_serial = &serial;
|
||||||
serial.enable();
|
serial.enable();
|
||||||
@@ -904,6 +940,8 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
i += 40;
|
i += 40;
|
||||||
StrHelper::strzcpy((char *)&out_frame[i], FIRMWARE_VERSION, 20);
|
StrHelper::strzcpy((char *)&out_frame[i], FIRMWARE_VERSION, 20);
|
||||||
i += 20;
|
i += 20;
|
||||||
|
out_frame[i++] = _prefs.client_repeat; // v9+
|
||||||
|
out_frame[i++] = _prefs.path_hash_mode; // v10+
|
||||||
_serial->writeFrame(out_frame, i);
|
_serial->writeFrame(out_frame, i);
|
||||||
} else if (cmd_frame[0] == CMD_APP_START &&
|
} else if (cmd_frame[0] == CMD_APP_START &&
|
||||||
len >= 8) { // sent when app establishes connection, respond with node ID
|
len >= 8) { // sent when app establishes connection, respond with node ID
|
||||||
@@ -1081,7 +1119,8 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
}
|
}
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
if (len >= 2 && cmd_frame[1] == 1) { // optional param (1 = flood, 0 = zero hop)
|
if (len >= 2 && cmd_frame[1] == 1) { // optional param (1 = flood, 0 = zero hop)
|
||||||
sendFlood(pkt);
|
unsigned long delay_millis = 0;
|
||||||
|
sendFlood(pkt, delay_millis, _prefs.path_hash_mode + 1);
|
||||||
} else {
|
} else {
|
||||||
sendZeroHop(pkt);
|
sendZeroHop(pkt);
|
||||||
}
|
}
|
||||||
@@ -1093,7 +1132,7 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
uint8_t *pub_key = &cmd_frame[1];
|
uint8_t *pub_key = &cmd_frame[1];
|
||||||
ContactInfo *recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE);
|
ContactInfo *recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE);
|
||||||
if (recipient) {
|
if (recipient) {
|
||||||
recipient->out_path_len = -1;
|
recipient->out_path_len = OUT_PATH_UNKNOWN;
|
||||||
// recipient->lastmod = ?? shouldn't be needed, app already has this version of contact
|
// recipient->lastmod = ?? shouldn't be needed, app already has this version of contact
|
||||||
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
||||||
writeOKFrame();
|
writeOKFrame();
|
||||||
@@ -1208,13 +1247,20 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
i += 4;
|
i += 4;
|
||||||
uint8_t sf = cmd_frame[i++];
|
uint8_t sf = cmd_frame[i++];
|
||||||
uint8_t cr = cmd_frame[i++];
|
uint8_t cr = cmd_frame[i++];
|
||||||
|
uint8_t repeat = 0; // default - false
|
||||||
|
if (len > i) {
|
||||||
|
repeat = cmd_frame[i++]; // FIRMWARE_VER_CODE 9+
|
||||||
|
}
|
||||||
|
|
||||||
if (freq >= 300000 && freq <= 2500000 && sf >= 5 && sf <= 12 && cr >= 5 && cr <= 8 && bw >= 7000 &&
|
if (repeat && !isValidClientRepeatFreq(freq)) {
|
||||||
|
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||||
|
} else if (freq >= 300000 && freq <= 2500000 && sf >= 5 && sf <= 12 && cr >= 5 && cr <= 8 && bw >= 7000 &&
|
||||||
bw <= 500000) {
|
bw <= 500000) {
|
||||||
_prefs.sf = sf;
|
_prefs.sf = sf;
|
||||||
_prefs.cr = cr;
|
_prefs.cr = cr;
|
||||||
_prefs.freq = (float)freq / 1000.0;
|
_prefs.freq = (float)freq / 1000.0;
|
||||||
_prefs.bw = (float)bw / 1000.0;
|
_prefs.bw = (float)bw / 1000.0;
|
||||||
|
_prefs.client_repeat = repeat;
|
||||||
savePrefs();
|
savePrefs();
|
||||||
|
|
||||||
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
|
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
|
||||||
@@ -1271,6 +1317,14 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
}
|
}
|
||||||
savePrefs();
|
savePrefs();
|
||||||
writeOKFrame();
|
writeOKFrame();
|
||||||
|
} else if (cmd_frame[0] == CMD_SET_PATH_HASH_MODE && cmd_frame[1] == 0 && len >= 3) {
|
||||||
|
if (cmd_frame[2] >= 3) {
|
||||||
|
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||||
|
} else {
|
||||||
|
_prefs.path_hash_mode = cmd_frame[2];
|
||||||
|
savePrefs();
|
||||||
|
writeOKFrame();
|
||||||
|
}
|
||||||
} else if (cmd_frame[0] == CMD_REBOOT && memcmp(&cmd_frame[1], "reboot", 6) == 0) {
|
} else if (cmd_frame[0] == CMD_REBOOT && memcmp(&cmd_frame[1], "reboot", 6) == 0) {
|
||||||
if (dirty_contacts_expiry) { // is there are pending dirty contacts write needed?
|
if (dirty_contacts_expiry) { // is there are pending dirty contacts write needed?
|
||||||
saveContacts();
|
saveContacts();
|
||||||
@@ -1408,7 +1462,7 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
memset(&req_data[2], 0, 3); // reserved
|
memset(&req_data[2], 0, 3); // reserved
|
||||||
getRNG()->random(&req_data[5], 4); // random blob to help make packet-hash unique
|
getRNG()->random(&req_data[5], 4); // random blob to help make packet-hash unique
|
||||||
auto save = recipient->out_path_len; // temporarily force sendRequest() to flood
|
auto save = recipient->out_path_len; // temporarily force sendRequest() to flood
|
||||||
recipient->out_path_len = -1;
|
recipient->out_path_len = OUT_PATH_UNKNOWN;
|
||||||
int result = sendRequest(*recipient, req_data, sizeof(req_data), tag, est_timeout);
|
int result = sendRequest(*recipient, req_data, sizeof(req_data), tag, est_timeout);
|
||||||
recipient->out_path_len = save;
|
recipient->out_path_len = save;
|
||||||
if (result == MSG_SEND_FAILED) {
|
if (result == MSG_SEND_FAILED) {
|
||||||
@@ -1645,11 +1699,12 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found) {
|
if (found) {
|
||||||
out_frame[0] = RESP_CODE_ADVERT_PATH;
|
int i = 0;
|
||||||
memcpy(&out_frame[1], &found->recv_timestamp, 4);
|
out_frame[i++] = RESP_CODE_ADVERT_PATH;
|
||||||
out_frame[5] = found->path_len;
|
memcpy(&out_frame[i], &found->recv_timestamp, 4); i += 4;
|
||||||
memcpy(&out_frame[6], found->path, found->path_len);
|
out_frame[i++] = found->path_len;
|
||||||
_serial->writeFrame(out_frame, 6 + found->path_len);
|
i += mesh::Packet::writePath(&out_frame[i], found->path, found->path_len);
|
||||||
|
_serial->writeFrame(out_frame, i);
|
||||||
} else {
|
} else {
|
||||||
writeErrFrame(ERR_CODE_NOT_FOUND);
|
writeErrFrame(ERR_CODE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
@@ -1734,12 +1789,25 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
}
|
}
|
||||||
} else if (cmd_frame[0] == CMD_SET_AUTOADD_CONFIG) {
|
} else if (cmd_frame[0] == CMD_SET_AUTOADD_CONFIG) {
|
||||||
_prefs.autoadd_config = cmd_frame[1];
|
_prefs.autoadd_config = cmd_frame[1];
|
||||||
|
if (len >= 3) {
|
||||||
|
_prefs.autoadd_max_hops = min(cmd_frame[2], (uint8_t)64);
|
||||||
|
}
|
||||||
savePrefs();
|
savePrefs();
|
||||||
writeOKFrame();
|
writeOKFrame();
|
||||||
} else if (cmd_frame[0] == CMD_GET_AUTOADD_CONFIG) {
|
} else if (cmd_frame[0] == CMD_GET_AUTOADD_CONFIG) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
out_frame[i++] = RESP_CODE_AUTOADD_CONFIG;
|
out_frame[i++] = RESP_CODE_AUTOADD_CONFIG;
|
||||||
out_frame[i++] = _prefs.autoadd_config;
|
out_frame[i++] = _prefs.autoadd_config;
|
||||||
|
out_frame[i++] = _prefs.autoadd_max_hops;
|
||||||
|
_serial->writeFrame(out_frame, i);
|
||||||
|
} else if (cmd_frame[0] == CMD_GET_ALLOWED_REPEAT_FREQ) {
|
||||||
|
int i = 0;
|
||||||
|
out_frame[i++] = RESP_ALLOWED_REPEAT_FREQ;
|
||||||
|
for (int k = 0; k < sizeof(repeat_freq_ranges)/sizeof(repeat_freq_ranges[0]) && i + 8 < sizeof(out_frame); k++) {
|
||||||
|
auto r = &repeat_freq_ranges[k];
|
||||||
|
memcpy(&out_frame[i], &r->lower_freq, 4); i += 4;
|
||||||
|
memcpy(&out_frame[i], &r->upper_freq, 4); i += 4;
|
||||||
|
}
|
||||||
_serial->writeFrame(out_frame, i);
|
_serial->writeFrame(out_frame, i);
|
||||||
} else {
|
} else {
|
||||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
#include "AbstractUITask.h"
|
#include "AbstractUITask.h"
|
||||||
|
|
||||||
/*------------ Frame Protocol --------------*/
|
/*------------ Frame Protocol --------------*/
|
||||||
#define FIRMWARE_VER_CODE 8
|
#define FIRMWARE_VER_CODE 10
|
||||||
|
|
||||||
#ifndef FIRMWARE_BUILD_DATE
|
#ifndef FIRMWARE_BUILD_DATE
|
||||||
#define FIRMWARE_BUILD_DATE "29 Jan 2026"
|
#define FIRMWARE_BUILD_DATE "15 Feb 2026"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FIRMWARE_VERSION
|
#ifndef FIRMWARE_VERSION
|
||||||
#define FIRMWARE_VERSION "v1.12.0"
|
#define FIRMWARE_VERSION "v1.13.0"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||||
@@ -106,8 +106,11 @@ protected:
|
|||||||
float getAirtimeBudgetFactor() const override;
|
float getAirtimeBudgetFactor() const override;
|
||||||
int getInterferenceThreshold() const override;
|
int getInterferenceThreshold() const override;
|
||||||
int calcRxDelay(float score, uint32_t air_time) const override;
|
int calcRxDelay(float score, uint32_t air_time) const override;
|
||||||
|
uint32_t getRetransmitDelay(const mesh::Packet *packet) override;
|
||||||
|
uint32_t getDirectRetransmitDelay(const mesh::Packet *packet) override;
|
||||||
uint8_t getExtraAckTransmitCount() const override;
|
uint8_t getExtraAckTransmitCount() const override;
|
||||||
bool filterRecvFloodPacket(mesh::Packet* packet) override;
|
bool filterRecvFloodPacket(mesh::Packet* packet) override;
|
||||||
|
bool allowPacketForward(const mesh::Packet* packet) override;
|
||||||
|
|
||||||
void sendFloodScoped(const ContactInfo& recipient, mesh::Packet* pkt, uint32_t delay_millis=0) override;
|
void sendFloodScoped(const ContactInfo& recipient, mesh::Packet* pkt, uint32_t delay_millis=0) override;
|
||||||
void sendFloodScoped(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t delay_millis=0) override;
|
void sendFloodScoped(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t delay_millis=0) override;
|
||||||
@@ -116,6 +119,7 @@ protected:
|
|||||||
bool isAutoAddEnabled() const override;
|
bool isAutoAddEnabled() const override;
|
||||||
bool shouldAutoAddContactType(uint8_t type) const override;
|
bool shouldAutoAddContactType(uint8_t type) const override;
|
||||||
bool shouldOverwriteWhenFull() const override;
|
bool shouldOverwriteWhenFull() const override;
|
||||||
|
uint8_t getAutoAddMaxHops() const override;
|
||||||
void onContactsFull() override;
|
void onContactsFull() override;
|
||||||
void onContactOverwrite(const uint8_t* pub_key) override;
|
void onContactOverwrite(const uint8_t* pub_key) override;
|
||||||
bool onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_t in_path_len, uint8_t* out_path, uint8_t out_path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override;
|
bool onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_t in_path_len, uint8_t* out_path, uint8_t out_path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override;
|
||||||
@@ -176,6 +180,7 @@ private:
|
|||||||
|
|
||||||
void checkCLIRescueCmd();
|
void checkCLIRescueCmd();
|
||||||
void checkSerialInterface();
|
void checkSerialInterface();
|
||||||
|
bool isValidClientRepeatFreq(uint32_t f) const;
|
||||||
|
|
||||||
// helpers, short-cuts
|
// helpers, short-cuts
|
||||||
void saveChannels() { _store->saveChannels(this); }
|
void saveChannels() { _store->saveChannels(this); }
|
||||||
|
|||||||
@@ -28,4 +28,7 @@ struct NodePrefs { // persisted to file
|
|||||||
uint8_t gps_enabled; // GPS enabled flag (0=disabled, 1=enabled)
|
uint8_t gps_enabled; // GPS enabled flag (0=disabled, 1=enabled)
|
||||||
uint32_t gps_interval; // GPS read interval in seconds
|
uint32_t gps_interval; // GPS read interval in seconds
|
||||||
uint8_t autoadd_config; // bitmask for auto-add contacts config
|
uint8_t autoadd_config; // bitmask for auto-add contacts config
|
||||||
|
uint8_t client_repeat;
|
||||||
|
uint8_t path_hash_mode; // which path mode to use when sending
|
||||||
|
uint8_t autoadd_max_hops; // 0 = no limit, 1 = direct (0 hops), N = up to N-1 hops (max 64)
|
||||||
};
|
};
|
||||||
@@ -131,6 +131,14 @@ class HomeScreen : public UIScreen {
|
|||||||
// fill the battery based on the percentage
|
// fill the battery based on the percentage
|
||||||
int fillWidth = (batteryPercentage * (iconWidth - 4)) / 100;
|
int fillWidth = (batteryPercentage * (iconWidth - 4)) / 100;
|
||||||
display.fillRect(iconX + 2, iconY + 2, fillWidth, iconHeight - 4);
|
display.fillRect(iconX + 2, iconY + 2, fillWidth, iconHeight - 4);
|
||||||
|
|
||||||
|
// show muted icon if buzzer is muted
|
||||||
|
#ifdef PIN_BUZZER
|
||||||
|
if (_task->isBuzzerQuiet()) {
|
||||||
|
display.setColor(DisplayDriver::RED);
|
||||||
|
display.drawXbm(iconX - 9, iconY + 1, muted_icon, 8, 8);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CayenneLPP sensors_lpp;
|
CayenneLPP sensors_lpp;
|
||||||
|
|||||||
@@ -78,6 +78,14 @@ public:
|
|||||||
bool hasDisplay() const { return _display != NULL; }
|
bool hasDisplay() const { return _display != NULL; }
|
||||||
bool isButtonPressed() const;
|
bool isButtonPressed() const;
|
||||||
|
|
||||||
|
bool isBuzzerQuiet() {
|
||||||
|
#ifdef PIN_BUZZER
|
||||||
|
return buzzer.isQuiet();
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void toggleBuzzer();
|
void toggleBuzzer();
|
||||||
bool getGPSState();
|
bool getGPSState();
|
||||||
void toggleGPS();
|
void toggleGPS();
|
||||||
|
|||||||
@@ -116,3 +116,7 @@ static const uint8_t advert_icon[] = {
|
|||||||
0x04, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x04, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const uint8_t muted_icon[] = {
|
||||||
|
0x20, 0x6a, 0xea, 0xe4, 0xe4, 0xea, 0x6a, 0x20
|
||||||
|
};
|
||||||
@@ -129,7 +129,7 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_flood) {
|
if (is_flood) {
|
||||||
client->out_path_len = -1; // need to rediscover out_path
|
client->out_path_len = OUT_PATH_UNKNOWN; // need to rediscover out_path
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t now = getRTCClock()->getCurrentTimeUnique();
|
uint32_t now = getRTCClock()->getCurrentTimeUnique();
|
||||||
@@ -147,9 +147,12 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
|
|||||||
uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
|
uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
|
||||||
if (anon_limiter.allow(rtc_clock.getCurrentTime())) {
|
if (anon_limiter.allow(rtc_clock.getCurrentTime())) {
|
||||||
// request data has: {reply-path-len}{reply-path}
|
// request data has: {reply-path-len}{reply-path}
|
||||||
reply_path_len = *data++ & 0x3F;
|
reply_path_len = *data & 63;
|
||||||
memcpy(reply_path, data, reply_path_len);
|
reply_path_hash_size = (*data >> 6) + 1;
|
||||||
// data += reply_path_len;
|
data++;
|
||||||
|
|
||||||
|
memcpy(reply_path, data, ((uint8_t)reply_path_len) * reply_path_hash_size);
|
||||||
|
// data += (uint8_t)reply_path_len * reply_path_hash_size;
|
||||||
|
|
||||||
memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag
|
memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag
|
||||||
uint32_t now = getRTCClock()->getCurrentTime();
|
uint32_t now = getRTCClock()->getCurrentTime();
|
||||||
@@ -163,9 +166,12 @@ uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t send
|
|||||||
uint8_t MyMesh::handleAnonOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
|
uint8_t MyMesh::handleAnonOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
|
||||||
if (anon_limiter.allow(rtc_clock.getCurrentTime())) {
|
if (anon_limiter.allow(rtc_clock.getCurrentTime())) {
|
||||||
// request data has: {reply-path-len}{reply-path}
|
// request data has: {reply-path-len}{reply-path}
|
||||||
reply_path_len = *data++ & 0x3F;
|
reply_path_len = *data & 63;
|
||||||
memcpy(reply_path, data, reply_path_len);
|
reply_path_hash_size = (*data >> 6) + 1;
|
||||||
// data += reply_path_len;
|
data++;
|
||||||
|
|
||||||
|
memcpy(reply_path, data, ((uint8_t)reply_path_len) * reply_path_hash_size);
|
||||||
|
// data += (uint8_t)reply_path_len * reply_path_hash_size;
|
||||||
|
|
||||||
memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag
|
memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag
|
||||||
uint32_t now = getRTCClock()->getCurrentTime();
|
uint32_t now = getRTCClock()->getCurrentTime();
|
||||||
@@ -180,9 +186,12 @@ uint8_t MyMesh::handleAnonOwnerReq(const mesh::Identity& sender, uint32_t sender
|
|||||||
uint8_t MyMesh::handleAnonClockReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
|
uint8_t MyMesh::handleAnonClockReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
|
||||||
if (anon_limiter.allow(rtc_clock.getCurrentTime())) {
|
if (anon_limiter.allow(rtc_clock.getCurrentTime())) {
|
||||||
// request data has: {reply-path-len}{reply-path}
|
// request data has: {reply-path-len}{reply-path}
|
||||||
reply_path_len = *data++ & 0x3F;
|
reply_path_len = *data & 63;
|
||||||
memcpy(reply_path, data, reply_path_len);
|
reply_path_hash_size = (*data >> 6) + 1;
|
||||||
// data += reply_path_len;
|
data++;
|
||||||
|
|
||||||
|
memcpy(reply_path, data, ((uint8_t)reply_path_len) * reply_path_hash_size);
|
||||||
|
// data += (uint8_t)reply_path_len * reply_path_hash_size;
|
||||||
|
|
||||||
memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag
|
memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag
|
||||||
uint32_t now = getRTCClock()->getCurrentTime();
|
uint32_t now = getRTCClock()->getCurrentTime();
|
||||||
@@ -292,6 +301,7 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
|
|||||||
|
|
||||||
// create copy of neighbours list, skipping empty entries so we can sort it separately from main list
|
// create copy of neighbours list, skipping empty entries so we can sort it separately from main list
|
||||||
int16_t neighbours_count = 0;
|
int16_t neighbours_count = 0;
|
||||||
|
#if MAX_NEIGHBOURS
|
||||||
NeighbourInfo* sorted_neighbours[MAX_NEIGHBOURS];
|
NeighbourInfo* sorted_neighbours[MAX_NEIGHBOURS];
|
||||||
for (int i = 0; i < MAX_NEIGHBOURS; i++) {
|
for (int i = 0; i < MAX_NEIGHBOURS; i++) {
|
||||||
auto neighbour = &neighbours[i];
|
auto neighbour = &neighbours[i];
|
||||||
@@ -327,6 +337,7 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
|
|||||||
return a->snr < b->snr; // asc
|
return a->snr < b->snr; // asc
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// build results buffer
|
// build results buffer
|
||||||
int results_count = 0;
|
int results_count = 0;
|
||||||
@@ -341,6 +352,7 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MAX_NEIGHBOURS
|
||||||
// add next neighbour to results
|
// add next neighbour to results
|
||||||
auto neighbour = sorted_neighbours[index + offset];
|
auto neighbour = sorted_neighbours[index + offset];
|
||||||
uint32_t heard_seconds_ago = getRTCClock()->getCurrentTime() - neighbour->heard_timestamp;
|
uint32_t heard_seconds_ago = getRTCClock()->getCurrentTime() - neighbour->heard_timestamp;
|
||||||
@@ -348,6 +360,7 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
|
|||||||
memcpy(&results_buffer[results_offset], &heard_seconds_ago, 4); results_offset += 4;
|
memcpy(&results_buffer[results_offset], &heard_seconds_ago, 4); results_offset += 4;
|
||||||
memcpy(&results_buffer[results_offset], &neighbour->snr, 1); results_offset += 1;
|
memcpy(&results_buffer[results_offset], &neighbour->snr, 1); results_offset += 1;
|
||||||
results_count++;
|
results_count++;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,21 +396,53 @@ File MyMesh::openAppend(const char *fname) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t max_loop_minimal[] = { 0, /* 1-byte */ 4, /* 2-byte */ 2, /* 3-byte */ 1 };
|
||||||
|
static uint8_t max_loop_moderate[] = { 0, /* 1-byte */ 2, /* 2-byte */ 1, /* 3-byte */ 1 };
|
||||||
|
static uint8_t max_loop_strict[] = { 0, /* 1-byte */ 1, /* 2-byte */ 1, /* 3-byte */ 1 };
|
||||||
|
|
||||||
|
bool MyMesh::isLooped(const mesh::Packet* packet, const uint8_t max_counters[]) {
|
||||||
|
uint8_t hash_size = packet->getPathHashSize();
|
||||||
|
uint8_t hash_count = packet->getPathHashCount();
|
||||||
|
uint8_t n = 0;
|
||||||
|
const uint8_t* path = packet->path;
|
||||||
|
while (hash_count > 0) { // count how many times this node is already in the path
|
||||||
|
if (self_id.isHashMatch(path, hash_size)) n++;
|
||||||
|
hash_count--;
|
||||||
|
path += hash_size;
|
||||||
|
}
|
||||||
|
return n >= max_counters[hash_size];
|
||||||
|
}
|
||||||
|
|
||||||
bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
|
bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
|
||||||
if (_prefs.disable_fwd) return false;
|
if (_prefs.disable_fwd) return false;
|
||||||
if (packet->isRouteFlood() && packet->path_len >= _prefs.flood_max) return false;
|
if (packet->isRouteFlood() && packet->getPathHashCount() >= _prefs.flood_max) return false;
|
||||||
if (packet->isRouteFlood() && recv_pkt_region == NULL) {
|
if (packet->isRouteFlood() && recv_pkt_region == NULL) {
|
||||||
MESH_DEBUG_PRINTLN("allowPacketForward: unknown transport code, or wildcard not allowed for FLOOD packet");
|
MESH_DEBUG_PRINTLN("allowPacketForward: unknown transport code, or wildcard not allowed for FLOOD packet");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (packet->isRouteFlood() && _prefs.loop_detect != LOOP_DETECT_OFF) {
|
||||||
|
const uint8_t* maximums;
|
||||||
|
if (_prefs.loop_detect == LOOP_DETECT_MINIMAL) {
|
||||||
|
maximums = max_loop_minimal;
|
||||||
|
} else if (_prefs.loop_detect == LOOP_DETECT_MODERATE) {
|
||||||
|
maximums = max_loop_moderate;
|
||||||
|
} else {
|
||||||
|
maximums = max_loop_strict;
|
||||||
|
}
|
||||||
|
if (isLooped(packet, maximums)) {
|
||||||
|
MESH_DEBUG_PRINTLN("allowPacketForward: FLOOD packet loop detected!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Limit flood advert paket forwarding using a probabilistic reduction defined by P(h) = 0.308^(hops-1)
|
// Limit flood advert paket forwarding using a probabilistic reduction defined by P(h) = 0.308^(hops-1)
|
||||||
// https://github.com/meshcore-dev/MeshCore/issues/1223
|
// https://github.com/meshcore-dev/MeshCore/issues/1223
|
||||||
double_t roll_dice = (double)rand() / RAND_MAX;
|
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->isRouteFlood()) {
|
||||||
double_t forw_prob = pow(_prefs.flood_advert_base, packet->path_len - 1);
|
double roll_dice = (double)rand() / RAND_MAX;
|
||||||
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->isRouteFlood() && roll_dice > forw_prob)
|
double forw_prob = pow(_prefs.flood_advert_base, packet->path_len - 1);
|
||||||
return false;
|
if (roll_dice > forw_prob)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// all other packets
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,11 +533,11 @@ int MyMesh::calcRxDelay(float score, uint32_t air_time) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) {
|
uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) {
|
||||||
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.tx_delay_factor);
|
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * _prefs.tx_delay_factor);
|
||||||
return getRNG()->nextInt(0, 5*t + 1);
|
return getRNG()->nextInt(0, 5*t + 1);
|
||||||
}
|
}
|
||||||
uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
|
uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
|
||||||
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
|
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
|
||||||
return getRNG()->nextInt(0, 5*t + 1);
|
return getRNG()->nextInt(0, 5*t + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,13 +587,14 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
|
|||||||
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
||||||
mesh::Packet* path = createPathReturn(sender, secret, packet->path, packet->path_len,
|
mesh::Packet* path = createPathReturn(sender, secret, packet->path, packet->path_len,
|
||||||
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
|
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
|
||||||
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
|
if (path) sendFlood(path, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
} else if (reply_path_len < 0) {
|
} else if (reply_path_len < 0) {
|
||||||
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len);
|
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len);
|
||||||
if (reply) sendFlood(reply, SERVER_RESPONSE_DELAY);
|
if (reply) sendFlood(reply, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
} else {
|
} else {
|
||||||
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len);
|
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len);
|
||||||
if (reply) sendDirect(reply, reply_path, reply_path_len, SERVER_RESPONSE_DELAY);
|
uint8_t path_len = ((reply_path_hash_size - 1) << 6) | (reply_path_len & 63);
|
||||||
|
if (reply) sendDirect(reply, reply_path, path_len, SERVER_RESPONSE_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -617,15 +663,15 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
|||||||
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
||||||
mesh::Packet *path = createPathReturn(client->id, secret, packet->path, packet->path_len,
|
mesh::Packet *path = createPathReturn(client->id, secret, packet->path, packet->path_len,
|
||||||
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
|
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
|
||||||
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
|
if (path) sendFlood(path, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
} else {
|
} else {
|
||||||
mesh::Packet *reply =
|
mesh::Packet *reply =
|
||||||
createDatagram(PAYLOAD_TYPE_RESPONSE, client->id, secret, reply_data, reply_len);
|
createDatagram(PAYLOAD_TYPE_RESPONSE, client->id, secret, reply_data, reply_len);
|
||||||
if (reply) {
|
if (reply) {
|
||||||
if (client->out_path_len >= 0) { // we have an out_path, so send DIRECT
|
if (client->out_path_len != OUT_PATH_UNKNOWN) { // we have an out_path, so send DIRECT
|
||||||
sendDirect(reply, client->out_path, client->out_path_len, SERVER_RESPONSE_DELAY);
|
sendDirect(reply, client->out_path, client->out_path_len, SERVER_RESPONSE_DELAY);
|
||||||
} else {
|
} else {
|
||||||
sendFlood(reply, SERVER_RESPONSE_DELAY);
|
sendFlood(reply, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,8 +701,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
|||||||
|
|
||||||
mesh::Packet *ack = createAck(ack_hash);
|
mesh::Packet *ack = createAck(ack_hash);
|
||||||
if (ack) {
|
if (ack) {
|
||||||
if (client->out_path_len < 0) {
|
if (client->out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFlood(ack, TXT_ACK_DELAY);
|
sendFlood(ack, TXT_ACK_DELAY, packet->getPathHashSize());
|
||||||
} else {
|
} else {
|
||||||
sendDirect(ack, client->out_path, client->out_path_len, TXT_ACK_DELAY);
|
sendDirect(ack, client->out_path, client->out_path_len, TXT_ACK_DELAY);
|
||||||
}
|
}
|
||||||
@@ -683,8 +729,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
|||||||
|
|
||||||
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len);
|
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len);
|
||||||
if (reply) {
|
if (reply) {
|
||||||
if (client->out_path_len < 0) {
|
if (client->out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFlood(reply, CLI_REPLY_DELAY_MILLIS);
|
sendFlood(reply, CLI_REPLY_DELAY_MILLIS, packet->getPathHashSize());
|
||||||
} else {
|
} else {
|
||||||
sendDirect(reply, client->out_path, client->out_path_len, CLI_REPLY_DELAY_MILLIS);
|
sendDirect(reply, client->out_path, client->out_path_len, CLI_REPLY_DELAY_MILLIS);
|
||||||
}
|
}
|
||||||
@@ -705,7 +751,8 @@ bool MyMesh::onPeerPathRecv(mesh::Packet *packet, int sender_idx, const uint8_t
|
|||||||
MESH_DEBUG_PRINTLN("PATH to client, path_len=%d", (uint32_t)path_len);
|
MESH_DEBUG_PRINTLN("PATH to client, path_len=%d", (uint32_t)path_len);
|
||||||
auto client = acl.getClientByIdx(i);
|
auto client = acl.getClientByIdx(i);
|
||||||
|
|
||||||
memcpy(client->out_path, path, client->out_path_len = path_len); // store a copy of path, for sendDirect()
|
// store a copy of path, for sendDirect()
|
||||||
|
client->out_path_len = mesh::Packet::copyPath(client->out_path, path, path_len);
|
||||||
client->last_activity = getRTCClock()->getCurrentTime();
|
client->last_activity = getRTCClock()->getCurrentTime();
|
||||||
} else {
|
} else {
|
||||||
MESH_DEBUG_PRINTLN("onPeerPathRecv: invalid peer idx: %d", i);
|
MESH_DEBUG_PRINTLN("onPeerPathRecv: invalid peer idx: %d", i);
|
||||||
@@ -746,6 +793,47 @@ void MyMesh::onControlDataRecv(mesh::Packet* packet) {
|
|||||||
sendZeroHop(resp, getRetransmitDelay(resp)*4); // apply random delay (widened x4), as multiple nodes can respond to this
|
sendZeroHop(resp, getRetransmitDelay(resp)*4); // apply random delay (widened x4), as multiple nodes can respond to this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (type == CTL_TYPE_NODE_DISCOVER_RESP && packet->payload_len >= 6) {
|
||||||
|
uint8_t node_type = packet->payload[0] & 0x0F;
|
||||||
|
if (node_type != ADV_TYPE_REPEATER) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (packet->payload_len < 6 + PUB_KEY_SIZE) {
|
||||||
|
MESH_DEBUG_PRINTLN("onControlDataRecv: DISCOVER_RESP pubkey too short: %d", (uint32_t)packet->payload_len);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pending_discover_tag == 0 || millisHasNowPassed(pending_discover_until)) {
|
||||||
|
pending_discover_tag = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t tag;
|
||||||
|
memcpy(&tag, &packet->payload[2], 4);
|
||||||
|
if (tag != pending_discover_tag) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh::Identity id(&packet->payload[6]);
|
||||||
|
if (id.matches(self_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
putNeighbour(id, rtc_clock.getCurrentTime(), packet->getSNR());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyMesh::sendNodeDiscoverReq() {
|
||||||
|
uint8_t data[10];
|
||||||
|
data[0] = CTL_TYPE_NODE_DISCOVER_REQ; // prefix_only=0
|
||||||
|
data[1] = (1 << ADV_TYPE_REPEATER);
|
||||||
|
getRNG()->random(&data[2], 4); // tag
|
||||||
|
memcpy(&pending_discover_tag, &data[2], 4);
|
||||||
|
pending_discover_until = futureMillis(60000);
|
||||||
|
uint32_t since = 0;
|
||||||
|
memcpy(&data[6], &since, 4);
|
||||||
|
|
||||||
|
auto pkt = createControlData(data, sizeof(data));
|
||||||
|
if (pkt) {
|
||||||
|
sendZeroHop(pkt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,10 +864,10 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
|
|||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
memset(&_prefs, 0, sizeof(_prefs));
|
memset(&_prefs, 0, sizeof(_prefs));
|
||||||
_prefs.airtime_factor = 1.0;
|
_prefs.airtime_factor = 1.0; // one half
|
||||||
_prefs.rx_delay_base = 0.0f; // turn off by default, was 10.0;
|
_prefs.rx_delay_base = 0.0f; // turn off by default, was 10.0;
|
||||||
_prefs.tx_delay_factor = 0.5f; // was 0.25f
|
_prefs.tx_delay_factor = 0.5f; // was 0.25f
|
||||||
_prefs.direct_tx_delay_factor = 0.2f; // was zero
|
_prefs.direct_tx_delay_factor = 0.3f; // was 0.2
|
||||||
StrHelper::strncpy(_prefs.node_name, ADVERT_NAME, sizeof(_prefs.node_name));
|
StrHelper::strncpy(_prefs.node_name, ADVERT_NAME, sizeof(_prefs.node_name));
|
||||||
_prefs.node_lat = ADVERT_LAT;
|
_prefs.node_lat = ADVERT_LAT;
|
||||||
_prefs.node_lon = ADVERT_LON;
|
_prefs.node_lon = ADVERT_LON;
|
||||||
@@ -810,6 +898,9 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
|
|||||||
_prefs.advert_loc_policy = ADVERT_LOC_PREFS;
|
_prefs.advert_loc_policy = ADVERT_LOC_PREFS;
|
||||||
|
|
||||||
_prefs.adc_multiplier = 0.0f; // 0.0f means use default board multiplier
|
_prefs.adc_multiplier = 0.0f; // 0.0f means use default board multiplier
|
||||||
|
|
||||||
|
pending_discover_tag = 0;
|
||||||
|
pending_discover_until = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyMesh::begin(FILESYSTEM *fs) {
|
void MyMesh::begin(FILESYSTEM *fs) {
|
||||||
@@ -867,7 +958,7 @@ void MyMesh::sendSelfAdvertisement(int delay_millis, bool flood) {
|
|||||||
mesh::Packet *pkt = createSelfAdvert();
|
mesh::Packet *pkt = createSelfAdvert();
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
if (flood) {
|
if (flood) {
|
||||||
sendFlood(pkt, delay_millis);
|
sendFlood(pkt, delay_millis, _prefs.path_hash_mode + 1);
|
||||||
} else {
|
} else {
|
||||||
sendZeroHop(pkt, delay_millis);
|
sendZeroHop(pkt, delay_millis);
|
||||||
}
|
}
|
||||||
@@ -1177,6 +1268,15 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
|
|||||||
} else {
|
} else {
|
||||||
strcpy(reply, "Err - ??");
|
strcpy(reply, "Err - ??");
|
||||||
}
|
}
|
||||||
|
} else if (memcmp(command, "discover.neighbors", 18) == 0) {
|
||||||
|
const char* sub = command + 18;
|
||||||
|
while (*sub == ' ') sub++;
|
||||||
|
if (*sub != 0) {
|
||||||
|
strcpy(reply, "Err - discover.neighbors has no options");
|
||||||
|
} else {
|
||||||
|
sendNodeDiscoverReq();
|
||||||
|
strcpy(reply, "OK - Discover sent");
|
||||||
|
}
|
||||||
} else{
|
} else{
|
||||||
_cli.handleCommand(sender_timestamp, command, reply); // common CLI commands
|
_cli.handleCommand(sender_timestamp, command, reply); // common CLI commands
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,11 +69,11 @@ struct NeighbourInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifndef FIRMWARE_BUILD_DATE
|
#ifndef FIRMWARE_BUILD_DATE
|
||||||
#define FIRMWARE_BUILD_DATE "29 Jan 2026"
|
#define FIRMWARE_BUILD_DATE "15 Feb 2026"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FIRMWARE_VERSION
|
#ifndef FIRMWARE_VERSION
|
||||||
#define FIRMWARE_VERSION "v1.12.0"
|
#define FIRMWARE_VERSION "v1.13.0"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FIRMWARE_ROLE "repeater"
|
#define FIRMWARE_ROLE "repeater"
|
||||||
@@ -92,11 +92,14 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
|||||||
uint8_t reply_data[MAX_PACKET_PAYLOAD];
|
uint8_t reply_data[MAX_PACKET_PAYLOAD];
|
||||||
uint8_t reply_path[MAX_PATH_SIZE];
|
uint8_t reply_path[MAX_PATH_SIZE];
|
||||||
int8_t reply_path_len;
|
int8_t reply_path_len;
|
||||||
|
uint8_t reply_path_hash_size;
|
||||||
TransportKeyStore key_store;
|
TransportKeyStore key_store;
|
||||||
RegionMap region_map, temp_map;
|
RegionMap region_map, temp_map;
|
||||||
RegionEntry* load_stack[8];
|
RegionEntry* load_stack[8];
|
||||||
RegionEntry* recv_pkt_region;
|
RegionEntry* recv_pkt_region;
|
||||||
RateLimiter discover_limiter, anon_limiter;
|
RateLimiter discover_limiter, anon_limiter;
|
||||||
|
uint32_t pending_discover_tag;
|
||||||
|
unsigned long pending_discover_until;
|
||||||
bool region_load_active;
|
bool region_load_active;
|
||||||
unsigned long dirty_contacts_expiry;
|
unsigned long dirty_contacts_expiry;
|
||||||
#if MAX_NEIGHBOURS
|
#if MAX_NEIGHBOURS
|
||||||
@@ -116,6 +119,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void putNeighbour(const mesh::Identity& id, uint32_t timestamp, float snr);
|
void putNeighbour(const mesh::Identity& id, uint32_t timestamp, float snr);
|
||||||
|
void sendNodeDiscoverReq();
|
||||||
uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood);
|
uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood);
|
||||||
uint8_t handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
|
uint8_t handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
|
||||||
uint8_t handleAnonOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
|
uint8_t handleAnonOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
|
||||||
@@ -124,6 +128,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
|||||||
mesh::Packet* createSelfAdvert();
|
mesh::Packet* createSelfAdvert();
|
||||||
|
|
||||||
File openAppend(const char* fname);
|
File openAppend(const char* fname);
|
||||||
|
bool isLooped(const mesh::Packet* packet, const uint8_t max_counters[]);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float getAirtimeBudgetFactor() const override {
|
float getAirtimeBudgetFactor() const override {
|
||||||
|
|||||||
@@ -73,13 +73,15 @@ void MyMesh::pushPostToClient(ClientInfo *client, PostInfo &post) {
|
|||||||
|
|
||||||
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, client->shared_secret, reply_data, len);
|
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, client->shared_secret, reply_data, len);
|
||||||
if (reply) {
|
if (reply) {
|
||||||
if (client->out_path_len < 0) {
|
if (client->out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFlood(reply);
|
unsigned long delay_millis = 0;
|
||||||
|
sendFlood(reply, delay_millis, _prefs.path_hash_mode + 1);
|
||||||
client->extra.room.ack_timeout = futureMillis(PUSH_ACK_TIMEOUT_FLOOD);
|
client->extra.room.ack_timeout = futureMillis(PUSH_ACK_TIMEOUT_FLOOD);
|
||||||
} else {
|
} else {
|
||||||
sendDirect(reply, client->out_path, client->out_path_len);
|
sendDirect(reply, client->out_path, client->out_path_len);
|
||||||
client->extra.room.ack_timeout =
|
|
||||||
futureMillis(PUSH_TIMEOUT_BASE + PUSH_ACK_TIMEOUT_FACTOR * (client->out_path_len + 1));
|
uint8_t path_hash_count = client->out_path_len & 63;
|
||||||
|
client->extra.room.ack_timeout = futureMillis(PUSH_TIMEOUT_BASE + PUSH_ACK_TIMEOUT_FACTOR * (path_hash_count + 1));
|
||||||
}
|
}
|
||||||
_num_post_pushes++; // stats
|
_num_post_pushes++; // stats
|
||||||
} else {
|
} else {
|
||||||
@@ -264,26 +266,27 @@ const char *MyMesh::getLogDateTime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) {
|
uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) {
|
||||||
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.tx_delay_factor);
|
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * _prefs.tx_delay_factor);
|
||||||
return getRNG()->nextInt(0, 5*t + 1);
|
return getRNG()->nextInt(0, 5*t + 1);
|
||||||
}
|
}
|
||||||
uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
|
uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
|
||||||
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
|
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
|
||||||
return getRNG()->nextInt(0, 5*t + 1);
|
return getRNG()->nextInt(0, 5*t + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
|
bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
|
||||||
if (_prefs.disable_fwd) return false;
|
if (_prefs.disable_fwd) return false;
|
||||||
if (packet->isRouteFlood() && packet->path_len >= _prefs.flood_max) return false;
|
if (packet->isRouteFlood() && packet->getPathHashCount() >= _prefs.flood_max) return false;
|
||||||
|
|
||||||
// Limit flood advert paket forwarding using a probabilistic reduction defined by P(h) = 0.308^(hops-1)
|
// Limit flood advert packet forwarding using a probabilistic reduction defined by P(h) = base^(hops-1)
|
||||||
// https://github.com/meshcore-dev/MeshCore/issues/1223
|
// https://github.com/meshcore-dev/MeshCore/issues/1223
|
||||||
double_t roll_dice = (double)rand() / RAND_MAX;
|
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->isRouteFlood()) {
|
||||||
double_t forw_prob = pow(_prefs.flood_advert_base, packet->path_len - 1);
|
double roll_dice = (double)rand() / RAND_MAX;
|
||||||
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->isRouteFlood() && roll_dice > forw_prob)
|
double forw_prob = pow(_prefs.flood_advert_base, packet->path_len - 1);
|
||||||
return false;
|
if (roll_dice > forw_prob)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// all other packets
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,7 +345,7 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (packet->isRouteFlood()) {
|
if (packet->isRouteFlood()) {
|
||||||
client->out_path_len = -1; // need to rediscover out_path
|
client->out_path_len = OUT_PATH_UNKNOWN; // need to rediscover out_path
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t now = getRTCClock()->getCurrentTimeUnique();
|
uint32_t now = getRTCClock()->getCurrentTimeUnique();
|
||||||
@@ -362,14 +365,14 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
|
|||||||
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
||||||
mesh::Packet *path = createPathReturn(sender, client->shared_secret, packet->path, packet->path_len,
|
mesh::Packet *path = createPathReturn(sender, client->shared_secret, packet->path, packet->path_len,
|
||||||
PAYLOAD_TYPE_RESPONSE, reply_data, 13);
|
PAYLOAD_TYPE_RESPONSE, reply_data, 13);
|
||||||
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
|
if (path) sendFlood(path, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
} else {
|
} else {
|
||||||
mesh::Packet *reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, client->shared_secret, reply_data, 13);
|
mesh::Packet *reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, client->shared_secret, reply_data, 13);
|
||||||
if (reply) {
|
if (reply) {
|
||||||
if (client->out_path_len >= 0) { // we have an out_path, so send DIRECT
|
if (client->out_path_len != OUT_PATH_UNKNOWN) { // we have an out_path, so send DIRECT
|
||||||
sendDirect(reply, client->out_path, client->out_path_len, SERVER_RESPONSE_DELAY);
|
sendDirect(reply, client->out_path, client->out_path_len, SERVER_RESPONSE_DELAY);
|
||||||
} else {
|
} else {
|
||||||
sendFlood(reply, SERVER_RESPONSE_DELAY);
|
sendFlood(reply, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -457,9 +460,9 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
|||||||
|
|
||||||
uint32_t delay_millis;
|
uint32_t delay_millis;
|
||||||
if (send_ack) {
|
if (send_ack) {
|
||||||
if (client->out_path_len < 0) {
|
if (client->out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
mesh::Packet *ack = createAck(ack_hash);
|
mesh::Packet *ack = createAck(ack_hash);
|
||||||
if (ack) sendFlood(ack, TXT_ACK_DELAY);
|
if (ack) sendFlood(ack, TXT_ACK_DELAY, packet->getPathHashSize());
|
||||||
delay_millis = TXT_ACK_DELAY + REPLY_DELAY_MILLIS;
|
delay_millis = TXT_ACK_DELAY + REPLY_DELAY_MILLIS;
|
||||||
} else {
|
} else {
|
||||||
uint32_t d = TXT_ACK_DELAY;
|
uint32_t d = TXT_ACK_DELAY;
|
||||||
@@ -491,8 +494,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
|||||||
|
|
||||||
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len);
|
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len);
|
||||||
if (reply) {
|
if (reply) {
|
||||||
if (client->out_path_len < 0) {
|
if (client->out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFlood(reply, delay_millis + SERVER_RESPONSE_DELAY);
|
sendFlood(reply, delay_millis + SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
} else {
|
} else {
|
||||||
sendDirect(reply, client->out_path, client->out_path_len, delay_millis + SERVER_RESPONSE_DELAY);
|
sendDirect(reply, client->out_path, client->out_path_len, delay_millis + SERVER_RESPONSE_DELAY);
|
||||||
}
|
}
|
||||||
@@ -530,7 +533,7 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
|||||||
// if client sends too quickly, evict()
|
// if client sends too quickly, evict()
|
||||||
|
|
||||||
// RULE: only send keep_alive response DIRECT!
|
// RULE: only send keep_alive response DIRECT!
|
||||||
if (client->out_path_len >= 0) {
|
if (client->out_path_len != OUT_PATH_UNKNOWN) {
|
||||||
uint32_t ack_hash; // calc ACK to prove to sender that we got request
|
uint32_t ack_hash; // calc ACK to prove to sender that we got request
|
||||||
mesh::Utils::sha256((uint8_t *)&ack_hash, 4, data, 9, client->id.pub_key, PUB_KEY_SIZE);
|
mesh::Utils::sha256((uint8_t *)&ack_hash, 4, data, 9, client->id.pub_key, PUB_KEY_SIZE);
|
||||||
|
|
||||||
@@ -547,14 +550,14 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
|||||||
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
||||||
mesh::Packet *path = createPathReturn(client->id, secret, packet->path, packet->path_len,
|
mesh::Packet *path = createPathReturn(client->id, secret, packet->path, packet->path_len,
|
||||||
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
|
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
|
||||||
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
|
if (path) sendFlood(path, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
} else {
|
} else {
|
||||||
mesh::Packet *reply = createDatagram(PAYLOAD_TYPE_RESPONSE, client->id, secret, reply_data, reply_len);
|
mesh::Packet *reply = createDatagram(PAYLOAD_TYPE_RESPONSE, client->id, secret, reply_data, reply_len);
|
||||||
if (reply) {
|
if (reply) {
|
||||||
if (client->out_path_len >= 0) { // we have an out_path, so send DIRECT
|
if (client->out_path_len != OUT_PATH_UNKNOWN) { // we have an out_path, so send DIRECT
|
||||||
sendDirect(reply, client->out_path, client->out_path_len, SERVER_RESPONSE_DELAY);
|
sendDirect(reply, client->out_path, client->out_path_len, SERVER_RESPONSE_DELAY);
|
||||||
} else {
|
} else {
|
||||||
sendFlood(reply, SERVER_RESPONSE_DELAY);
|
sendFlood(reply, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -572,7 +575,7 @@ bool MyMesh::onPeerPathRecv(mesh::Packet *packet, int sender_idx, const uint8_t
|
|||||||
if (i >= 0 && i < acl.getNumClients()) { // get from our known_clients table (sender SHOULD already be known in this context)
|
if (i >= 0 && i < acl.getNumClients()) { // get from our known_clients table (sender SHOULD already be known in this context)
|
||||||
MESH_DEBUG_PRINTLN("PATH to client, path_len=%d", (uint32_t)path_len);
|
MESH_DEBUG_PRINTLN("PATH to client, path_len=%d", (uint32_t)path_len);
|
||||||
auto client = acl.getClientByIdx(i);
|
auto client = acl.getClientByIdx(i);
|
||||||
memcpy(client->out_path, path, client->out_path_len = path_len); // store a copy of path, for sendDirect()
|
client->out_path_len = mesh::Packet::copyPath(client->out_path, path, path_len); // store a copy of path, for sendDirect()
|
||||||
client->last_activity = getRTCClock()->getCurrentTime();
|
client->last_activity = getRTCClock()->getCurrentTime();
|
||||||
} else {
|
} else {
|
||||||
MESH_DEBUG_PRINTLN("onPeerPathRecv: invalid peer idx: %d", i);
|
MESH_DEBUG_PRINTLN("onPeerPathRecv: invalid peer idx: %d", i);
|
||||||
@@ -606,7 +609,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
|
|||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
memset(&_prefs, 0, sizeof(_prefs));
|
memset(&_prefs, 0, sizeof(_prefs));
|
||||||
_prefs.airtime_factor = 1.0;
|
_prefs.airtime_factor = 1.0; // one half
|
||||||
_prefs.rx_delay_base = 0.0f; // off by default, was 10.0
|
_prefs.rx_delay_base = 0.0f; // off by default, was 10.0
|
||||||
_prefs.tx_delay_factor = 0.5f; // was 0.25f;
|
_prefs.tx_delay_factor = 0.5f; // was 0.25f;
|
||||||
_prefs.direct_tx_delay_factor = 0.2f; // was zero
|
_prefs.direct_tx_delay_factor = 0.2f; // was zero
|
||||||
@@ -689,7 +692,7 @@ void MyMesh::sendSelfAdvertisement(int delay_millis, bool flood) {
|
|||||||
mesh::Packet *pkt = createSelfAdvert();
|
mesh::Packet *pkt = createSelfAdvert();
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
if (flood) {
|
if (flood) {
|
||||||
sendFlood(pkt, delay_millis);
|
sendFlood(pkt, delay_millis, _prefs.path_hash_mode + 1);
|
||||||
} else {
|
} else {
|
||||||
sendZeroHop(pkt, delay_millis);
|
sendZeroHop(pkt, delay_millis);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,11 @@
|
|||||||
/* ------------------------------ Config -------------------------------- */
|
/* ------------------------------ Config -------------------------------- */
|
||||||
|
|
||||||
#ifndef FIRMWARE_BUILD_DATE
|
#ifndef FIRMWARE_BUILD_DATE
|
||||||
#define FIRMWARE_BUILD_DATE "29 Jan 2026"
|
#define FIRMWARE_BUILD_DATE "15 Feb 2026"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FIRMWARE_VERSION
|
#ifndef FIRMWARE_VERSION
|
||||||
#define FIRMWARE_VERSION "v1.12.0"
|
#define FIRMWARE_VERSION "v1.13.0"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LORA_FREQ
|
#ifndef LORA_FREQ
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onContactPathUpdated(const ContactInfo& contact) override {
|
void onContactPathUpdated(const ContactInfo& contact) override {
|
||||||
Serial.printf("PATH to: %s, path_len=%d\n", contact.name, (int32_t) contact.out_path_len);
|
Serial.printf("PATH to: %s, path_len=%d\n", contact.name, (uint32_t) contact.out_path_len);
|
||||||
saveContacts();
|
saveContacts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,8 +266,9 @@ protected:
|
|||||||
return SEND_TIMEOUT_BASE_MILLIS + (FLOOD_SEND_TIMEOUT_FACTOR * pkt_airtime_millis);
|
return SEND_TIMEOUT_BASE_MILLIS + (FLOOD_SEND_TIMEOUT_FACTOR * pkt_airtime_millis);
|
||||||
}
|
}
|
||||||
uint32_t calcDirectTimeoutMillisFor(uint32_t pkt_airtime_millis, uint8_t path_len) const override {
|
uint32_t calcDirectTimeoutMillisFor(uint32_t pkt_airtime_millis, uint8_t path_len) const override {
|
||||||
|
uint8_t path_hash_count = path_len & 63;
|
||||||
return SEND_TIMEOUT_BASE_MILLIS +
|
return SEND_TIMEOUT_BASE_MILLIS +
|
||||||
( (pkt_airtime_millis*DIRECT_SEND_PERHOP_FACTOR + DIRECT_SEND_PERHOP_EXTRA_MILLIS) * (path_len + 1));
|
( (pkt_airtime_millis*DIRECT_SEND_PERHOP_FACTOR + DIRECT_SEND_PERHOP_EXTRA_MILLIS) * (path_hash_count + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void onSendTimeout() override {
|
void onSendTimeout() override {
|
||||||
@@ -280,7 +281,7 @@ public:
|
|||||||
{
|
{
|
||||||
// defaults
|
// defaults
|
||||||
memset(&_prefs, 0, sizeof(_prefs));
|
memset(&_prefs, 0, sizeof(_prefs));
|
||||||
_prefs.airtime_factor = 1.0;
|
_prefs.airtime_factor = 2.0; // one third
|
||||||
strcpy(_prefs.node_name, "NONAME");
|
strcpy(_prefs.node_name, "NONAME");
|
||||||
_prefs.freq = LORA_FREQ;
|
_prefs.freq = LORA_FREQ;
|
||||||
_prefs.tx_power_dbm = LORA_TX_POWER;
|
_prefs.tx_power_dbm = LORA_TX_POWER;
|
||||||
|
|||||||
@@ -258,10 +258,11 @@ void SensorMesh::sendAlert(const ClientInfo* c, Trigger* t) {
|
|||||||
|
|
||||||
auto pkt = createDatagram(PAYLOAD_TYPE_TXT_MSG, c->id, c->shared_secret, data, 5 + text_len);
|
auto pkt = createDatagram(PAYLOAD_TYPE_TXT_MSG, c->id, c->shared_secret, data, 5 + text_len);
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
if (c->out_path_len >= 0) { // we have an out_path, so send DIRECT
|
if (c->out_path_len != OUT_PATH_UNKNOWN) { // we have an out_path, so send DIRECT
|
||||||
sendDirect(pkt, c->out_path, c->out_path_len);
|
sendDirect(pkt, c->out_path, c->out_path_len);
|
||||||
} else {
|
} else {
|
||||||
sendFlood(pkt);
|
unsigned long delay_millis = 0;
|
||||||
|
sendFlood(pkt, delay_millis, _prefs.path_hash_mode + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t->send_expiry = futureMillis(ALERT_ACK_EXPIRY_MILLIS);
|
t->send_expiry = futureMillis(ALERT_ACK_EXPIRY_MILLIS);
|
||||||
@@ -302,7 +303,7 @@ float SensorMesh::getAirtimeBudgetFactor() const {
|
|||||||
|
|
||||||
bool SensorMesh::allowPacketForward(const mesh::Packet* packet) {
|
bool SensorMesh::allowPacketForward(const mesh::Packet* packet) {
|
||||||
if (_prefs.disable_fwd) return false;
|
if (_prefs.disable_fwd) return false;
|
||||||
if (packet->isRouteFlood() && packet->path_len >= _prefs.flood_max) return false;
|
if (packet->isRouteFlood() && packet->getPathHashCount() >= _prefs.flood_max) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,11 +313,11 @@ int SensorMesh::calcRxDelay(float score, uint32_t air_time) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SensorMesh::getRetransmitDelay(const mesh::Packet* packet) {
|
uint32_t SensorMesh::getRetransmitDelay(const mesh::Packet* packet) {
|
||||||
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.tx_delay_factor);
|
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * _prefs.tx_delay_factor);
|
||||||
return getRNG()->nextInt(0, 6)*t;
|
return getRNG()->nextInt(0, 6)*t;
|
||||||
}
|
}
|
||||||
uint32_t SensorMesh::getDirectRetransmitDelay(const mesh::Packet* packet) {
|
uint32_t SensorMesh::getDirectRetransmitDelay(const mesh::Packet* packet) {
|
||||||
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
|
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
|
||||||
return getRNG()->nextInt(0, 6)*t;
|
return getRNG()->nextInt(0, 6)*t;
|
||||||
}
|
}
|
||||||
int SensorMesh::getInterferenceThreshold() const {
|
int SensorMesh::getInterferenceThreshold() const {
|
||||||
@@ -360,7 +361,7 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_flood) {
|
if (is_flood) {
|
||||||
client->out_path_len = -1; // need to rediscover out_path
|
client->out_path_len = OUT_PATH_UNKNOWN; // need to rediscover out_path
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t now = getRTCClock()->getCurrentTimeUnique();
|
uint32_t now = getRTCClock()->getCurrentTimeUnique();
|
||||||
@@ -468,10 +469,10 @@ void SensorMesh::onAnonDataRecv(mesh::Packet* packet, const uint8_t* secret, con
|
|||||||
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
||||||
mesh::Packet* path = createPathReturn(sender, secret, packet->path, packet->path_len,
|
mesh::Packet* path = createPathReturn(sender, secret, packet->path, packet->path_len,
|
||||||
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
|
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
|
||||||
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
|
if (path) sendFlood(path, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
} else {
|
} else {
|
||||||
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len);
|
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len);
|
||||||
if (reply) sendFlood(reply, SERVER_RESPONSE_DELAY);
|
if (reply) sendFlood(reply, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -496,10 +497,10 @@ void SensorMesh::getPeerSharedSecret(uint8_t* dest_secret, int peer_idx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorMesh::sendAckTo(const ClientInfo& dest, uint32_t ack_hash) {
|
void SensorMesh::sendAckTo(const ClientInfo& dest, uint32_t ack_hash, uint8_t path_hash_size) {
|
||||||
if (dest.out_path_len < 0) {
|
if (dest.out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
mesh::Packet* ack = createAck(ack_hash);
|
mesh::Packet* ack = createAck(ack_hash);
|
||||||
if (ack) sendFlood(ack, TXT_ACK_DELAY);
|
if (ack) sendFlood(ack, TXT_ACK_DELAY, path_hash_size);
|
||||||
} else {
|
} else {
|
||||||
uint32_t d = TXT_ACK_DELAY;
|
uint32_t d = TXT_ACK_DELAY;
|
||||||
if (getExtraAckTransmitCount() > 0) {
|
if (getExtraAckTransmitCount() > 0) {
|
||||||
@@ -537,14 +538,14 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
|
|||||||
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
|
||||||
mesh::Packet* path = createPathReturn(from->id, secret, packet->path, packet->path_len,
|
mesh::Packet* path = createPathReturn(from->id, secret, packet->path, packet->path_len,
|
||||||
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
|
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
|
||||||
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
|
if (path) sendFlood(path, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
} else {
|
} else {
|
||||||
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, from->id, secret, reply_data, reply_len);
|
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, from->id, secret, reply_data, reply_len);
|
||||||
if (reply) {
|
if (reply) {
|
||||||
if (from->out_path_len >= 0) { // we have an out_path, so send DIRECT
|
if (from->out_path_len != OUT_PATH_UNKNOWN) { // we have an out_path, so send DIRECT
|
||||||
sendDirect(reply, from->out_path, from->out_path_len, SERVER_RESPONSE_DELAY);
|
sendDirect(reply, from->out_path, from->out_path_len, SERVER_RESPONSE_DELAY);
|
||||||
} else {
|
} else {
|
||||||
sendFlood(reply, SERVER_RESPONSE_DELAY);
|
sendFlood(reply, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -567,9 +568,9 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
|
|||||||
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the ACK
|
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the ACK
|
||||||
mesh::Packet* path = createPathReturn(from->id, secret, packet->path, packet->path_len,
|
mesh::Packet* path = createPathReturn(from->id, secret, packet->path, packet->path_len,
|
||||||
PAYLOAD_TYPE_ACK, (uint8_t *) &ack_hash, 4);
|
PAYLOAD_TYPE_ACK, (uint8_t *) &ack_hash, 4);
|
||||||
if (path) sendFlood(path, TXT_ACK_DELAY);
|
if (path) sendFlood(path, TXT_ACK_DELAY, packet->getPathHashSize());
|
||||||
} else {
|
} else {
|
||||||
sendAckTo(*from, ack_hash);
|
sendAckTo(*from, ack_hash, packet->getPathHashSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (flags == TXT_TYPE_CLI_DATA) {
|
} else if (flags == TXT_TYPE_CLI_DATA) {
|
||||||
@@ -596,8 +597,8 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
|
|||||||
|
|
||||||
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, from->id, secret, temp, 5 + text_len);
|
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, from->id, secret, temp, 5 + text_len);
|
||||||
if (reply) {
|
if (reply) {
|
||||||
if (from->out_path_len < 0) {
|
if (from->out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFlood(reply, CLI_REPLY_DELAY_MILLIS);
|
sendFlood(reply, CLI_REPLY_DELAY_MILLIS, packet->getPathHashSize());
|
||||||
} else {
|
} else {
|
||||||
sendDirect(reply, from->out_path, from->out_path_len, CLI_REPLY_DELAY_MILLIS);
|
sendDirect(reply, from->out_path, from->out_path_len, CLI_REPLY_DELAY_MILLIS);
|
||||||
}
|
}
|
||||||
@@ -666,7 +667,7 @@ bool SensorMesh::onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint
|
|||||||
MESH_DEBUG_PRINTLN("PATH to contact, path_len=%d", (uint32_t) path_len);
|
MESH_DEBUG_PRINTLN("PATH to contact, path_len=%d", (uint32_t) path_len);
|
||||||
// NOTE: for this impl, we just replace the current 'out_path' regardless, whenever sender sends us a new out_path.
|
// NOTE: for this impl, we just replace the current 'out_path' regardless, whenever sender sends us a new out_path.
|
||||||
// FUTURE: could store multiple out_paths per contact, and try to find which is the 'best'(?)
|
// FUTURE: could store multiple out_paths per contact, and try to find which is the 'best'(?)
|
||||||
memcpy(from->out_path, path, from->out_path_len = path_len); // store a copy of path, for sendDirect()
|
from->out_path_len = mesh::Packet::copyPath(from->out_path, path, path_len); // store a copy of path, for sendDirect()
|
||||||
from->last_activity = getRTCClock()->getCurrentTime();
|
from->last_activity = getRTCClock()->getCurrentTime();
|
||||||
|
|
||||||
// REVISIT: maybe make ALL out_paths non-persisted to minimise flash writes??
|
// REVISIT: maybe make ALL out_paths non-persisted to minimise flash writes??
|
||||||
@@ -705,7 +706,7 @@ SensorMesh::SensorMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::Millise
|
|||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
memset(&_prefs, 0, sizeof(_prefs));
|
memset(&_prefs, 0, sizeof(_prefs));
|
||||||
_prefs.airtime_factor = 1.0;
|
_prefs.airtime_factor = 1.0; // one half
|
||||||
_prefs.rx_delay_base = 0.0f; // turn off by default, was 10.0;
|
_prefs.rx_delay_base = 0.0f; // turn off by default, was 10.0;
|
||||||
_prefs.tx_delay_factor = 0.5f; // was 0.25f
|
_prefs.tx_delay_factor = 0.5f; // was 0.25f
|
||||||
_prefs.direct_tx_delay_factor = 0.2f; // was zero
|
_prefs.direct_tx_delay_factor = 0.2f; // was zero
|
||||||
@@ -791,7 +792,7 @@ void SensorMesh::sendSelfAdvertisement(int delay_millis, bool flood) {
|
|||||||
mesh::Packet* pkt = createSelfAdvert();
|
mesh::Packet* pkt = createSelfAdvert();
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
if (flood) {
|
if (flood) {
|
||||||
sendFlood(pkt, delay_millis);
|
sendFlood(pkt, delay_millis, _prefs.path_hash_mode + 1);
|
||||||
} else {
|
} else {
|
||||||
sendZeroHop(pkt, delay_millis);
|
sendZeroHop(pkt, delay_millis);
|
||||||
}
|
}
|
||||||
@@ -868,7 +869,8 @@ void SensorMesh::loop() {
|
|||||||
|
|
||||||
if (next_flood_advert && millisHasNowPassed(next_flood_advert)) {
|
if (next_flood_advert && millisHasNowPassed(next_flood_advert)) {
|
||||||
mesh::Packet* pkt = createSelfAdvert();
|
mesh::Packet* pkt = createSelfAdvert();
|
||||||
if (pkt) sendFlood(pkt);
|
unsigned long delay_millis = 0;
|
||||||
|
if (pkt) sendFlood(pkt, delay_millis, _prefs.path_hash_mode + 1);
|
||||||
|
|
||||||
updateFloodAdvertTimer(); // schedule next flood advert
|
updateFloodAdvertTimer(); // schedule next flood advert
|
||||||
updateAdvertTimer(); // also schedule local advert (so they don't overlap)
|
updateAdvertTimer(); // also schedule local advert (so they don't overlap)
|
||||||
|
|||||||
@@ -33,11 +33,11 @@
|
|||||||
#define PERM_RECV_ALERTS_HI (1 << 7) // high priority alerts
|
#define PERM_RECV_ALERTS_HI (1 << 7) // high priority alerts
|
||||||
|
|
||||||
#ifndef FIRMWARE_BUILD_DATE
|
#ifndef FIRMWARE_BUILD_DATE
|
||||||
#define FIRMWARE_BUILD_DATE "29 Jan 2026"
|
#define FIRMWARE_BUILD_DATE "15 Feb 2026"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FIRMWARE_VERSION
|
#ifndef FIRMWARE_VERSION
|
||||||
#define FIRMWARE_VERSION "v1.12.0"
|
#define FIRMWARE_VERSION "v1.13.0"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FIRMWARE_ROLE "sensor"
|
#define FIRMWARE_ROLE "sensor"
|
||||||
@@ -128,7 +128,7 @@ protected:
|
|||||||
void onControlDataRecv(mesh::Packet* packet) override;
|
void onControlDataRecv(mesh::Packet* packet) override;
|
||||||
void onAckRecv(mesh::Packet* packet, uint32_t ack_crc) override;
|
void onAckRecv(mesh::Packet* packet, uint32_t ack_crc) override;
|
||||||
virtual bool handleIncomingMsg(ClientInfo& from, uint32_t timestamp, uint8_t* data, uint8_t flags, size_t len);
|
virtual bool handleIncomingMsg(ClientInfo& from, uint32_t timestamp, uint8_t* data, uint8_t flags, size_t len);
|
||||||
void sendAckTo(const ClientInfo& dest, uint32_t ack_hash);
|
void sendAckTo(const ClientInfo& dest, uint32_t ack_hash, uint8_t path_hash_size=1);
|
||||||
private:
|
private:
|
||||||
FILESYSTEM* _fs;
|
FILESYSTEM* _fs;
|
||||||
unsigned long next_local_advert, next_flood_advert;
|
unsigned long next_local_advert, next_flood_advert;
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
git branch -D pr-1297
|
|
||||||
git branch -D pr-1338
|
|
||||||
|
|
||||||
# fetch PRs
|
|
||||||
git fetch upstream pull/1338/head:pr-1338
|
|
||||||
git fetch upstream pull/1297/head:pr-1297
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
git merge pr-1338 --no-edit -m "Integration of upstrem PR #1338"
|
|
||||||
git merge pr-1297 --no-edit -m "Integration of upstrem PR #1297"
|
|
||||||
|
|
||||||
git merge pio-ini-adjustments -m "platformio.ini: Adjust defaults for LoRa frequncies and advert interval limits"
|
|
||||||
|
|
||||||
|
|
||||||
@@ -24,9 +24,9 @@ lib_deps =
|
|||||||
melopero/Melopero RV3028 @ ^1.1.0
|
melopero/Melopero RV3028 @ ^1.1.0
|
||||||
electroniccats/CayenneLPP @ 1.6.1
|
electroniccats/CayenneLPP @ 1.6.1
|
||||||
build_flags = -w -DNDEBUG -DRADIOLIB_STATIC_ONLY=1 -DRADIOLIB_GODMODE=1
|
build_flags = -w -DNDEBUG -DRADIOLIB_STATIC_ONLY=1 -DRADIOLIB_GODMODE=1
|
||||||
-D LORA_FREQ=869.525
|
-D LORA_FREQ=869.618
|
||||||
-D LORA_BW=250
|
-D LORA_BW=62.5
|
||||||
-D LORA_SF=11
|
-D LORA_SF=8
|
||||||
-D ENABLE_ADVERT_ON_BOOT=1
|
-D ENABLE_ADVERT_ON_BOOT=1
|
||||||
-D ENABLE_PRIVATE_KEY_IMPORT=1 ; NOTE: comment these out for more secure firmware
|
-D ENABLE_PRIVATE_KEY_IMPORT=1 ; NOTE: comment these out for more secure firmware
|
||||||
-D ENABLE_PRIVATE_KEY_EXPORT=1
|
-D ENABLE_PRIVATE_KEY_EXPORT=1
|
||||||
@@ -59,6 +59,7 @@ platform = platformio/espressif32@6.11.0
|
|||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
extra_scripts = merge-bin.py
|
extra_scripts = merge-bin.py
|
||||||
build_flags = ${arduino_base.build_flags}
|
build_flags = ${arduino_base.build_flags}
|
||||||
|
-D ESP32_PLATFORM
|
||||||
; -D ESP32_CPU_FREQ=80 ; change it to your need
|
; -D ESP32_CPU_FREQ=80 ; change it to your need
|
||||||
build_src_filter = ${arduino_base.build_src_filter}
|
build_src_filter = ${arduino_base.build_src_filter}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,7 @@
|
|||||||
|
|
||||||
namespace mesh {
|
namespace mesh {
|
||||||
|
|
||||||
#define MAX_RX_DELAY_MILLIS 32000 // 32 seconds
|
#define MAX_RX_DELAY_MILLIS 32000 // 32 seconds
|
||||||
#define MIN_TX_BUDGET_RESERVE_MS 100 // min budget (ms) required before allowing next TX
|
|
||||||
#define MIN_TX_BUDGET_AIRTIME_DIV 2 // require at least 1/N of estimated airtime as budget before TX
|
|
||||||
|
|
||||||
#ifndef NOISE_FLOOR_CALIB_INTERVAL
|
#ifndef NOISE_FLOOR_CALIB_INTERVAL
|
||||||
#define NOISE_FLOOR_CALIB_INTERVAL 2000 // 2 seconds
|
#define NOISE_FLOOR_CALIB_INTERVAL 2000 // 2 seconds
|
||||||
@@ -22,34 +20,12 @@ void Dispatcher::begin() {
|
|||||||
_err_flags = 0;
|
_err_flags = 0;
|
||||||
radio_nonrx_start = _ms->getMillis();
|
radio_nonrx_start = _ms->getMillis();
|
||||||
|
|
||||||
duty_cycle_window_ms = getDutyCycleWindowMs();
|
|
||||||
float duty_cycle = 1.0f / (1.0f + getAirtimeBudgetFactor());
|
|
||||||
tx_budget_ms = (unsigned long)(duty_cycle_window_ms * duty_cycle);
|
|
||||||
last_budget_update = _ms->getMillis();
|
|
||||||
|
|
||||||
_radio->begin();
|
_radio->begin();
|
||||||
prev_isrecv_mode = _radio->isInRecvMode();
|
prev_isrecv_mode = _radio->isInRecvMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
float Dispatcher::getAirtimeBudgetFactor() const {
|
float Dispatcher::getAirtimeBudgetFactor() const {
|
||||||
return 1.0;
|
return 2.0; // default, 33.3% (1/3rd)
|
||||||
}
|
|
||||||
|
|
||||||
void Dispatcher::updateTxBudget() {
|
|
||||||
unsigned long now = _ms->getMillis();
|
|
||||||
unsigned long elapsed = now - last_budget_update;
|
|
||||||
|
|
||||||
float duty_cycle = 1.0f / (1.0f + getAirtimeBudgetFactor());
|
|
||||||
unsigned long max_budget = (unsigned long)(getDutyCycleWindowMs() * duty_cycle);
|
|
||||||
unsigned long refill = (unsigned long)(elapsed * duty_cycle);
|
|
||||||
|
|
||||||
if (refill > 0) {
|
|
||||||
tx_budget_ms += refill;
|
|
||||||
if (tx_budget_ms > max_budget) {
|
|
||||||
tx_budget_ms = max_budget;
|
|
||||||
}
|
|
||||||
last_budget_update = now;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Dispatcher::calcRxDelay(float score, uint32_t air_time) const {
|
int Dispatcher::calcRxDelay(float score, uint32_t air_time) const {
|
||||||
@@ -85,27 +61,14 @@ void Dispatcher::loop() {
|
|||||||
if (outbound) { // waiting for outbound send to be completed
|
if (outbound) { // waiting for outbound send to be completed
|
||||||
if (_radio->isSendComplete()) {
|
if (_radio->isSendComplete()) {
|
||||||
long t = _ms->getMillis() - outbound_start;
|
long t = _ms->getMillis() - outbound_start;
|
||||||
total_air_time += t;
|
total_air_time += t; // keep track of how much air time we are using
|
||||||
//Serial.print(" airtime="); Serial.println(t);
|
//Serial.print(" airtime="); Serial.println(t);
|
||||||
|
|
||||||
updateTxBudget();
|
// will need radio silence up to next_tx_time
|
||||||
|
next_tx_time = futureMillis(t * getAirtimeBudgetFactor());
|
||||||
if (t > tx_budget_ms) {
|
|
||||||
tx_budget_ms = 0;
|
|
||||||
} else {
|
|
||||||
tx_budget_ms -= t;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tx_budget_ms < MIN_TX_BUDGET_RESERVE_MS) {
|
|
||||||
float duty_cycle = 1.0f / (1.0f + getAirtimeBudgetFactor());
|
|
||||||
unsigned long needed = MIN_TX_BUDGET_RESERVE_MS - tx_budget_ms;
|
|
||||||
next_tx_time = futureMillis((unsigned long)(needed / duty_cycle));
|
|
||||||
} else {
|
|
||||||
next_tx_time = _ms->getMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
_radio->onSendFinished();
|
_radio->onSendFinished();
|
||||||
logTx(outbound, 2 + outbound->path_len + outbound->payload_len);
|
logTx(outbound, 2 + outbound->getPathByteLen() + outbound->payload_len);
|
||||||
if (outbound->isRouteFlood()) {
|
if (outbound->isRouteFlood()) {
|
||||||
n_sent_flood++;
|
n_sent_flood++;
|
||||||
} else {
|
} else {
|
||||||
@@ -117,7 +80,7 @@ void Dispatcher::loop() {
|
|||||||
MESH_DEBUG_PRINTLN("%s Dispatcher::loop(): WARNING: outbound packed send timed out!", getLogDateTime());
|
MESH_DEBUG_PRINTLN("%s Dispatcher::loop(): WARNING: outbound packed send timed out!", getLogDateTime());
|
||||||
|
|
||||||
_radio->onSendFinished();
|
_radio->onSendFinished();
|
||||||
logTxFail(outbound, 2 + outbound->path_len + outbound->payload_len);
|
logTxFail(outbound, 2 + outbound->getPathByteLen() + outbound->payload_len);
|
||||||
|
|
||||||
releasePacket(outbound); // return to pool
|
releasePacket(outbound); // return to pool
|
||||||
outbound = NULL;
|
outbound = NULL;
|
||||||
@@ -145,6 +108,48 @@ void Dispatcher::loop() {
|
|||||||
checkSend();
|
checkSend();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Dispatcher::tryParsePacket(Packet* pkt, const uint8_t* raw, int len) {
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
pkt->header = raw[i++];
|
||||||
|
if (pkt->getPayloadVer() > PAYLOAD_VER_1) {
|
||||||
|
MESH_DEBUG_PRINTLN("%s Dispatcher::checkRecv(): unsupported packet version", getLogDateTime());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pkt->hasTransportCodes()) {
|
||||||
|
memcpy(&pkt->transport_codes[0], &raw[i], 2); i += 2;
|
||||||
|
memcpy(&pkt->transport_codes[1], &raw[i], 2); i += 2;
|
||||||
|
} else {
|
||||||
|
pkt->transport_codes[0] = pkt->transport_codes[1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pkt->path_len = raw[i++];
|
||||||
|
uint8_t path_mode = pkt->path_len >> 6; // upper 2 bits (legacy firmware: 00)
|
||||||
|
if (path_mode == 3) { // Reserved for future
|
||||||
|
MESH_DEBUG_PRINTLN("%s Dispatcher::checkRecv(): unsupported path mode: 3", getLogDateTime());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t path_byte_len = (pkt->path_len & 63) * pkt->getPathHashSize();
|
||||||
|
if (path_byte_len > MAX_PATH_SIZE || i + path_byte_len > len) {
|
||||||
|
MESH_DEBUG_PRINTLN("%s Dispatcher::checkRecv(): partial or corrupt packet received, len=%d", getLogDateTime(), len);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(pkt->path, &raw[i], path_byte_len); i += path_byte_len;
|
||||||
|
|
||||||
|
pkt->payload_len = len - i; // payload is remainder
|
||||||
|
if (pkt->payload_len > sizeof(pkt->payload)) {
|
||||||
|
MESH_DEBUG_PRINTLN("%s Dispatcher::checkRecv(): packet payload too big, payload_len=%d", getLogDateTime(), (uint32_t)pkt->payload_len);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(pkt->payload, &raw[i], pkt->payload_len);
|
||||||
|
|
||||||
|
return true; // success
|
||||||
|
}
|
||||||
|
|
||||||
void Dispatcher::checkRecv() {
|
void Dispatcher::checkRecv() {
|
||||||
Packet* pkt;
|
Packet* pkt;
|
||||||
float score;
|
float score;
|
||||||
@@ -159,45 +164,14 @@ void Dispatcher::checkRecv() {
|
|||||||
if (pkt == NULL) {
|
if (pkt == NULL) {
|
||||||
MESH_DEBUG_PRINTLN("%s Dispatcher::checkRecv(): WARNING: received data, no unused packets available!", getLogDateTime());
|
MESH_DEBUG_PRINTLN("%s Dispatcher::checkRecv(): WARNING: received data, no unused packets available!", getLogDateTime());
|
||||||
} else {
|
} else {
|
||||||
int i = 0;
|
if (tryParsePacket(pkt, raw, len)) {
|
||||||
#ifdef NODE_ID
|
pkt->_snr = _radio->getLastSNR() * 4.0f;
|
||||||
uint8_t sender_id = raw[i++];
|
score = _radio->packetScore(_radio->getLastSNR(), len);
|
||||||
if (sender_id == NODE_ID - 1 || sender_id == NODE_ID + 1) { // simulate that NODE_ID can only hear NODE_ID-1 or NODE_ID+1, eg. 3 can't hear 1
|
air_time = _radio->getEstAirtimeFor(len);
|
||||||
|
rx_air_time += air_time;
|
||||||
} else {
|
} else {
|
||||||
_mgr->free(pkt); // put back into pool
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pkt->header = raw[i++];
|
|
||||||
if (pkt->hasTransportCodes()) {
|
|
||||||
memcpy(&pkt->transport_codes[0], &raw[i], 2); i += 2;
|
|
||||||
memcpy(&pkt->transport_codes[1], &raw[i], 2); i += 2;
|
|
||||||
} else {
|
|
||||||
pkt->transport_codes[0] = pkt->transport_codes[1] = 0;
|
|
||||||
}
|
|
||||||
pkt->path_len = raw[i++];
|
|
||||||
|
|
||||||
if (pkt->path_len > MAX_PATH_SIZE || i + pkt->path_len > len) {
|
|
||||||
MESH_DEBUG_PRINTLN("%s Dispatcher::checkRecv(): partial or corrupt packet received, len=%d", getLogDateTime(), len);
|
|
||||||
_mgr->free(pkt); // put back into pool
|
_mgr->free(pkt); // put back into pool
|
||||||
pkt = NULL;
|
pkt = NULL;
|
||||||
} else {
|
|
||||||
memcpy(pkt->path, &raw[i], pkt->path_len); i += pkt->path_len;
|
|
||||||
|
|
||||||
pkt->payload_len = len - i; // payload is remainder
|
|
||||||
if (pkt->payload_len > sizeof(pkt->payload)) {
|
|
||||||
MESH_DEBUG_PRINTLN("%s Dispatcher::checkRecv(): packet payload too big, payload_len=%d", getLogDateTime(), (uint32_t)pkt->payload_len);
|
|
||||||
_mgr->free(pkt); // put back into pool
|
|
||||||
pkt = NULL;
|
|
||||||
} else {
|
|
||||||
memcpy(pkt->payload, &raw[i], pkt->payload_len);
|
|
||||||
|
|
||||||
pkt->_snr = _radio->getLastSNR() * 4.0f;
|
|
||||||
score = _radio->packetScore(_radio->getLastSNR(), len);
|
|
||||||
air_time = _radio->getEstAirtimeFor(len);
|
|
||||||
rx_air_time += air_time;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -261,20 +235,9 @@ void Dispatcher::processRecvPacket(Packet* pkt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Dispatcher::checkSend() {
|
void Dispatcher::checkSend() {
|
||||||
if (_mgr->getOutboundCount(_ms->getMillis()) == 0) return;
|
if (_mgr->getOutboundCount(_ms->getMillis()) == 0) return; // nothing waiting to send
|
||||||
|
if (!millisHasNowPassed(next_tx_time)) return; // still in 'radio silence' phase (from airtime budget setting)
|
||||||
updateTxBudget();
|
if (_radio->isReceiving()) { // LBT - check if radio is currently mid-receive, or if channel activity
|
||||||
|
|
||||||
uint32_t est_airtime = _radio->getEstAirtimeFor(MAX_TRANS_UNIT);
|
|
||||||
if (tx_budget_ms < est_airtime / MIN_TX_BUDGET_AIRTIME_DIV) {
|
|
||||||
float duty_cycle = 1.0f / (1.0f + getAirtimeBudgetFactor());
|
|
||||||
unsigned long needed = est_airtime / MIN_TX_BUDGET_AIRTIME_DIV - tx_budget_ms;
|
|
||||||
next_tx_time = futureMillis((unsigned long)(needed / duty_cycle));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!millisHasNowPassed(next_tx_time)) return;
|
|
||||||
if (_radio->isReceiving()) {
|
|
||||||
if (cad_busy_start == 0) {
|
if (cad_busy_start == 0) {
|
||||||
cad_busy_start = _ms->getMillis(); // record when CAD busy state started
|
cad_busy_start = _ms->getMillis(); // record when CAD busy state started
|
||||||
}
|
}
|
||||||
@@ -297,16 +260,13 @@ void Dispatcher::checkSend() {
|
|||||||
int len = 0;
|
int len = 0;
|
||||||
uint8_t raw[MAX_TRANS_UNIT];
|
uint8_t raw[MAX_TRANS_UNIT];
|
||||||
|
|
||||||
#ifdef NODE_ID
|
|
||||||
raw[len++] = NODE_ID;
|
|
||||||
#endif
|
|
||||||
raw[len++] = outbound->header;
|
raw[len++] = outbound->header;
|
||||||
if (outbound->hasTransportCodes()) {
|
if (outbound->hasTransportCodes()) {
|
||||||
memcpy(&raw[len], &outbound->transport_codes[0], 2); len += 2;
|
memcpy(&raw[len], &outbound->transport_codes[0], 2); len += 2;
|
||||||
memcpy(&raw[len], &outbound->transport_codes[1], 2); len += 2;
|
memcpy(&raw[len], &outbound->transport_codes[1], 2); len += 2;
|
||||||
}
|
}
|
||||||
raw[len++] = outbound->path_len;
|
raw[len++] = outbound->path_len;
|
||||||
memcpy(&raw[len], outbound->path, outbound->path_len); len += outbound->path_len;
|
len += Packet::writePath(&raw[len], outbound->path, outbound->path_len);
|
||||||
|
|
||||||
if (len + outbound->payload_len > MAX_TRANS_UNIT) {
|
if (len + outbound->payload_len > MAX_TRANS_UNIT) {
|
||||||
MESH_DEBUG_PRINTLN("%s Dispatcher::checkSend(): FATAL: Invalid packet queued... too long, len=%d", getLogDateTime(), len + outbound->payload_len);
|
MESH_DEBUG_PRINTLN("%s Dispatcher::checkSend(): FATAL: Invalid packet queued... too long, len=%d", getLogDateTime(), len + outbound->payload_len);
|
||||||
@@ -360,7 +320,7 @@ void Dispatcher::releasePacket(Packet* packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Dispatcher::sendPacket(Packet* packet, uint8_t priority, uint32_t delay_millis) {
|
void Dispatcher::sendPacket(Packet* packet, uint8_t priority, uint32_t delay_millis) {
|
||||||
if (packet->path_len > MAX_PATH_SIZE || packet->payload_len > MAX_PACKET_PAYLOAD) {
|
if (!Packet::isValidPathLen(packet->path_len) || packet->payload_len > MAX_PACKET_PAYLOAD) {
|
||||||
MESH_DEBUG_PRINTLN("%s Dispatcher::sendPacket(): ERROR: invalid packet... path_len=%d, payload_len=%d", getLogDateTime(), (uint32_t) packet->path_len, (uint32_t) packet->payload_len);
|
MESH_DEBUG_PRINTLN("%s Dispatcher::sendPacket(): ERROR: invalid packet... path_len=%d, payload_len=%d", getLogDateTime(), (uint32_t) packet->path_len, (uint32_t) packet->payload_len);
|
||||||
_mgr->free(packet);
|
_mgr->free(packet);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -122,12 +122,8 @@ class Dispatcher {
|
|||||||
bool prev_isrecv_mode;
|
bool prev_isrecv_mode;
|
||||||
uint32_t n_sent_flood, n_sent_direct;
|
uint32_t n_sent_flood, n_sent_direct;
|
||||||
uint32_t n_recv_flood, n_recv_direct;
|
uint32_t n_recv_flood, n_recv_direct;
|
||||||
unsigned long tx_budget_ms;
|
|
||||||
unsigned long last_budget_update;
|
|
||||||
unsigned long duty_cycle_window_ms;
|
|
||||||
|
|
||||||
void processRecvPacket(Packet* pkt);
|
void processRecvPacket(Packet* pkt);
|
||||||
void updateTxBudget();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PacketManager* _mgr;
|
PacketManager* _mgr;
|
||||||
@@ -146,9 +142,6 @@ protected:
|
|||||||
_err_flags = 0;
|
_err_flags = 0;
|
||||||
radio_nonrx_start = 0;
|
radio_nonrx_start = 0;
|
||||||
prev_isrecv_mode = true;
|
prev_isrecv_mode = true;
|
||||||
tx_budget_ms = 0;
|
|
||||||
last_budget_update = 0;
|
|
||||||
duty_cycle_window_ms = 3600000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual DispatcherAction onRecvPacket(Packet* pkt) = 0;
|
virtual DispatcherAction onRecvPacket(Packet* pkt) = 0;
|
||||||
@@ -166,7 +159,6 @@ protected:
|
|||||||
virtual uint32_t getCADFailMaxDuration() const;
|
virtual uint32_t getCADFailMaxDuration() const;
|
||||||
virtual int getInterferenceThreshold() const { return 0; } // disabled by default
|
virtual int getInterferenceThreshold() const { return 0; } // disabled by default
|
||||||
virtual int getAGCResetInterval() const { return 0; } // disabled by default
|
virtual int getAGCResetInterval() const { return 0; } // disabled by default
|
||||||
virtual unsigned long getDutyCycleWindowMs() const { return 3600000; }
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void begin();
|
void begin();
|
||||||
@@ -176,9 +168,8 @@ public:
|
|||||||
void releasePacket(Packet* packet);
|
void releasePacket(Packet* packet);
|
||||||
void sendPacket(Packet* packet, uint8_t priority, uint32_t delay_millis=0);
|
void sendPacket(Packet* packet, uint8_t priority, uint32_t delay_millis=0);
|
||||||
|
|
||||||
unsigned long getTotalAirTime() const { return total_air_time; }
|
unsigned long getTotalAirTime() const { return total_air_time; } // in milliseconds
|
||||||
unsigned long getReceiveAirTime() const {return rx_air_time; }
|
unsigned long getReceiveAirTime() const {return rx_air_time; }
|
||||||
unsigned long getRemainingTxBudget() const { return tx_budget_ms; }
|
|
||||||
uint32_t getNumSentFlood() const { return n_sent_flood; }
|
uint32_t getNumSentFlood() const { return n_sent_flood; }
|
||||||
uint32_t getNumSentDirect() const { return n_sent_direct; }
|
uint32_t getNumSentDirect() const { return n_sent_direct; }
|
||||||
uint32_t getNumRecvFlood() const { return n_recv_flood; }
|
uint32_t getNumRecvFlood() const { return n_recv_flood; }
|
||||||
@@ -193,6 +184,7 @@ public:
|
|||||||
unsigned long futureMillis(int millis_from_now) const;
|
unsigned long futureMillis(int millis_from_now) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool tryParsePacket(Packet* pkt, const uint8_t* raw, int len);
|
||||||
void checkRecv();
|
void checkRecv();
|
||||||
void checkSend();
|
void checkSend();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ public:
|
|||||||
memcpy(dest, pub_key, PATH_HASH_SIZE); // hash is just prefix of pub_key
|
memcpy(dest, pub_key, PATH_HASH_SIZE); // hash is just prefix of pub_key
|
||||||
return PATH_HASH_SIZE;
|
return PATH_HASH_SIZE;
|
||||||
}
|
}
|
||||||
|
int copyHashTo(uint8_t* dest, uint8_t len) const {
|
||||||
|
memcpy(dest, pub_key, len); // hash is just prefix of pub_key
|
||||||
|
return len;
|
||||||
|
}
|
||||||
bool isHashMatch(const uint8_t* hash) const {
|
bool isHashMatch(const uint8_t* hash) const {
|
||||||
return memcmp(hash, pub_key, PATH_HASH_SIZE) == 0;
|
return memcmp(hash, pub_key, PATH_HASH_SIZE) == 0;
|
||||||
}
|
}
|
||||||
|
|||||||
74
src/Mesh.cpp
74
src/Mesh.cpp
@@ -39,11 +39,6 @@ int Mesh::searchChannelsByHash(const uint8_t* hash, GroupChannel channels[], int
|
|||||||
}
|
}
|
||||||
|
|
||||||
DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
|
DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
|
||||||
if (pkt->getPayloadVer() > PAYLOAD_VER_1) { // not supported in this firmware version
|
|
||||||
MESH_DEBUG_PRINTLN("%s Mesh::onRecvPacket(): unsupported packet version", getLogDateTime());
|
|
||||||
return ACTION_RELEASE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pkt->isRouteDirect() && pkt->getPayloadType() == PAYLOAD_TYPE_TRACE) {
|
if (pkt->isRouteDirect() && pkt->getPayloadType() == PAYLOAD_TYPE_TRACE) {
|
||||||
if (pkt->path_len < MAX_PATH_SIZE) {
|
if (pkt->path_len < MAX_PATH_SIZE) {
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
@@ -70,14 +65,14 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pkt->isRouteDirect() && pkt->getPayloadType() == PAYLOAD_TYPE_CONTROL && (pkt->payload[0] & 0x80) != 0) {
|
if (pkt->isRouteDirect() && pkt->getPayloadType() == PAYLOAD_TYPE_CONTROL && (pkt->payload[0] & 0x80) != 0) {
|
||||||
if (pkt->path_len == 0) {
|
if (pkt->getPathHashCount() == 0) {
|
||||||
onControlDataRecv(pkt);
|
onControlDataRecv(pkt);
|
||||||
}
|
}
|
||||||
// just zero-hop control packets allowed (for this subset of payloads)
|
// just zero-hop control packets allowed (for this subset of payloads)
|
||||||
return ACTION_RELEASE;
|
return ACTION_RELEASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pkt->isRouteDirect() && pkt->path_len >= PATH_HASH_SIZE) {
|
if (pkt->isRouteDirect() && pkt->getPathHashCount() > 0) {
|
||||||
// check for 'early received' ACK
|
// check for 'early received' ACK
|
||||||
if (pkt->getPayloadType() == PAYLOAD_TYPE_ACK) {
|
if (pkt->getPayloadType() == PAYLOAD_TYPE_ACK) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -88,7 +83,7 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self_id.isHashMatch(pkt->path) && allowPacketForward(pkt)) {
|
if (self_id.isHashMatch(pkt->path, pkt->getPathHashSize()) && allowPacketForward(pkt)) {
|
||||||
if (pkt->getPayloadType() == PAYLOAD_TYPE_MULTIPART) {
|
if (pkt->getPayloadType() == PAYLOAD_TYPE_MULTIPART) {
|
||||||
return forwardMultipartDirect(pkt);
|
return forwardMultipartDirect(pkt);
|
||||||
} else if (pkt->getPayloadType() == PAYLOAD_TYPE_ACK) {
|
} else if (pkt->getPayloadType() == PAYLOAD_TYPE_ACK) {
|
||||||
@@ -158,7 +153,9 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
|
|||||||
if (pkt->getPayloadType() == PAYLOAD_TYPE_PATH) {
|
if (pkt->getPayloadType() == PAYLOAD_TYPE_PATH) {
|
||||||
int k = 0;
|
int k = 0;
|
||||||
uint8_t path_len = data[k++];
|
uint8_t path_len = data[k++];
|
||||||
uint8_t* path = &data[k]; k += path_len;
|
uint8_t hash_size = (path_len >> 6) + 1;
|
||||||
|
uint8_t hash_count = path_len & 63;
|
||||||
|
uint8_t* path = &data[k]; k += hash_size*hash_count;
|
||||||
uint8_t extra_type = data[k++] & 0x0F; // upper 4 bits reserved for future use
|
uint8_t extra_type = data[k++] & 0x0F; // upper 4 bits reserved for future use
|
||||||
uint8_t* extra = &data[k];
|
uint8_t* extra = &data[k];
|
||||||
uint8_t extra_len = len - k; // remainder of packet (may be padded with zeroes!)
|
uint8_t extra_len = len - k; // remainder of packet (may be padded with zeroes!)
|
||||||
@@ -293,8 +290,7 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
|
|||||||
if (type == PAYLOAD_TYPE_ACK && pkt->payload_len >= 5) { // a multipart ACK
|
if (type == PAYLOAD_TYPE_ACK && pkt->payload_len >= 5) { // a multipart ACK
|
||||||
Packet tmp;
|
Packet tmp;
|
||||||
tmp.header = pkt->header;
|
tmp.header = pkt->header;
|
||||||
tmp.path_len = pkt->path_len;
|
tmp.path_len = Packet::copyPath(tmp.path, pkt->path, pkt->path_len);
|
||||||
memcpy(tmp.path, pkt->path, pkt->path_len);
|
|
||||||
tmp.payload_len = pkt->payload_len - 1;
|
tmp.payload_len = pkt->payload_len - 1;
|
||||||
memcpy(tmp.payload, &pkt->payload[1], tmp.payload_len);
|
memcpy(tmp.payload, &pkt->payload[1], tmp.payload_len);
|
||||||
|
|
||||||
@@ -321,27 +317,25 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
|
|||||||
|
|
||||||
void Mesh::removeSelfFromPath(Packet* pkt) {
|
void Mesh::removeSelfFromPath(Packet* pkt) {
|
||||||
// remove our hash from 'path'
|
// remove our hash from 'path'
|
||||||
pkt->path_len -= PATH_HASH_SIZE;
|
pkt->setPathHashCount(pkt->getPathHashCount() - 1); // decrement the count
|
||||||
#if 0
|
|
||||||
memcpy(pkt->path, &pkt->path[PATH_HASH_SIZE], pkt->path_len);
|
uint8_t sz = pkt->getPathHashSize();
|
||||||
#elif PATH_HASH_SIZE == 1
|
for (int k = 0; k < pkt->getPathHashCount()*sz; k += sz) { // shuffle path by 1 'entry'
|
||||||
for (int k = 0; k < pkt->path_len; k++) { // shuffle bytes by 1
|
memcpy(&pkt->path[k], &pkt->path[k + sz], sz);
|
||||||
pkt->path[k] = pkt->path[k + 1];
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#error "need path remove impl"
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatcherAction Mesh::routeRecvPacket(Packet* packet) {
|
DispatcherAction Mesh::routeRecvPacket(Packet* packet) {
|
||||||
|
uint8_t n = packet->getPathHashCount();
|
||||||
if (packet->isRouteFlood() && !packet->isMarkedDoNotRetransmit()
|
if (packet->isRouteFlood() && !packet->isMarkedDoNotRetransmit()
|
||||||
&& packet->path_len + PATH_HASH_SIZE <= MAX_PATH_SIZE && allowPacketForward(packet)) {
|
&& (n + 1)*packet->getPathHashSize() <= MAX_PATH_SIZE && allowPacketForward(packet)) {
|
||||||
// append this node's hash to 'path'
|
// append this node's hash to 'path'
|
||||||
packet->path_len += self_id.copyHashTo(&packet->path[packet->path_len]);
|
self_id.copyHashTo(&packet->path[n * packet->getPathHashSize()], packet->getPathHashSize());
|
||||||
|
packet->setPathHashCount(n + 1);
|
||||||
|
|
||||||
uint32_t d = getRetransmitDelay(packet);
|
uint32_t d = getRetransmitDelay(packet);
|
||||||
// as this propagates outwards, give it lower and lower priority
|
// as this propagates outwards, give it lower and lower priority
|
||||||
return ACTION_RETRANSMIT_DELAYED(packet->path_len, d); // give priority to closer sources, than ones further away
|
return ACTION_RETRANSMIT_DELAYED(packet->getPathHashCount(), d); // give priority to closer sources, than ones further away
|
||||||
}
|
}
|
||||||
return ACTION_RELEASE;
|
return ACTION_RELEASE;
|
||||||
}
|
}
|
||||||
@@ -353,8 +347,7 @@ DispatcherAction Mesh::forwardMultipartDirect(Packet* pkt) {
|
|||||||
if (type == PAYLOAD_TYPE_ACK && pkt->payload_len >= 5) { // a multipart ACK
|
if (type == PAYLOAD_TYPE_ACK && pkt->payload_len >= 5) { // a multipart ACK
|
||||||
Packet tmp;
|
Packet tmp;
|
||||||
tmp.header = pkt->header;
|
tmp.header = pkt->header;
|
||||||
tmp.path_len = pkt->path_len;
|
tmp.path_len = Packet::copyPath(tmp.path, pkt->path, pkt->path_len);
|
||||||
memcpy(tmp.path, pkt->path, pkt->path_len);
|
|
||||||
tmp.payload_len = pkt->payload_len - 1;
|
tmp.payload_len = pkt->payload_len - 1;
|
||||||
memcpy(tmp.payload, &pkt->payload[1], tmp.payload_len);
|
memcpy(tmp.payload, &pkt->payload[1], tmp.payload_len);
|
||||||
|
|
||||||
@@ -376,7 +369,7 @@ void Mesh::routeDirectRecvAcks(Packet* packet, uint32_t delay_millis) {
|
|||||||
delay_millis += getDirectRetransmitDelay(packet) + 300;
|
delay_millis += getDirectRetransmitDelay(packet) + 300;
|
||||||
auto a1 = createMultiAck(crc, extra);
|
auto a1 = createMultiAck(crc, extra);
|
||||||
if (a1) {
|
if (a1) {
|
||||||
memcpy(a1->path, packet->path, a1->path_len = packet->path_len);
|
a1->path_len = Packet::copyPath(a1->path, packet->path, packet->path_len);
|
||||||
a1->header &= ~PH_ROUTE_MASK;
|
a1->header &= ~PH_ROUTE_MASK;
|
||||||
a1->header |= ROUTE_TYPE_DIRECT;
|
a1->header |= ROUTE_TYPE_DIRECT;
|
||||||
sendPacket(a1, 0, delay_millis);
|
sendPacket(a1, 0, delay_millis);
|
||||||
@@ -386,7 +379,7 @@ void Mesh::routeDirectRecvAcks(Packet* packet, uint32_t delay_millis) {
|
|||||||
|
|
||||||
auto a2 = createAck(crc);
|
auto a2 = createAck(crc);
|
||||||
if (a2) {
|
if (a2) {
|
||||||
memcpy(a2->path, packet->path, a2->path_len = packet->path_len);
|
a2->path_len = Packet::copyPath(a2->path, packet->path, packet->path_len);
|
||||||
a2->header &= ~PH_ROUTE_MASK;
|
a2->header &= ~PH_ROUTE_MASK;
|
||||||
a2->header |= ROUTE_TYPE_DIRECT;
|
a2->header |= ROUTE_TYPE_DIRECT;
|
||||||
sendPacket(a2, 0, delay_millis);
|
sendPacket(a2, 0, delay_millis);
|
||||||
@@ -439,7 +432,10 @@ Packet* Mesh::createPathReturn(const Identity& dest, const uint8_t* secret, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
Packet* Mesh::createPathReturn(const uint8_t* dest_hash, const uint8_t* secret, const uint8_t* path, uint8_t path_len, uint8_t extra_type, const uint8_t*extra, size_t extra_len) {
|
Packet* Mesh::createPathReturn(const uint8_t* dest_hash, const uint8_t* secret, const uint8_t* path, uint8_t path_len, uint8_t extra_type, const uint8_t*extra, size_t extra_len) {
|
||||||
if (path_len + extra_len + 5 > MAX_COMBINED_PATH) return NULL; // too long!!
|
uint8_t path_hash_size = (path_len >> 6) + 1;
|
||||||
|
uint8_t path_hash_count = path_len & 63;
|
||||||
|
|
||||||
|
if (path_hash_count*path_hash_size + extra_len + 5 > MAX_COMBINED_PATH) return NULL; // too long!!
|
||||||
|
|
||||||
Packet* packet = obtainNewPacket();
|
Packet* packet = obtainNewPacket();
|
||||||
if (packet == NULL) {
|
if (packet == NULL) {
|
||||||
@@ -457,7 +453,7 @@ Packet* Mesh::createPathReturn(const uint8_t* dest_hash, const uint8_t* secret,
|
|||||||
uint8_t data[MAX_PACKET_PAYLOAD];
|
uint8_t data[MAX_PACKET_PAYLOAD];
|
||||||
|
|
||||||
data[data_len++] = path_len;
|
data[data_len++] = path_len;
|
||||||
memcpy(&data[data_len], path, path_len); data_len += path_len;
|
memcpy(&data[data_len], path, path_hash_count*path_hash_size); data_len += path_hash_count*path_hash_size;
|
||||||
if (extra_len > 0) {
|
if (extra_len > 0) {
|
||||||
data[data_len++] = extra_type;
|
data[data_len++] = extra_type;
|
||||||
memcpy(&data[data_len], extra, extra_len); data_len += extra_len;
|
memcpy(&data[data_len], extra, extra_len); data_len += extra_len;
|
||||||
@@ -624,15 +620,19 @@ Packet* Mesh::createControlData(const uint8_t* data, size_t len) {
|
|||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::sendFlood(Packet* packet, uint32_t delay_millis) {
|
void Mesh::sendFlood(Packet* packet, uint32_t delay_millis, uint8_t path_hash_size) {
|
||||||
if (packet->getPayloadType() == PAYLOAD_TYPE_TRACE) {
|
if (packet->getPayloadType() == PAYLOAD_TYPE_TRACE) {
|
||||||
MESH_DEBUG_PRINTLN("%s Mesh::sendFlood(): TRACE type not suspported", getLogDateTime());
|
MESH_DEBUG_PRINTLN("%s Mesh::sendFlood(): TRACE type not suspported", getLogDateTime());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (path_hash_size == 0 || path_hash_size > 3) {
|
||||||
|
MESH_DEBUG_PRINTLN("%s Mesh::sendFlood(): invalid path_hash_size", getLogDateTime());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
packet->header &= ~PH_ROUTE_MASK;
|
packet->header &= ~PH_ROUTE_MASK;
|
||||||
packet->header |= ROUTE_TYPE_FLOOD;
|
packet->header |= ROUTE_TYPE_FLOOD;
|
||||||
packet->path_len = 0;
|
packet->setPathHashSizeAndCount(path_hash_size, 0);
|
||||||
|
|
||||||
_tables->hasSeen(packet); // mark this packet as already sent in case it is rebroadcast back to us
|
_tables->hasSeen(packet); // mark this packet as already sent in case it is rebroadcast back to us
|
||||||
|
|
||||||
@@ -647,17 +647,21 @@ void Mesh::sendFlood(Packet* packet, uint32_t delay_millis) {
|
|||||||
sendPacket(packet, pri, delay_millis);
|
sendPacket(packet, pri, delay_millis);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::sendFlood(Packet* packet, uint16_t* transport_codes, uint32_t delay_millis) {
|
void Mesh::sendFlood(Packet* packet, uint16_t* transport_codes, uint32_t delay_millis, uint8_t path_hash_size) {
|
||||||
if (packet->getPayloadType() == PAYLOAD_TYPE_TRACE) {
|
if (packet->getPayloadType() == PAYLOAD_TYPE_TRACE) {
|
||||||
MESH_DEBUG_PRINTLN("%s Mesh::sendFlood(): TRACE type not suspported", getLogDateTime());
|
MESH_DEBUG_PRINTLN("%s Mesh::sendFlood(): TRACE type not suspported", getLogDateTime());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (path_hash_size == 0 || path_hash_size > 3) {
|
||||||
|
MESH_DEBUG_PRINTLN("%s Mesh::sendFlood(): invalid path_hash_size", getLogDateTime());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
packet->header &= ~PH_ROUTE_MASK;
|
packet->header &= ~PH_ROUTE_MASK;
|
||||||
packet->header |= ROUTE_TYPE_TRANSPORT_FLOOD;
|
packet->header |= ROUTE_TYPE_TRANSPORT_FLOOD;
|
||||||
packet->transport_codes[0] = transport_codes[0];
|
packet->transport_codes[0] = transport_codes[0];
|
||||||
packet->transport_codes[1] = transport_codes[1];
|
packet->transport_codes[1] = transport_codes[1];
|
||||||
packet->path_len = 0;
|
packet->setPathHashSizeAndCount(path_hash_size, 0);
|
||||||
|
|
||||||
_tables->hasSeen(packet); // mark this packet as already sent in case it is rebroadcast back to us
|
_tables->hasSeen(packet); // mark this packet as already sent in case it is rebroadcast back to us
|
||||||
|
|
||||||
@@ -679,13 +683,13 @@ void Mesh::sendDirect(Packet* packet, const uint8_t* path, uint8_t path_len, uin
|
|||||||
uint8_t pri;
|
uint8_t pri;
|
||||||
if (packet->getPayloadType() == PAYLOAD_TYPE_TRACE) { // TRACE packets are different
|
if (packet->getPayloadType() == PAYLOAD_TYPE_TRACE) { // TRACE packets are different
|
||||||
// for TRACE packets, path is appended to end of PAYLOAD. (path is used for SNR's)
|
// for TRACE packets, path is appended to end of PAYLOAD. (path is used for SNR's)
|
||||||
memcpy(&packet->payload[packet->payload_len], path, path_len);
|
memcpy(&packet->payload[packet->payload_len], path, path_len); // NOTE: path_len here can be > 64, and NOT in the new scheme
|
||||||
packet->payload_len += path_len;
|
packet->payload_len += path_len;
|
||||||
|
|
||||||
packet->path_len = 0;
|
packet->path_len = 0;
|
||||||
pri = 5; // maybe make this configurable
|
pri = 5; // maybe make this configurable
|
||||||
} else {
|
} else {
|
||||||
memcpy(packet->path, path, packet->path_len = path_len);
|
packet->path_len = Packet::copyPath(packet->path, path, path_len);
|
||||||
if (packet->getPayloadType() == PAYLOAD_TYPE_PATH) {
|
if (packet->getPayloadType() == PAYLOAD_TYPE_PATH) {
|
||||||
pri = 1; // slightly less priority
|
pri = 1; // slightly less priority
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -196,13 +196,13 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \brief send a locally-generated Packet with flood routing
|
* \brief send a locally-generated Packet with flood routing
|
||||||
*/
|
*/
|
||||||
void sendFlood(Packet* packet, uint32_t delay_millis=0);
|
void sendFlood(Packet* packet, uint32_t delay_millis=0, uint8_t path_hash_size=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief send a locally-generated Packet with flood routing
|
* \brief send a locally-generated Packet with flood routing
|
||||||
* \param transport_codes array of 2 codes to attach to packet
|
* \param transport_codes array of 2 codes to attach to packet
|
||||||
*/
|
*/
|
||||||
void sendFlood(Packet* packet, uint16_t* transport_codes, uint32_t delay_millis=0);
|
void sendFlood(Packet* packet, uint16_t* transport_codes, uint32_t delay_millis=0, uint8_t path_hash_size=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief send a locally-generated Packet with Direct routing
|
* \brief send a locally-generated Packet with Direct routing
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public:
|
|||||||
virtual uint32_t getGpio() { return 0; }
|
virtual uint32_t getGpio() { return 0; }
|
||||||
virtual void setGpio(uint32_t values) {}
|
virtual void setGpio(uint32_t values) {}
|
||||||
virtual uint8_t getStartupReason() const = 0;
|
virtual uint8_t getStartupReason() const = 0;
|
||||||
|
virtual bool getBootloaderVersion(char* version, size_t max_len) { return false; }
|
||||||
virtual bool startOTAUpdate(const char* id, char reply[]) { return false; } // not supported
|
virtual bool startOTAUpdate(const char* id, char reply[]) { return false; } // not supported
|
||||||
|
|
||||||
// Power management interface (boards with power management override these)
|
// Power management interface (boards with power management override these)
|
||||||
|
|||||||
@@ -10,8 +10,32 @@ Packet::Packet() {
|
|||||||
payload_len = 0;
|
payload_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Packet::isValidPathLen(uint8_t path_len) {
|
||||||
|
uint8_t hash_count = path_len & 63;
|
||||||
|
uint8_t hash_size = (path_len >> 6) + 1;
|
||||||
|
if (hash_size == 4) return false; // Reserved for future
|
||||||
|
return hash_count*hash_size <= MAX_PATH_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Packet::writePath(uint8_t* dest, const uint8_t* src, uint8_t path_len) {
|
||||||
|
uint8_t hash_count = path_len & 63;
|
||||||
|
uint8_t hash_size = (path_len >> 6) + 1;
|
||||||
|
size_t len = hash_count*hash_size;
|
||||||
|
if (len > MAX_PATH_SIZE) {
|
||||||
|
MESH_DEBUG_PRINTLN("Packet::copyPath, invalid path_len=%d", (uint32_t)path_len);
|
||||||
|
return 0; // Error
|
||||||
|
}
|
||||||
|
memcpy(dest, src, len);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Packet::copyPath(uint8_t* dest, const uint8_t* src, uint8_t path_len) {
|
||||||
|
writePath(dest, src, path_len);
|
||||||
|
return path_len;
|
||||||
|
}
|
||||||
|
|
||||||
int Packet::getRawLength() const {
|
int Packet::getRawLength() const {
|
||||||
return 2 + path_len + payload_len + (hasTransportCodes() ? 4 : 0);
|
return 2 + getPathByteLen() + payload_len + (hasTransportCodes() ? 4 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Packet::calculatePacketHash(uint8_t* hash) const {
|
void Packet::calculatePacketHash(uint8_t* hash) const {
|
||||||
@@ -33,7 +57,7 @@ uint8_t Packet::writeTo(uint8_t dest[]) const {
|
|||||||
memcpy(&dest[i], &transport_codes[1], 2); i += 2;
|
memcpy(&dest[i], &transport_codes[1], 2); i += 2;
|
||||||
}
|
}
|
||||||
dest[i++] = path_len;
|
dest[i++] = path_len;
|
||||||
memcpy(&dest[i], path, path_len); i += path_len;
|
i += writePath(&dest[i], path, path_len);
|
||||||
memcpy(&dest[i], payload, payload_len); i += payload_len;
|
memcpy(&dest[i], payload, payload_len); i += payload_len;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -48,8 +72,11 @@ bool Packet::readFrom(const uint8_t src[], uint8_t len) {
|
|||||||
transport_codes[0] = transport_codes[1] = 0;
|
transport_codes[0] = transport_codes[1] = 0;
|
||||||
}
|
}
|
||||||
path_len = src[i++];
|
path_len = src[i++];
|
||||||
if (path_len > sizeof(path)) return false; // bad encoding
|
if (!isValidPathLen(path_len)) return false; // bad encoding
|
||||||
memcpy(path, &src[i], path_len); i += path_len;
|
|
||||||
|
uint8_t bl = getPathByteLen();
|
||||||
|
memcpy(path, &src[i], bl); i += bl;
|
||||||
|
|
||||||
if (i >= len) return false; // bad encoding
|
if (i >= len) return false; // bad encoding
|
||||||
payload_len = len - i;
|
payload_len = len - i;
|
||||||
if (payload_len > sizeof(payload)) return false; // bad encoding
|
if (payload_len > sizeof(payload)) return false; // bad encoding
|
||||||
|
|||||||
10
src/Packet.h
10
src/Packet.h
@@ -76,6 +76,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
uint8_t getPayloadVer() const { return (header >> PH_VER_SHIFT) & PH_VER_MASK; }
|
uint8_t getPayloadVer() const { return (header >> PH_VER_SHIFT) & PH_VER_MASK; }
|
||||||
|
|
||||||
|
uint8_t getPathHashSize() const { return (path_len >> 6) + 1; }
|
||||||
|
uint8_t getPathHashCount() const { return path_len & 63; }
|
||||||
|
uint8_t getPathByteLen() const { return getPathHashCount() * getPathHashSize(); }
|
||||||
|
void setPathHashCount(uint8_t n) { path_len &= ~63; path_len |= n; }
|
||||||
|
void setPathHashSizeAndCount(uint8_t sz, uint8_t n) { path_len = ((sz - 1) << 6) | (n & 63); }
|
||||||
|
|
||||||
|
static uint8_t copyPath(uint8_t* dest, const uint8_t* src, uint8_t path_len); // returns path_len
|
||||||
|
static size_t writePath(uint8_t* dest, const uint8_t* src, uint8_t path_len); // returns byte length written
|
||||||
|
static bool isValidPathLen(uint8_t path_len);
|
||||||
|
|
||||||
void markDoNotRetransmit() { header = 0xFF; }
|
void markDoNotRetransmit() { header = 0xFF; }
|
||||||
bool isMarkedDoNotRetransmit() const { return header == 0xFF; }
|
bool isMarkedDoNotRetransmit() const { return header == 0xFF; }
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ mesh::Packet* BaseChatMesh::createSelfAdvert(const char* name, double lat, doubl
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BaseChatMesh::sendAckTo(const ContactInfo& dest, uint32_t ack_hash) {
|
void BaseChatMesh::sendAckTo(const ContactInfo& dest, uint32_t ack_hash) {
|
||||||
if (dest.out_path_len < 0) {
|
if (dest.out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
mesh::Packet* ack = createAck(ack_hash);
|
mesh::Packet* ack = createAck(ack_hash);
|
||||||
if (ack) sendFloodScoped(dest, ack, TXT_ACK_DELAY);
|
if (ack) sendFloodScoped(dest, ack, TXT_ACK_DELAY);
|
||||||
} else {
|
} else {
|
||||||
@@ -92,7 +92,7 @@ ContactInfo* BaseChatMesh::allocateContactSlot() {
|
|||||||
void BaseChatMesh::populateContactFromAdvert(ContactInfo& ci, const mesh::Identity& id, const AdvertDataParser& parser, uint32_t timestamp) {
|
void BaseChatMesh::populateContactFromAdvert(ContactInfo& ci, const mesh::Identity& id, const AdvertDataParser& parser, uint32_t timestamp) {
|
||||||
memset(&ci, 0, sizeof(ci));
|
memset(&ci, 0, sizeof(ci));
|
||||||
ci.id = id;
|
ci.id = id;
|
||||||
ci.out_path_len = -1; // initially out_path is unknown
|
ci.out_path_len = OUT_PATH_UNKNOWN;
|
||||||
StrHelper::strncpy(ci.name, parser.getName(), sizeof(ci.name));
|
StrHelper::strncpy(ci.name, parser.getName(), sizeof(ci.name));
|
||||||
ci.type = parser.getType();
|
ci.type = parser.getType();
|
||||||
if (parser.hasLatLon()) {
|
if (parser.hasLatLon()) {
|
||||||
@@ -141,6 +141,15 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check hop limit for new contacts (0 = no limit, 1 = direct (0 hops), N = up to N-1 hops)
|
||||||
|
uint8_t max_hops = getAutoAddMaxHops();
|
||||||
|
if (max_hops > 0 && packet->getPathHashCount() >= max_hops) {
|
||||||
|
ContactInfo ci;
|
||||||
|
populateContactFromAdvert(ci, id, parser, timestamp);
|
||||||
|
onDiscoveredContact(ci, true, packet->path_len, packet->path); // let UI know
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
from = allocateContactSlot();
|
from = allocateContactSlot();
|
||||||
if (from == NULL) {
|
if (from == NULL) {
|
||||||
ContactInfo ci;
|
ContactInfo ci;
|
||||||
@@ -263,7 +272,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
|
|||||||
} else {
|
} else {
|
||||||
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, from.id, secret, temp_buf, reply_len);
|
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, from.id, secret, temp_buf, reply_len);
|
||||||
if (reply) {
|
if (reply) {
|
||||||
if (from.out_path_len >= 0) { // we have an out_path, so send DIRECT
|
if (from.out_path_len != OUT_PATH_UNKNOWN) { // we have an out_path, so send DIRECT
|
||||||
sendDirect(reply, from.out_path, from.out_path_len, SERVER_RESPONSE_DELAY);
|
sendDirect(reply, from.out_path, from.out_path_len, SERVER_RESPONSE_DELAY);
|
||||||
} else {
|
} else {
|
||||||
sendFloodScoped(from, reply, SERVER_RESPONSE_DELAY);
|
sendFloodScoped(from, reply, SERVER_RESPONSE_DELAY);
|
||||||
@@ -273,7 +282,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
|
|||||||
}
|
}
|
||||||
} else if (type == PAYLOAD_TYPE_RESPONSE && len > 0) {
|
} else if (type == PAYLOAD_TYPE_RESPONSE && len > 0) {
|
||||||
onContactResponse(from, data, len);
|
onContactResponse(from, data, len);
|
||||||
if (packet->isRouteFlood() && from.out_path_len >= 0) {
|
if (packet->isRouteFlood() && from.out_path_len != OUT_PATH_UNKNOWN) {
|
||||||
// we have direct path, but other node is still sending flood response, so maybe they didn't receive reciprocal path properly(?)
|
// we have direct path, but other node is still sending flood response, so maybe they didn't receive reciprocal path properly(?)
|
||||||
handleReturnPathRetry(from, packet->path, packet->path_len);
|
handleReturnPathRetry(from, packet->path, packet->path_len);
|
||||||
}
|
}
|
||||||
@@ -295,7 +304,7 @@ bool BaseChatMesh::onPeerPathRecv(mesh::Packet* packet, int sender_idx, const ui
|
|||||||
bool BaseChatMesh::onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_t in_path_len, uint8_t* out_path, uint8_t out_path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) {
|
bool BaseChatMesh::onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_t in_path_len, uint8_t* out_path, uint8_t out_path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) {
|
||||||
// NOTE: default impl, we just replace the current 'out_path' regardless, whenever sender sends us a new out_path.
|
// NOTE: default impl, we just replace the current 'out_path' regardless, whenever sender sends us a new out_path.
|
||||||
// FUTURE: could store multiple out_paths per contact, and try to find which is the 'best'(?)
|
// FUTURE: could store multiple out_paths per contact, and try to find which is the 'best'(?)
|
||||||
memcpy(from.out_path, out_path, from.out_path_len = out_path_len); // store a copy of path, for sendDirect()
|
from.out_path_len = mesh::Packet::copyPath(from.out_path, out_path, out_path_len); // store a copy of path, for sendDirect()
|
||||||
from.lastmod = getRTCClock()->getCurrentTime();
|
from.lastmod = getRTCClock()->getCurrentTime();
|
||||||
|
|
||||||
onContactPathUpdated(from);
|
onContactPathUpdated(from);
|
||||||
@@ -317,7 +326,7 @@ void BaseChatMesh::onAckRecv(mesh::Packet* packet, uint32_t ack_crc) {
|
|||||||
txt_send_timeout = 0; // matched one we're waiting for, cancel timeout timer
|
txt_send_timeout = 0; // matched one we're waiting for, cancel timeout timer
|
||||||
packet->markDoNotRetransmit(); // ACK was for this node, so don't retransmit
|
packet->markDoNotRetransmit(); // ACK was for this node, so don't retransmit
|
||||||
|
|
||||||
if (packet->isRouteFlood() && from->out_path_len >= 0) {
|
if (packet->isRouteFlood() && from->out_path_len != OUT_PATH_UNKNOWN) {
|
||||||
// we have direct path, but other node is still sending flood, so maybe they didn't receive reciprocal path properly(?)
|
// we have direct path, but other node is still sending flood, so maybe they didn't receive reciprocal path properly(?)
|
||||||
handleReturnPathRetry(*from, packet->path, packet->path_len);
|
handleReturnPathRetry(*from, packet->path, packet->path_len);
|
||||||
}
|
}
|
||||||
@@ -386,7 +395,7 @@ int BaseChatMesh::sendMessage(const ContactInfo& recipient, uint32_t timestamp,
|
|||||||
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
||||||
|
|
||||||
int rc;
|
int rc;
|
||||||
if (recipient.out_path_len < 0) {
|
if (recipient.out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFloodScoped(recipient, pkt);
|
sendFloodScoped(recipient, pkt);
|
||||||
txt_send_timeout = futureMillis(est_timeout = calcFloodTimeoutMillisFor(t));
|
txt_send_timeout = futureMillis(est_timeout = calcFloodTimeoutMillisFor(t));
|
||||||
rc = MSG_SEND_SENT_FLOOD;
|
rc = MSG_SEND_SENT_FLOOD;
|
||||||
@@ -412,7 +421,7 @@ int BaseChatMesh::sendCommandData(const ContactInfo& recipient, uint32_t timest
|
|||||||
|
|
||||||
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
||||||
int rc;
|
int rc;
|
||||||
if (recipient.out_path_len < 0) {
|
if (recipient.out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFloodScoped(recipient, pkt);
|
sendFloodScoped(recipient, pkt);
|
||||||
txt_send_timeout = futureMillis(est_timeout = calcFloodTimeoutMillisFor(t));
|
txt_send_timeout = futureMillis(est_timeout = calcFloodTimeoutMillisFor(t));
|
||||||
rc = MSG_SEND_SENT_FLOOD;
|
rc = MSG_SEND_SENT_FLOOD;
|
||||||
@@ -500,7 +509,7 @@ int BaseChatMesh::sendLogin(const ContactInfo& recipient, const char* password,
|
|||||||
}
|
}
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
||||||
if (recipient.out_path_len < 0) {
|
if (recipient.out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFloodScoped(recipient, pkt);
|
sendFloodScoped(recipient, pkt);
|
||||||
est_timeout = calcFloodTimeoutMillisFor(t);
|
est_timeout = calcFloodTimeoutMillisFor(t);
|
||||||
return MSG_SEND_SENT_FLOOD;
|
return MSG_SEND_SENT_FLOOD;
|
||||||
@@ -525,7 +534,7 @@ int BaseChatMesh::sendAnonReq(const ContactInfo& recipient, const uint8_t* data,
|
|||||||
}
|
}
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
||||||
if (recipient.out_path_len < 0) {
|
if (recipient.out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFloodScoped(recipient, pkt);
|
sendFloodScoped(recipient, pkt);
|
||||||
est_timeout = calcFloodTimeoutMillisFor(t);
|
est_timeout = calcFloodTimeoutMillisFor(t);
|
||||||
return MSG_SEND_SENT_FLOOD;
|
return MSG_SEND_SENT_FLOOD;
|
||||||
@@ -552,7 +561,7 @@ int BaseChatMesh::sendRequest(const ContactInfo& recipient, const uint8_t* req_
|
|||||||
}
|
}
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
||||||
if (recipient.out_path_len < 0) {
|
if (recipient.out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFloodScoped(recipient, pkt);
|
sendFloodScoped(recipient, pkt);
|
||||||
est_timeout = calcFloodTimeoutMillisFor(t);
|
est_timeout = calcFloodTimeoutMillisFor(t);
|
||||||
return MSG_SEND_SENT_FLOOD;
|
return MSG_SEND_SENT_FLOOD;
|
||||||
@@ -579,7 +588,7 @@ int BaseChatMesh::sendRequest(const ContactInfo& recipient, uint8_t req_type, u
|
|||||||
}
|
}
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength());
|
||||||
if (recipient.out_path_len < 0) {
|
if (recipient.out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFloodScoped(recipient, pkt);
|
sendFloodScoped(recipient, pkt);
|
||||||
est_timeout = calcFloodTimeoutMillisFor(t);
|
est_timeout = calcFloodTimeoutMillisFor(t);
|
||||||
return MSG_SEND_SENT_FLOOD;
|
return MSG_SEND_SENT_FLOOD;
|
||||||
@@ -683,7 +692,7 @@ void BaseChatMesh::checkConnections() {
|
|||||||
MESH_DEBUG_PRINTLN("checkConnections(): Keep_alive contact not found!");
|
MESH_DEBUG_PRINTLN("checkConnections(): Keep_alive contact not found!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (contact->out_path_len < 0) {
|
if (contact->out_path_len == OUT_PATH_UNKNOWN) {
|
||||||
MESH_DEBUG_PRINTLN("checkConnections(): Keep_alive contact, no out_path!");
|
MESH_DEBUG_PRINTLN("checkConnections(): Keep_alive contact, no out_path!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -710,7 +719,7 @@ void BaseChatMesh::checkConnections() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BaseChatMesh::resetPathTo(ContactInfo& recipient) {
|
void BaseChatMesh::resetPathTo(ContactInfo& recipient) {
|
||||||
recipient.out_path_len = -1;
|
recipient.out_path_len = OUT_PATH_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ContactInfo* table; // pass via global :-(
|
static ContactInfo* table; // pass via global :-(
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ protected:
|
|||||||
virtual bool shouldAutoAddContactType(uint8_t type) const { return true; }
|
virtual bool shouldAutoAddContactType(uint8_t type) const { return true; }
|
||||||
virtual void onContactsFull() {};
|
virtual void onContactsFull() {};
|
||||||
virtual bool shouldOverwriteWhenFull() const { return false; }
|
virtual bool shouldOverwriteWhenFull() const { return false; }
|
||||||
|
virtual uint8_t getAutoAddMaxHops() const { return 0; } // 0 = no limit, 1 = direct (0 hops), N = up to N-1 hops
|
||||||
virtual void onContactOverwrite(const uint8_t* pub_key) {};
|
virtual void onContactOverwrite(const uint8_t* pub_key) {};
|
||||||
virtual void onDiscoveredContact(ContactInfo& contact, bool is_new, uint8_t path_len, const uint8_t* path) = 0;
|
virtual void onDiscoveredContact(ContactInfo& contact, bool is_new, uint8_t path_len, const uint8_t* path) = 0;
|
||||||
virtual ContactInfo* processAck(const uint8_t *data) = 0;
|
virtual ContactInfo* processAck(const uint8_t *data) = 0;
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms) {
|
|||||||
memset(c, 0, sizeof(*c));
|
memset(c, 0, sizeof(*c));
|
||||||
c->permissions = init_perms;
|
c->permissions = init_perms;
|
||||||
c->id = id;
|
c->id = id;
|
||||||
c->out_path_len = -1; // initially out_path is unknown
|
c->out_path_len = OUT_PATH_UNKNOWN;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,12 @@
|
|||||||
#define PERM_ACL_READ_WRITE 2
|
#define PERM_ACL_READ_WRITE 2
|
||||||
#define PERM_ACL_ADMIN 3
|
#define PERM_ACL_ADMIN 3
|
||||||
|
|
||||||
|
#define OUT_PATH_UNKNOWN 0xFF
|
||||||
|
|
||||||
struct ClientInfo {
|
struct ClientInfo {
|
||||||
mesh::Identity id;
|
mesh::Identity id;
|
||||||
uint8_t permissions;
|
uint8_t permissions;
|
||||||
int8_t out_path_len;
|
uint8_t out_path_len;
|
||||||
uint8_t out_path[MAX_PATH_SIZE];
|
uint8_t out_path[MAX_PATH_SIZE];
|
||||||
uint8_t shared_secret[PUB_KEY_SIZE];
|
uint8_t shared_secret[PUB_KEY_SIZE];
|
||||||
uint32_t last_timestamp; // by THEIR clock (transient)
|
uint32_t last_timestamp; // by THEIR clock (transient)
|
||||||
|
|||||||
@@ -63,7 +63,9 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
|||||||
file.read((uint8_t *)&_prefs->multi_acks, sizeof(_prefs->multi_acks)); // 115
|
file.read((uint8_t *)&_prefs->multi_acks, sizeof(_prefs->multi_acks)); // 115
|
||||||
file.read((uint8_t *)&_prefs->bw, sizeof(_prefs->bw)); // 116
|
file.read((uint8_t *)&_prefs->bw, sizeof(_prefs->bw)); // 116
|
||||||
file.read((uint8_t *)&_prefs->agc_reset_interval, sizeof(_prefs->agc_reset_interval)); // 120
|
file.read((uint8_t *)&_prefs->agc_reset_interval, sizeof(_prefs->agc_reset_interval)); // 120
|
||||||
file.read(pad, 3); // 121
|
file.read((uint8_t *)&_prefs->path_hash_mode, sizeof(_prefs->path_hash_mode)); // 121
|
||||||
|
file.read((uint8_t *)&_prefs->loop_detect, sizeof(_prefs->loop_detect)); // 122
|
||||||
|
file.read(pad, 1); // 123
|
||||||
file.read((uint8_t *)&_prefs->flood_max, sizeof(_prefs->flood_max)); // 124
|
file.read((uint8_t *)&_prefs->flood_max, sizeof(_prefs->flood_max)); // 124
|
||||||
file.read((uint8_t *)&_prefs->flood_advert_interval, sizeof(_prefs->flood_advert_interval)); // 125
|
file.read((uint8_t *)&_prefs->flood_advert_interval, sizeof(_prefs->flood_advert_interval)); // 125
|
||||||
file.read((uint8_t *)&_prefs->interference_threshold, sizeof(_prefs->interference_threshold)); // 126
|
file.read((uint8_t *)&_prefs->interference_threshold, sizeof(_prefs->interference_threshold)); // 126
|
||||||
@@ -97,6 +99,7 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
|||||||
_prefs->tx_power_dbm = constrain(_prefs->tx_power_dbm, -9, 30);
|
_prefs->tx_power_dbm = constrain(_prefs->tx_power_dbm, -9, 30);
|
||||||
_prefs->multi_acks = constrain(_prefs->multi_acks, 0, 1);
|
_prefs->multi_acks = constrain(_prefs->multi_acks, 0, 1);
|
||||||
_prefs->adc_multiplier = constrain(_prefs->adc_multiplier, 0.0f, 10.0f);
|
_prefs->adc_multiplier = constrain(_prefs->adc_multiplier, 0.0f, 10.0f);
|
||||||
|
_prefs->path_hash_mode = constrain(_prefs->path_hash_mode, 0, 2); // NOTE: mode 3 reserved for future
|
||||||
|
|
||||||
// sanitise bad bridge pref values
|
// sanitise bad bridge pref values
|
||||||
_prefs->bridge_enabled = constrain(_prefs->bridge_enabled, 0, 1);
|
_prefs->bridge_enabled = constrain(_prefs->bridge_enabled, 0, 1);
|
||||||
@@ -151,7 +154,9 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
|
|||||||
file.write((uint8_t *)&_prefs->multi_acks, sizeof(_prefs->multi_acks)); // 115
|
file.write((uint8_t *)&_prefs->multi_acks, sizeof(_prefs->multi_acks)); // 115
|
||||||
file.write((uint8_t *)&_prefs->bw, sizeof(_prefs->bw)); // 116
|
file.write((uint8_t *)&_prefs->bw, sizeof(_prefs->bw)); // 116
|
||||||
file.write((uint8_t *)&_prefs->agc_reset_interval, sizeof(_prefs->agc_reset_interval)); // 120
|
file.write((uint8_t *)&_prefs->agc_reset_interval, sizeof(_prefs->agc_reset_interval)); // 120
|
||||||
file.write(pad, 3); // 121
|
file.write((uint8_t *)&_prefs->path_hash_mode, sizeof(_prefs->path_hash_mode)); // 121
|
||||||
|
file.write((uint8_t *)&_prefs->loop_detect, sizeof(_prefs->loop_detect)); // 122
|
||||||
|
file.write(pad, 1); // 123
|
||||||
file.write((uint8_t *)&_prefs->flood_max, sizeof(_prefs->flood_max)); // 124
|
file.write((uint8_t *)&_prefs->flood_max, sizeof(_prefs->flood_max)); // 124
|
||||||
file.write((uint8_t *)&_prefs->flood_advert_interval, sizeof(_prefs->flood_advert_interval)); // 125
|
file.write((uint8_t *)&_prefs->flood_advert_interval, sizeof(_prefs->flood_advert_interval)); // 125
|
||||||
file.write((uint8_t *)&_prefs->interference_threshold, sizeof(_prefs->interference_threshold)); // 126
|
file.write((uint8_t *)&_prefs->interference_threshold, sizeof(_prefs->interference_threshold)); // 126
|
||||||
@@ -206,6 +211,10 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
|||||||
// Reset clock
|
// Reset clock
|
||||||
getRTCClock()->setCurrentTime(1715770351); // 15 May 2024, 8:50pm
|
getRTCClock()->setCurrentTime(1715770351); // 15 May 2024, 8:50pm
|
||||||
_board->reboot(); // doesn't return
|
_board->reboot(); // doesn't return
|
||||||
|
} else if (memcmp(command, "advert.zerohop", 14) == 0 && (command[14] == 0 || command[14] == ' ')) {
|
||||||
|
// send zerohop advert
|
||||||
|
_callbacks->sendSelfAdvertisement(1500, false); // longer delay, give CLI response time to be sent first
|
||||||
|
strcpy(reply, "OK - zerohop advert sent");
|
||||||
} else if (memcmp(command, "advert", 6) == 0) {
|
} else if (memcmp(command, "advert", 6) == 0) {
|
||||||
// send flood advert
|
// send flood advert
|
||||||
_callbacks->sendSelfAdvertisement(1500, true); // longer delay, give CLI response time to be sent first
|
_callbacks->sendSelfAdvertisement(1500, true); // longer delay, give CLI response time to be sent first
|
||||||
@@ -331,6 +340,18 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
|||||||
sp++;
|
sp++;
|
||||||
}
|
}
|
||||||
*reply = 0; // set null terminator
|
*reply = 0; // set null terminator
|
||||||
|
} else if (memcmp(config, "path.hash.mode", 14) == 0) {
|
||||||
|
sprintf(reply, "> %d", (uint32_t)_prefs->path_hash_mode);
|
||||||
|
} else if (memcmp(config, "loop.detect", 11) == 0) {
|
||||||
|
if (_prefs->loop_detect == LOOP_DETECT_OFF) {
|
||||||
|
strcpy(reply, "> off");
|
||||||
|
} else if (_prefs->loop_detect == LOOP_DETECT_MINIMAL) {
|
||||||
|
strcpy(reply, "> minimal");
|
||||||
|
} else if (_prefs->loop_detect == LOOP_DETECT_MODERATE) {
|
||||||
|
strcpy(reply, "> moderate");
|
||||||
|
} else {
|
||||||
|
strcpy(reply, "> strict");
|
||||||
|
}
|
||||||
} else if (memcmp(config, "tx", 2) == 0 && (config[2] == 0 || config[2] == ' ')) {
|
} else if (memcmp(config, "tx", 2) == 0 && (config[2] == 0 || config[2] == ' ')) {
|
||||||
sprintf(reply, "> %d", (int32_t) _prefs->tx_power_dbm);
|
sprintf(reply, "> %d", (int32_t) _prefs->tx_power_dbm);
|
||||||
} else if (memcmp(config, "freq", 4) == 0) {
|
} else if (memcmp(config, "freq", 4) == 0) {
|
||||||
@@ -368,6 +389,17 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
|||||||
} else if (memcmp(config, "bridge.secret", 13) == 0) {
|
} else if (memcmp(config, "bridge.secret", 13) == 0) {
|
||||||
sprintf(reply, "> %s", _prefs->bridge_secret);
|
sprintf(reply, "> %s", _prefs->bridge_secret);
|
||||||
#endif
|
#endif
|
||||||
|
} else if (memcmp(config, "bootloader.ver", 14) == 0) {
|
||||||
|
#ifdef NRF52_PLATFORM
|
||||||
|
char ver[32];
|
||||||
|
if (_board->getBootloaderVersion(ver, sizeof(ver))) {
|
||||||
|
sprintf(reply, "> %s", ver);
|
||||||
|
} else {
|
||||||
|
strcpy(reply, "> unknown");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
strcpy(reply, "ERROR: unsupported");
|
||||||
|
#endif
|
||||||
} else if (memcmp(config, "adc.multiplier", 14) == 0) {
|
} else if (memcmp(config, "adc.multiplier", 14) == 0) {
|
||||||
float adc_mult = _board->getAdcMultiplier();
|
float adc_mult = _board->getAdcMultiplier();
|
||||||
if (adc_mult == 0.0f) {
|
if (adc_mult == 0.0f) {
|
||||||
@@ -553,6 +585,36 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
|||||||
*dp = 0;
|
*dp = 0;
|
||||||
savePrefs();
|
savePrefs();
|
||||||
strcpy(reply, "OK");
|
strcpy(reply, "OK");
|
||||||
|
} else if (memcmp(config, "path.hash.mode ", 15) == 0) {
|
||||||
|
config += 15;
|
||||||
|
uint8_t mode = atoi(config);
|
||||||
|
if (mode < 3) {
|
||||||
|
_prefs->path_hash_mode = mode;
|
||||||
|
savePrefs();
|
||||||
|
strcpy(reply, "OK");
|
||||||
|
} else {
|
||||||
|
strcpy(reply, "Error, must be 0,1, or 2");
|
||||||
|
}
|
||||||
|
} else if (memcmp(config, "loop.detect ", 12) == 0) {
|
||||||
|
config += 12;
|
||||||
|
uint8_t mode;
|
||||||
|
if (memcmp(config, "off", 3) == 0) {
|
||||||
|
mode = LOOP_DETECT_OFF;
|
||||||
|
} else if (memcmp(config, "minimal", 7) == 0) {
|
||||||
|
mode = LOOP_DETECT_MINIMAL;
|
||||||
|
} else if (memcmp(config, "moderate", 8) == 0) {
|
||||||
|
mode = LOOP_DETECT_MODERATE;
|
||||||
|
} else if (memcmp(config, "strict", 6) == 0) {
|
||||||
|
mode = LOOP_DETECT_STRICT;
|
||||||
|
} else {
|
||||||
|
mode = 0xFF;
|
||||||
|
strcpy(reply, "Error, must be: off, minimal, moderate, or strict");
|
||||||
|
}
|
||||||
|
if (mode != 0xFF) {
|
||||||
|
_prefs->loop_detect = mode;
|
||||||
|
savePrefs();
|
||||||
|
strcpy(reply, "OK");
|
||||||
|
}
|
||||||
} else if (memcmp(config, "tx ", 3) == 0) {
|
} else if (memcmp(config, "tx ", 3) == 0) {
|
||||||
_prefs->tx_power_dbm = atoi(&config[3]);
|
_prefs->tx_power_dbm = atoi(&config[3]);
|
||||||
savePrefs();
|
savePrefs();
|
||||||
@@ -626,7 +688,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
|||||||
};
|
};
|
||||||
} else if (memcmp(config, "flood.advert.base ", 18) == 0) {
|
} else if (memcmp(config, "flood.advert.base ", 18) == 0) {
|
||||||
float f = atof(&config[18]);
|
float f = atof(&config[18]);
|
||||||
if((f > 0) || (f<1)) {
|
if(f >= 0 && f <= 1) {
|
||||||
_prefs->flood_advert_base = f;
|
_prefs->flood_advert_base = f;
|
||||||
savePrefs();
|
savePrefs();
|
||||||
strcpy(reply, "OK");
|
strcpy(reply, "OK");
|
||||||
@@ -708,6 +770,9 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
|||||||
LocationProvider * l = _sensors->getLocationProvider();
|
LocationProvider * l = _sensors->getLocationProvider();
|
||||||
if (l != NULL) {
|
if (l != NULL) {
|
||||||
l->syncTime();
|
l->syncTime();
|
||||||
|
strcpy(reply, "ok");
|
||||||
|
} else {
|
||||||
|
strcpy(reply, "gps provider not found");
|
||||||
}
|
}
|
||||||
} else if (memcmp(command, "gps setloc", 10) == 0) {
|
} else if (memcmp(command, "gps setloc", 10) == 0) {
|
||||||
_prefs->node_lat = _sensors->node_lat;
|
_prefs->node_lat = _sensors->node_lat;
|
||||||
@@ -737,7 +802,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
|||||||
_prefs->advert_loc_policy = ADVERT_LOC_SHARE;
|
_prefs->advert_loc_policy = ADVERT_LOC_SHARE;
|
||||||
savePrefs();
|
savePrefs();
|
||||||
strcpy(reply, "ok");
|
strcpy(reply, "ok");
|
||||||
} else if (memcmp(command+11, "prefs", 4) == 0) {
|
} else if (memcmp(command+11, "prefs", 5) == 0) {
|
||||||
_prefs->advert_loc_policy = ADVERT_LOC_PREFS;
|
_prefs->advert_loc_policy = ADVERT_LOC_PREFS;
|
||||||
savePrefs();
|
savePrefs();
|
||||||
strcpy(reply, "ok");
|
strcpy(reply, "ok");
|
||||||
|
|||||||
@@ -13,6 +13,11 @@
|
|||||||
#define ADVERT_LOC_SHARE 1
|
#define ADVERT_LOC_SHARE 1
|
||||||
#define ADVERT_LOC_PREFS 2
|
#define ADVERT_LOC_PREFS 2
|
||||||
|
|
||||||
|
#define LOOP_DETECT_OFF 0
|
||||||
|
#define LOOP_DETECT_MINIMAL 1
|
||||||
|
#define LOOP_DETECT_MODERATE 2
|
||||||
|
#define LOOP_DETECT_STRICT 3
|
||||||
|
|
||||||
struct NodePrefs { // persisted to file
|
struct NodePrefs { // persisted to file
|
||||||
float airtime_factor;
|
float airtime_factor;
|
||||||
char node_name[32];
|
char node_name[32];
|
||||||
@@ -53,6 +58,8 @@ struct NodePrefs { // persisted to file
|
|||||||
uint32_t discovery_mod_timestamp;
|
uint32_t discovery_mod_timestamp;
|
||||||
float adc_multiplier;
|
float adc_multiplier;
|
||||||
char owner_info[120];
|
char owner_info[120];
|
||||||
|
uint8_t path_hash_mode; // which path mode to use when sending
|
||||||
|
uint8_t loop_detect;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CommonCLICallbacks {
|
class CommonCLICallbacks {
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Mesh.h>
|
#include <Mesh.h>
|
||||||
|
|
||||||
|
#define OUT_PATH_UNKNOWN 0xFF
|
||||||
|
|
||||||
struct ContactInfo {
|
struct ContactInfo {
|
||||||
mesh::Identity id;
|
mesh::Identity id;
|
||||||
char name[32];
|
char name[32];
|
||||||
uint8_t type; // on of ADV_TYPE_*
|
uint8_t type; // on of ADV_TYPE_*
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
int8_t out_path_len;
|
uint8_t out_path_len;
|
||||||
mutable bool shared_secret_valid; // flag to indicate if shared_secret has been calculated
|
mutable bool shared_secret_valid; // flag to indicate if shared_secret has been calculated
|
||||||
uint8_t out_path[MAX_PATH_SIZE];
|
uint8_t out_path[MAX_PATH_SIZE];
|
||||||
uint32_t last_advert_timestamp; // by THEIR clock
|
uint32_t last_advert_timestamp; // by THEIR clock
|
||||||
|
|||||||
@@ -297,6 +297,25 @@ float NRF52Board::getMCUTemperature() {
|
|||||||
return temp * 0.25f; // Convert to *C
|
return temp * 0.25f; // Convert to *C
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NRF52Board::getBootloaderVersion(char* out, size_t max_len) {
|
||||||
|
static const char BOOTLOADER_MARKER[] = "UF2 Bootloader ";
|
||||||
|
const uint8_t* flash = (const uint8_t*)0x000FB000; // earliest known info.txt location is 0xFB90B, latest is 0xFCC4B
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < 0x3000 - (sizeof(BOOTLOADER_MARKER) - 1); i++) {
|
||||||
|
if (memcmp(&flash[i], BOOTLOADER_MARKER, sizeof(BOOTLOADER_MARKER) - 1) == 0) {
|
||||||
|
const char* ver = (const char*)&flash[i + sizeof(BOOTLOADER_MARKER) - 1];
|
||||||
|
size_t len = 0;
|
||||||
|
while (len < max_len - 1 && ver[len] != '\0' && ver[len] != ' ' && ver[len] != '\n' && ver[len] != '\r') {
|
||||||
|
out[len] = ver[len];
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
out[len] = '\0';
|
||||||
|
return len > 0; // bootloader string is non-empty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool NRF52Board::startOTAUpdate(const char *id, char reply[]) {
|
bool NRF52Board::startOTAUpdate(const char *id, char reply[]) {
|
||||||
// Config the peripheral connection with maximum bandwidth
|
// Config the peripheral connection with maximum bandwidth
|
||||||
// more SRAM required by SoftDevice
|
// more SRAM required by SoftDevice
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public:
|
|||||||
virtual uint8_t getStartupReason() const override { return startup_reason; }
|
virtual uint8_t getStartupReason() const override { return startup_reason; }
|
||||||
virtual float getMCUTemperature() override;
|
virtual float getMCUTemperature() override;
|
||||||
virtual void reboot() override { NVIC_SystemReset(); }
|
virtual void reboot() override { NVIC_SystemReset(); }
|
||||||
|
virtual bool getBootloaderVersion(char* version, size_t max_len) override;
|
||||||
virtual bool startOTAUpdate(const char *id, char reply[]) override;
|
virtual bool startOTAUpdate(const char *id, char reply[]) override;
|
||||||
virtual void sleep(uint32_t secs) override;
|
virtual void sleep(uint32_t secs) override;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ public:
|
|||||||
digitalWrite(_pin, _active);
|
digitalWrite(_pin, _active);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void release() {
|
void release() {
|
||||||
|
if (_claims == 0) return; // avoid negative _claims
|
||||||
|
|
||||||
_claims--;
|
_claims--;
|
||||||
if (_claims == 0) {
|
if (_claims == 0) {
|
||||||
digitalWrite(_pin, !_active);
|
digitalWrite(_pin, !_active);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ PacketQueue::PacketQueue(int max_entries) {
|
|||||||
int PacketQueue::countBefore(uint32_t now) const {
|
int PacketQueue::countBefore(uint32_t now) const {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (int j = 0; j < _num; j++) {
|
for (int j = 0; j < _num; j++) {
|
||||||
if (_schedule_table[j] > now) continue; // scheduled for future... ignore for now
|
if ((int32_t)(_schedule_table[j] - now) > 0) continue; // scheduled for future... ignore for now
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
@@ -21,7 +21,7 @@ mesh::Packet* PacketQueue::get(uint32_t now) {
|
|||||||
uint8_t min_pri = 0xFF;
|
uint8_t min_pri = 0xFF;
|
||||||
int best_idx = -1;
|
int best_idx = -1;
|
||||||
for (int j = 0; j < _num; j++) {
|
for (int j = 0; j < _num; j++) {
|
||||||
if (_schedule_table[j] > now) continue; // scheduled for future... ignore for now
|
if ((int32_t)(_schedule_table[j] - now) > 0) continue; // scheduled for future... ignore for now
|
||||||
if (_pri_table[j] < min_pri) { // select most important priority amongst non-future entries
|
if (_pri_table[j] < min_pri) { // select most important priority amongst non-future entries
|
||||||
min_pri = _pri_table[j];
|
min_pri = _pri_table[j];
|
||||||
best_idx = j;
|
best_idx = j;
|
||||||
@@ -55,15 +55,15 @@ mesh::Packet* PacketQueue::removeByIdx(int i) {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketQueue::add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) {
|
bool PacketQueue::add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) {
|
||||||
if (_num == _size) {
|
if (_num == _size) {
|
||||||
// TODO: log "FATAL: queue is full!"
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
_table[_num] = packet;
|
_table[_num] = packet;
|
||||||
_pri_table[_num] = priority;
|
_pri_table[_num] = priority;
|
||||||
_schedule_table[_num] = scheduled_for;
|
_schedule_table[_num] = scheduled_for;
|
||||||
_num++;
|
_num++;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticPoolPacketManager::StaticPoolPacketManager(int pool_size): unused(pool_size), send_queue(pool_size), rx_queue(pool_size) {
|
StaticPoolPacketManager::StaticPoolPacketManager(int pool_size): unused(pool_size), send_queue(pool_size), rx_queue(pool_size) {
|
||||||
@@ -82,7 +82,10 @@ void StaticPoolPacketManager::free(mesh::Packet* packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StaticPoolPacketManager::queueOutbound(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) {
|
void StaticPoolPacketManager::queueOutbound(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) {
|
||||||
send_queue.add(packet, priority, scheduled_for);
|
if (!send_queue.add(packet, priority, scheduled_for)) {
|
||||||
|
MESH_DEBUG_PRINTLN("queueOutbound: send queue full, dropping packet");
|
||||||
|
free(packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh::Packet* StaticPoolPacketManager::getNextOutbound(uint32_t now) {
|
mesh::Packet* StaticPoolPacketManager::getNextOutbound(uint32_t now) {
|
||||||
@@ -106,7 +109,10 @@ mesh::Packet* StaticPoolPacketManager::removeOutboundByIdx(int i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StaticPoolPacketManager::queueInbound(mesh::Packet* packet, uint32_t scheduled_for) {
|
void StaticPoolPacketManager::queueInbound(mesh::Packet* packet, uint32_t scheduled_for) {
|
||||||
rx_queue.add(packet, 0, scheduled_for);
|
if (!rx_queue.add(packet, 0, scheduled_for)) {
|
||||||
|
MESH_DEBUG_PRINTLN("queueInbound: rx queue full, dropping packet");
|
||||||
|
free(packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mesh::Packet* StaticPoolPacketManager::getNextInbound(uint32_t now) {
|
mesh::Packet* StaticPoolPacketManager::getNextInbound(uint32_t now) {
|
||||||
return rx_queue.get(now);
|
return rx_queue.get(now);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class PacketQueue {
|
|||||||
public:
|
public:
|
||||||
PacketQueue(int max_entries);
|
PacketQueue(int max_entries);
|
||||||
mesh::Packet* get(uint32_t now);
|
mesh::Packet* get(uint32_t now);
|
||||||
void add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for);
|
bool add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for);
|
||||||
int count() const { return _num; }
|
int count() const { return _num; }
|
||||||
int countBefore(uint32_t now) const;
|
int countBefore(uint32_t now) const;
|
||||||
mesh::Packet* itemAt(int i) const { return _table[i]; }
|
mesh::Packet* itemAt(int i) const { return _table[i]; }
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "SerialBLEInterface.h"
|
#include "SerialBLEInterface.h"
|
||||||
|
#include "esp_mac.h"
|
||||||
|
|
||||||
// See the following for generating UUIDs:
|
// See the following for generating UUIDs:
|
||||||
// https://www.uuidgenerator.net/
|
// https://www.uuidgenerator.net/
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "CustomLLCC68.h"
|
#include "CustomLLCC68.h"
|
||||||
#include "RadioLibWrappers.h"
|
#include "RadioLibWrappers.h"
|
||||||
|
#include "SX126xReset.h"
|
||||||
|
|
||||||
class CustomLLCC68Wrapper : public RadioLibWrapper {
|
class CustomLLCC68Wrapper : public RadioLibWrapper {
|
||||||
public:
|
public:
|
||||||
@@ -19,4 +20,6 @@ public:
|
|||||||
int sf = ((CustomLLCC68 *)_radio)->spreadingFactor;
|
int sf = ((CustomLLCC68 *)_radio)->spreadingFactor;
|
||||||
return packetScoreInt(snr, sf, packet_len);
|
return packetScoreInt(snr, sf, packet_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void doResetAGC() override { sx126xResetAGC((SX126x *)_radio); }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ class CustomLR1110 : public LR1110 {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float getFreqMHz() const { return freqMHz; }
|
||||||
|
|
||||||
bool isReceiving() {
|
bool isReceiving() {
|
||||||
uint16_t irq = getIrqStatus();
|
uint16_t irq = getIrqStatus();
|
||||||
bool detected = ((irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID) || (irq & RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED));
|
bool detected = ((irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID) || (irq & RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED));
|
||||||
|
|||||||
@@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
#include "CustomLR1110.h"
|
#include "CustomLR1110.h"
|
||||||
#include "RadioLibWrappers.h"
|
#include "RadioLibWrappers.h"
|
||||||
|
#include "LR11x0Reset.h"
|
||||||
|
|
||||||
class CustomLR1110Wrapper : public RadioLibWrapper {
|
class CustomLR1110Wrapper : public RadioLibWrapper {
|
||||||
public:
|
public:
|
||||||
CustomLR1110Wrapper(CustomLR1110& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }
|
CustomLR1110Wrapper(CustomLR1110& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }
|
||||||
|
void doResetAGC() override { lr11x0ResetAGC((LR11x0 *)_radio, ((CustomLR1110 *)_radio)->getFreqMHz()); }
|
||||||
bool isReceivingPacket() override {
|
bool isReceivingPacket() override {
|
||||||
return ((CustomLR1110 *)_radio)->isReceiving();
|
return ((CustomLR1110 *)_radio)->isReceiving();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "CustomSTM32WLx.h"
|
#include "CustomSTM32WLx.h"
|
||||||
#include "RadioLibWrappers.h"
|
#include "RadioLibWrappers.h"
|
||||||
|
#include "SX126xReset.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
class CustomSTM32WLxWrapper : public RadioLibWrapper {
|
class CustomSTM32WLxWrapper : public RadioLibWrapper {
|
||||||
@@ -20,4 +21,6 @@ public:
|
|||||||
int sf = ((CustomSTM32WLx *)_radio)->spreadingFactor;
|
int sf = ((CustomSTM32WLx *)_radio)->spreadingFactor;
|
||||||
return packetScoreInt(snr, sf, packet_len);
|
return packetScoreInt(snr, sf, packet_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void doResetAGC() override { sx126xResetAGC((SX126x *)_radio); }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "CustomSX1262.h"
|
#include "CustomSX1262.h"
|
||||||
#include "RadioLibWrappers.h"
|
#include "RadioLibWrappers.h"
|
||||||
|
#include "SX126xReset.h"
|
||||||
|
|
||||||
class CustomSX1262Wrapper : public RadioLibWrapper {
|
class CustomSX1262Wrapper : public RadioLibWrapper {
|
||||||
public:
|
public:
|
||||||
@@ -22,4 +23,6 @@ public:
|
|||||||
virtual void powerOff() override {
|
virtual void powerOff() override {
|
||||||
((CustomSX1262 *)_radio)->sleep(false);
|
((CustomSX1262 *)_radio)->sleep(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void doResetAGC() override { sx126xResetAGC((SX126x *)_radio); }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "CustomSX1268.h"
|
#include "CustomSX1268.h"
|
||||||
#include "RadioLibWrappers.h"
|
#include "RadioLibWrappers.h"
|
||||||
|
#include "SX126xReset.h"
|
||||||
|
|
||||||
class CustomSX1268Wrapper : public RadioLibWrapper {
|
class CustomSX1268Wrapper : public RadioLibWrapper {
|
||||||
public:
|
public:
|
||||||
@@ -19,4 +20,6 @@ public:
|
|||||||
int sf = ((CustomSX1268 *)_radio)->spreadingFactor;
|
int sf = ((CustomSX1268 *)_radio)->spreadingFactor;
|
||||||
return packetScoreInt(snr, sf, packet_len);
|
return packetScoreInt(snr, sf, packet_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void doResetAGC() override { sx126xResetAGC((SX126x *)_radio); }
|
||||||
};
|
};
|
||||||
|
|||||||
21
src/helpers/radiolib/LR11x0Reset.h
Normal file
21
src/helpers/radiolib/LR11x0Reset.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <RadioLib.h>
|
||||||
|
|
||||||
|
// Full receiver reset for LR11x0-family chips (LR1110, LR1120, LR1121).
|
||||||
|
// Warm sleep powers down analog, calibrate(0x3F) refreshes all calibration blocks,
|
||||||
|
// then re-applies RX settings that calibration may reset.
|
||||||
|
inline void lr11x0ResetAGC(LR11x0* radio, float freqMHz) {
|
||||||
|
radio->sleep(true, 0);
|
||||||
|
radio->standby(RADIOLIB_LR11X0_STANDBY_RC, true);
|
||||||
|
|
||||||
|
radio->calibrate(RADIOLIB_LR11X0_CALIBRATE_ALL);
|
||||||
|
|
||||||
|
// calibrate(0x3F) defaults image calibration to 902-928MHz band.
|
||||||
|
// Re-calibrate for the actual operating frequency (band=4MHz matches RadioLib default).
|
||||||
|
radio->calibrateImageRejection(freqMHz - 4.0f, freqMHz + 4.0f);
|
||||||
|
|
||||||
|
#ifdef RX_BOOSTED_GAIN
|
||||||
|
radio->setRxBoostedGainMode(RX_BOOSTED_GAIN);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -53,13 +53,24 @@ void RadioLibWrapper::triggerNoiseFloorCalibrate(int threshold) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RadioLibWrapper::doResetAGC() {
|
||||||
|
_radio->sleep(); // warm sleep to reset analog frontend
|
||||||
|
}
|
||||||
|
|
||||||
void RadioLibWrapper::resetAGC() {
|
void RadioLibWrapper::resetAGC() {
|
||||||
// make sure we're not mid-receive of packet!
|
// make sure we're not mid-receive of packet!
|
||||||
if ((state & STATE_INT_READY) != 0 || isReceivingPacket()) return;
|
if ((state & STATE_INT_READY) != 0 || isReceivingPacket()) return;
|
||||||
|
|
||||||
// NOTE: according to higher powers, just issuing RadioLib's startReceive() will reset the AGC.
|
doResetAGC();
|
||||||
// revisit this if a better impl is discovered.
|
|
||||||
state = STATE_IDLE; // trigger a startReceive()
|
state = STATE_IDLE; // trigger a startReceive()
|
||||||
|
|
||||||
|
// Reset noise floor sampling so it reconverges from scratch.
|
||||||
|
// Without this, a stuck _noise_floor of -120 makes the sampling threshold
|
||||||
|
// too low (-106) to accept normal samples (~-105), self-reinforcing the
|
||||||
|
// stuck value even after the receiver has recovered.
|
||||||
|
_noise_floor = 0;
|
||||||
|
_num_floor_samples = 0;
|
||||||
|
_floor_sample_sum = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioLibWrapper::loop() {
|
void RadioLibWrapper::loop() {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ protected:
|
|||||||
void startRecv();
|
void startRecv();
|
||||||
float packetScoreInt(float snr, int sf, int packet_len);
|
float packetScoreInt(float snr, int sf, int packet_len);
|
||||||
virtual bool isReceivingPacket() =0;
|
virtual bool isReceivingPacket() =0;
|
||||||
|
virtual void doResetAGC();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board) { n_recv = n_sent = 0; }
|
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board) { n_recv = n_sent = 0; }
|
||||||
|
|||||||
37
src/helpers/radiolib/SX126xReset.h
Normal file
37
src/helpers/radiolib/SX126xReset.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <RadioLib.h>
|
||||||
|
|
||||||
|
// Full receiver reset for all SX126x-family chips (SX1262, SX1268, LLCC68, STM32WLx).
|
||||||
|
// Warm sleep powers down analog, Calibrate(0x7F) refreshes ADC/PLL/image calibration,
|
||||||
|
// then re-applies RX settings that calibration may reset.
|
||||||
|
inline void sx126xResetAGC(SX126x* radio) {
|
||||||
|
radio->sleep(true);
|
||||||
|
radio->standby(RADIOLIB_SX126X_STANDBY_RC, true);
|
||||||
|
|
||||||
|
uint8_t calData = RADIOLIB_SX126X_CALIBRATE_ALL;
|
||||||
|
radio->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_CALIBRATE, &calData, 1, true, false);
|
||||||
|
radio->mod->hal->delay(5);
|
||||||
|
uint32_t start = millis();
|
||||||
|
while (radio->mod->hal->digitalRead(radio->mod->getGpio())) {
|
||||||
|
if (millis() - start > 50) break;
|
||||||
|
radio->mod->hal->yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calibrate(0x7F) defaults image calibration to 902-928MHz band.
|
||||||
|
// Re-calibrate for the actual operating frequency.
|
||||||
|
radio->calibrateImage(radio->freqMHz);
|
||||||
|
|
||||||
|
#ifdef SX126X_DIO2_AS_RF_SWITCH
|
||||||
|
radio->setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
|
||||||
|
#endif
|
||||||
|
#ifdef SX126X_RX_BOOSTED_GAIN
|
||||||
|
radio->setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN);
|
||||||
|
#endif
|
||||||
|
#ifdef SX126X_REGISTER_PATCH
|
||||||
|
uint8_t r_data = 0;
|
||||||
|
radio->readRegister(0x8B5, &r_data, 1);
|
||||||
|
r_data |= 0x01;
|
||||||
|
radio->writeRegister(0x8B5, &r_data, 1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -683,7 +683,7 @@ void EnvironmentSensorManager::start_gps() {
|
|||||||
_location->begin();
|
_location->begin();
|
||||||
_location->reset();
|
_location->reset();
|
||||||
|
|
||||||
#ifndef PIN_GPS_RESET
|
#ifndef PIN_GPS_EN
|
||||||
MESH_DEBUG_PRINTLN("Start GPS is N/A on this board. Actual GPS state unchanged");
|
MESH_DEBUG_PRINTLN("Start GPS is N/A on this board. Actual GPS state unchanged");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -707,7 +707,9 @@ void EnvironmentSensorManager::loop() {
|
|||||||
static long next_gps_update = 0;
|
static long next_gps_update = 0;
|
||||||
|
|
||||||
#if ENV_INCLUDE_GPS
|
#if ENV_INCLUDE_GPS
|
||||||
_location->loop();
|
if (gps_active) {
|
||||||
|
_location->loop();
|
||||||
|
}
|
||||||
if (millis() > next_gps_update) {
|
if (millis() > next_gps_update) {
|
||||||
|
|
||||||
if(gps_active){
|
if(gps_active){
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ public :
|
|||||||
if (_pin_en != -1) {
|
if (_pin_en != -1) {
|
||||||
digitalWrite(_pin_en, !PIN_GPS_EN_ACTIVE);
|
digitalWrite(_pin_en, !PIN_GPS_EN_ACTIVE);
|
||||||
}
|
}
|
||||||
|
if (_pin_reset != -1) {
|
||||||
|
digitalWrite(_pin_reset, GPS_RESET_FORCE);
|
||||||
|
}
|
||||||
if (_peripher_power) _peripher_power->release();
|
if (_peripher_power) _peripher_power->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
# Maintenance Tools
|
|
||||||
|
|
||||||
This directory contains automation for managing our **Friendly Fork**. It allows us to integrate community-submitted Pull Requests from the upstream repository into our local development branches.
|
|
||||||
|
|
||||||
## Why this exists
|
|
||||||
|
|
||||||
In firmware development, critical bug fixes or hardware support often exist in the upstream "Pull Request" queue long before they are officially merged. This tool allows us to build an integrated firmware version that includes those necessary patches while remaining syncable with the official source.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
### 1. Prerequisites
|
|
||||||
|
|
||||||
You must have the original repository added as a remote named `upstream`:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git remote add upstream https://github.com/meshcore-dev/MeshCore.git
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Basic Commands
|
|
||||||
|
|
||||||
**Apply specific patches:**
|
|
||||||
To pull in PR #1338 and PR #1400 from the upstream project:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./tools/maint/apply_patches.sh 1338 1400
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
**Start over (Reset):**
|
|
||||||
To wipe the integrated branch and reset it to match the official upstream `main` branch exactly:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./tools/maint/apply_patches.sh --reset
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## Traceability
|
|
||||||
|
|
||||||
Every time this script runs, it updates `patch_manifest.log`. This file tracks:
|
|
||||||
|
|
||||||
* The date of the integration.
|
|
||||||
* The base commit SHA we started from.
|
|
||||||
* The specific commit SHA of every PR applied.
|
|
||||||
|
|
||||||
**This log is essential for debugging firmware regressions.** If the hardware fails, check the manifest to identify which experimental patch might be the cause.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### A Note on Merge Conflicts
|
|
||||||
|
|
||||||
If a PR cannot be applied automatically, the script will abort the merge. You will need to:
|
|
||||||
|
|
||||||
1. Manually merge the PR.
|
|
||||||
2. Resolve the conflicts in your editor.
|
|
||||||
3. Commit the result.
|
|
||||||
4. Manually update the `patch_manifest.log`.
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Configuration
|
|
||||||
UPSTREAM_REMOTE="upstream"
|
|
||||||
BASE_BRANCH="main" # Change to 'master' if that's what upstream uses
|
|
||||||
TARGET_BRANCH="main-integrated"
|
|
||||||
MANIFEST_FILE="tools/maint/patch_manifest.log"
|
|
||||||
|
|
||||||
# Function to reset the branch
|
|
||||||
reset_to_upstream() {
|
|
||||||
echo "Warning: This will wipe all local changes on $TARGET_BRANCH."
|
|
||||||
read -p "Are you sure you want to reset to $UPSTREAM_REMOTE/$BASE_BRANCH? (y/n) " -n 1 -r
|
|
||||||
echo
|
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
||||||
git fetch "$UPSTREAM_REMOTE"
|
|
||||||
git checkout -B "$TARGET_BRANCH" "$UPSTREAM_REMOTE/$BASE_BRANCH"
|
|
||||||
echo "--- Reset to Upstream: $(date) ---" > "$MANIFEST_FILE"
|
|
||||||
echo "Base Commit: $(git rev-parse HEAD)" >> "$MANIFEST_FILE"
|
|
||||||
echo "Reset successful. Branch is now clean."
|
|
||||||
else
|
|
||||||
echo "Reset aborted."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check for reset flag
|
|
||||||
if [[ "$1" == "--reset" ]]; then
|
|
||||||
reset_to_upstream
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Standard PR application logic
|
|
||||||
PR_IDS=("$@")
|
|
||||||
if [ ${#PR_IDS[@]} -eq 0 ]; then
|
|
||||||
echo "Usage:"
|
|
||||||
echo " Apply PRs: $0 <PR_ID1> <PR_ID2> ..."
|
|
||||||
echo " Reset: $0 --reset"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Ensure target branch exists and is checked out
|
|
||||||
git checkout -B "$TARGET_BRANCH"
|
|
||||||
|
|
||||||
echo "--- Patch Session: $(date) ---" >> "$MANIFEST_FILE"
|
|
||||||
|
|
||||||
for PR in "${PR_IDS[@]}"; do
|
|
||||||
echo "--------------------------------------"
|
|
||||||
echo "Fetching PR #$PR..."
|
|
||||||
|
|
||||||
if git fetch "$UPSTREAM_REMOTE" "pull/$PR/head:PR_TEMP_FETCH"; then
|
|
||||||
if git merge PR_TEMP_FETCH --no-edit -m "Integrate upstream PR #$PR"; then
|
|
||||||
echo "Successfully integrated PR #$PR"
|
|
||||||
echo "PR #$PR SHA: $(git rev-parse PR_TEMP_FETCH)" >> "$MANIFEST_FILE"
|
|
||||||
else
|
|
||||||
echo "Conflict in PR #$PR. Aborting merge."
|
|
||||||
git merge --abort
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
git branch -D PR_TEMP_FETCH
|
|
||||||
else
|
|
||||||
echo "Error: PR #$PR not found."
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "--------------------------------------"
|
|
||||||
echo "Done. See $MANIFEST_FILE for details."
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
#!/bin/bash # Note: switched to bash for process substitution support
|
|
||||||
|
|
||||||
export PATH="$HOME/.platformio/penv/bin:$PATH"
|
|
||||||
|
|
||||||
LOGFILE="$PWD/meshcore-evo-fw.log"
|
|
||||||
FIRMWARE_VERSION="v1.12.0-evo_0.1.7"
|
|
||||||
FIRMWARE_BUILD_DATE=$(date '+%d-%b-%Y')
|
|
||||||
|
|
||||||
collect_bin_files(){
|
|
||||||
DEST_DIR="./firmwares"
|
|
||||||
mkdir -p "$DEST_DIR"
|
|
||||||
BUILD_DIR=".pio/build"
|
|
||||||
|
|
||||||
if [ ! -d "$BUILD_DIR" ]; then
|
|
||||||
echo "Error: $BUILD_DIR not found. Did you run the build process?"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Copying firmware files to $DEST_DIR..."
|
|
||||||
|
|
||||||
for target_path in "$BUILD_DIR"/*/; do
|
|
||||||
echo $target_path
|
|
||||||
target_name=$(basename "$target_path")
|
|
||||||
# if ls "$target_path"*.bin >/dev/null 2>&1; then
|
|
||||||
for bin_file in "$target_path"*firmware*.{uf2,bin,zip}; do
|
|
||||||
filename=$(basename "$bin_file")
|
|
||||||
new_filename="${target_name}_${FIRMWARE_VERSION}_${FIRMWARE_BUILD_DATE}_${filename}"
|
|
||||||
cp "$bin_file" "$DEST_DIR/$new_filename"
|
|
||||||
echo "Done: $new_filename"
|
|
||||||
done
|
|
||||||
# fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Everything after this line goes to BOTH console and logfile
|
|
||||||
exec > >(tee -a "$LOGFILE") 2>&1
|
|
||||||
|
|
||||||
echo "-------------------- Build start ----------------"
|
|
||||||
date
|
|
||||||
echo "-------------------------------------------------"
|
|
||||||
|
|
||||||
# apply patches
|
|
||||||
# ./tools/maint/apply_patches.sh 1199 1338 1297
|
|
||||||
|
|
||||||
# build all repeater firmwares, the will be in .out
|
|
||||||
FIRMWARE_VERSION=$FIRMWARE_VERSION ./build.sh build-repeater-firmwares
|
|
||||||
|
|
||||||
# build single firmwares
|
|
||||||
#FIRMWARE_VERSION=$FIRMWARE_VERSION FIRMWARE_BUILD_DATE=$FIRMWARE_BUILD_DATE ./build.sh build-firmware ProMicro_repeater
|
|
||||||
#FIRMWARE_VERSION=$FIRMWARE_VERSION FIRMWARE_BUILD_DATE=$FIRMWARE_BUILD_DATE ./build.sh build-firmware RAK_4631_repeater
|
|
||||||
#FIRMWARE_VERSION=$FIRMWARE_VERSION FIRMWARE_BUILD_DATE=$FIRMWARE_BUILD_DATE ./build.sh build-firmware heltec_v4_repeater
|
|
||||||
#FIRMWARE_VERSION=$FIRMWARE_VERSION FIRMWARE_BUILD_DATE=$FIRMWARE_BUILD_DATE ./build.sh build-firmware Heltec_v3_repeater
|
|
||||||
#FIRMWARE_VERSION=$FIRMWARE_VERSION FIRMWARE_BUILD_DATE=$FIRMWARE_BUILD_DATE ./build.sh build-firmware Xiao_nrf52_repeater
|
|
||||||
#FIRMWARE_VERSION=$FIRMWARE_VERSION FIRMWARE_BUILD_DATE=$FIRMWARE_BUILD_DATE ./build.sh build-firmware LilyGo_T3S3_sx1262_repeater
|
|
||||||
#FIRMWARE_VERSION=$FIRMWARE_VERSION FIRMWARE_BUILD_DATE=$FIRMWARE_BUILD_DATE ./build.sh build-firmware Heltec_t114_without_display_repeater
|
|
||||||
#FIRMWARE_VERSION=$FIRMWARE_VERSION FIRMWARE_BUILD_DATE=$FIRMWARE_BUILD_DATE ./build.sh build-firmware Heltec_t114_repeater
|
|
||||||
#collect_bin_files
|
|
||||||
|
|
||||||
|
|
||||||
echo "-------------------- Build end ------------------"
|
|
||||||
date
|
|
||||||
echo "-------------------------------------------------"
|
|
||||||
|
|
||||||
#grep -E " SUCCESS | FAILED " hansemesh_fw.log
|
|
||||||
@@ -32,6 +32,11 @@ build_flags =
|
|||||||
-D PIN_TFT_LEDA_CTL=21 ; LEDK (switches on/off via mosfet to create the ground)
|
-D PIN_TFT_LEDA_CTL=21 ; LEDK (switches on/off via mosfet to create the ground)
|
||||||
-D PIN_GPS_RX=33
|
-D PIN_GPS_RX=33
|
||||||
-D PIN_GPS_TX=34
|
-D PIN_GPS_TX=34
|
||||||
|
-D PIN_GPS_EN=35 ; N-ch MOSFET Q2 drives P-ch high-side switch → active HIGH (default)
|
||||||
|
-D PIN_GPS_RESET=36
|
||||||
|
-D PIN_GPS_RESET_ACTIVE=LOW
|
||||||
|
-D GPS_BAUD_RATE=115200
|
||||||
|
-D ENV_INCLUDE_GPS=1
|
||||||
-D SX126X_DIO2_AS_RF_SWITCH=true
|
-D SX126X_DIO2_AS_RF_SWITCH=true
|
||||||
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
||||||
-D SX126X_CURRENT_LIMIT=140
|
-D SX126X_CURRENT_LIMIT=140
|
||||||
@@ -43,6 +48,31 @@ lib_deps =
|
|||||||
stevemarple/MicroNMEA @ ^2.0.6
|
stevemarple/MicroNMEA @ ^2.0.6
|
||||||
adafruit/Adafruit ST7735 and ST7789 Library @ ^1.11.0
|
adafruit/Adafruit ST7735 and ST7789 Library @ ^1.11.0
|
||||||
|
|
||||||
|
[env:Heltec_Wireless_Tracker_companion_radio_usb]
|
||||||
|
extends = Heltec_tracker_base
|
||||||
|
build_flags =
|
||||||
|
${Heltec_tracker_base.build_flags}
|
||||||
|
-I src/helpers/ui
|
||||||
|
-I examples/companion_radio/ui-new
|
||||||
|
-D DISPLAY_ROTATION=1
|
||||||
|
-D DISPLAY_CLASS=ST7735Display
|
||||||
|
-D MAX_CONTACTS=350
|
||||||
|
-D MAX_GROUP_CHANNELS=40
|
||||||
|
; -D BLE_PIN_CODE=123456 ; HWT will use display for pin
|
||||||
|
; -D OFFLINE_QUEUE_SIZE=256
|
||||||
|
; -D BLE_DEBUG_LOGGING=1
|
||||||
|
; -D MESH_PACKET_LOGGING=1
|
||||||
|
; -D MESH_DEBUG=1
|
||||||
|
build_src_filter = ${Heltec_tracker_base.build_src_filter}
|
||||||
|
+<helpers/esp32/*.cpp>
|
||||||
|
+<helpers/ui/MomentaryButton.cpp>
|
||||||
|
+<../examples/companion_radio/*.cpp>
|
||||||
|
+<../examples/companion_radio/ui-new/*.cpp>
|
||||||
|
+<helpers/ui/ST7735Display.cpp>
|
||||||
|
lib_deps =
|
||||||
|
${Heltec_tracker_base.lib_deps}
|
||||||
|
densaugeo/base64 @ ~1.4.0
|
||||||
|
|
||||||
[env:Heltec_Wireless_Tracker_companion_radio_ble]
|
[env:Heltec_Wireless_Tracker_companion_radio_ble]
|
||||||
extends = Heltec_tracker_base
|
extends = Heltec_tracker_base
|
||||||
build_flags =
|
build_flags =
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ WRAPPER_CLASS radio_driver(radio, board);
|
|||||||
|
|
||||||
ESP32RTCClock fallback_clock;
|
ESP32RTCClock fallback_clock;
|
||||||
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||||
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
|
// GPS_EN (GPIO35) drives N-ch MOSFET → P-ch high-side switch; GPS_RESET (GPIO36) active LOW
|
||||||
|
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock, GPS_RESET, GPS_EN, &board.periph_power);
|
||||||
HWTSensorManager sensors = HWTSensorManager(nmea);
|
HWTSensorManager sensors = HWTSensorManager(nmea);
|
||||||
|
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
@@ -58,18 +59,16 @@ mesh::LocalIdentity radio_new_identity() {
|
|||||||
|
|
||||||
void HWTSensorManager::start_gps() {
|
void HWTSensorManager::start_gps() {
|
||||||
if (!gps_active) {
|
if (!gps_active) {
|
||||||
board.periph_power.claim();
|
_location->begin(); // Claims periph_power via RefCountedDigitalPin
|
||||||
|
|
||||||
gps_active = true;
|
gps_active = true;
|
||||||
Serial1.println("$CFGSYS,h35155*68");
|
Serial1.println("$CFGSYS,h35155*68"); // Configure GPS for all constellations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HWTSensorManager::stop_gps() {
|
void HWTSensorManager::stop_gps() {
|
||||||
if (gps_active) {
|
if (gps_active) {
|
||||||
gps_active = false;
|
gps_active = false;
|
||||||
|
_location->stop(); // Releases periph_power via RefCountedDigitalPin
|
||||||
board.periph_power.release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public:
|
|||||||
const char* getSettingName(int i) const override;
|
const char* getSettingName(int i) const override;
|
||||||
const char* getSettingValue(int i) const override;
|
const char* getSettingValue(int i) const override;
|
||||||
bool setSettingValue(const char* name, const char* value) override;
|
bool setSettingValue(const char* name, const char* value) override;
|
||||||
|
LocationProvider* getLocationProvider() override { return _location; }
|
||||||
};
|
};
|
||||||
|
|
||||||
extern HeltecV3Board board;
|
extern HeltecV3Board board;
|
||||||
|
|||||||
@@ -6,18 +6,26 @@ void HeltecTrackerV2Board::begin() {
|
|||||||
pinMode(PIN_ADC_CTRL, OUTPUT);
|
pinMode(PIN_ADC_CTRL, OUTPUT);
|
||||||
digitalWrite(PIN_ADC_CTRL, LOW); // Initially inactive
|
digitalWrite(PIN_ADC_CTRL, LOW); // Initially inactive
|
||||||
|
|
||||||
|
// Set up digital GPIO registers before releasing RTC hold. The hold latches
|
||||||
|
// the pad state including function select, so register writes accumulate
|
||||||
|
// without affecting the pad. On hold release, all changes apply atomically
|
||||||
|
// (IO MUX switches to digital GPIO with output already HIGH — no glitch).
|
||||||
pinMode(P_LORA_PA_POWER, OUTPUT);
|
pinMode(P_LORA_PA_POWER, OUTPUT);
|
||||||
digitalWrite(P_LORA_PA_POWER,HIGH);
|
digitalWrite(P_LORA_PA_POWER,HIGH);
|
||||||
|
rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_POWER);
|
||||||
|
|
||||||
rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_EN);
|
|
||||||
pinMode(P_LORA_PA_EN, OUTPUT);
|
pinMode(P_LORA_PA_EN, OUTPUT);
|
||||||
digitalWrite(P_LORA_PA_EN,HIGH);
|
digitalWrite(P_LORA_PA_EN,HIGH);
|
||||||
|
rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_EN);
|
||||||
pinMode(P_LORA_PA_TX_EN, OUTPUT);
|
pinMode(P_LORA_PA_TX_EN, OUTPUT);
|
||||||
digitalWrite(P_LORA_PA_TX_EN,LOW);
|
digitalWrite(P_LORA_PA_TX_EN,LOW);
|
||||||
|
|
||||||
periph_power.begin();
|
|
||||||
|
|
||||||
esp_reset_reason_t reason = esp_reset_reason();
|
esp_reset_reason_t reason = esp_reset_reason();
|
||||||
|
if (reason != ESP_RST_DEEPSLEEP) {
|
||||||
|
delay(1); // GC1109 startup time after cold power-on
|
||||||
|
}
|
||||||
|
|
||||||
|
periph_power.begin();
|
||||||
if (reason == ESP_RST_DEEPSLEEP) {
|
if (reason == ESP_RST_DEEPSLEEP) {
|
||||||
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
||||||
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
|
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
|
||||||
@@ -48,7 +56,9 @@ void HeltecTrackerV2Board::begin() {
|
|||||||
|
|
||||||
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
|
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
|
||||||
|
|
||||||
rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_EN); //It also needs to be enabled in receive mode
|
// Hold GC1109 FEM pins during sleep to keep LNA active for RX wake
|
||||||
|
rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_POWER);
|
||||||
|
rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_EN);
|
||||||
|
|
||||||
if (pin_wake_btn < 0) {
|
if (pin_wake_btn < 0) {
|
||||||
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
|
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
|
||||||
|
|||||||
@@ -17,15 +17,16 @@ build_flags =
|
|||||||
-D P_LORA_SCLK=9
|
-D P_LORA_SCLK=9
|
||||||
-D P_LORA_MISO=11
|
-D P_LORA_MISO=11
|
||||||
-D P_LORA_MOSI=10
|
-D P_LORA_MOSI=10
|
||||||
-D P_LORA_PA_POWER=7 ;power en
|
-D P_LORA_PA_POWER=7 ; VFEM_Ctrl - GC1109 LDO power enable
|
||||||
-D P_LORA_PA_EN=4
|
-D P_LORA_PA_EN=4 ; CSD - GC1109 chip enable (HIGH=on)
|
||||||
-D P_LORA_PA_TX_EN=46 ;enable tx
|
-D P_LORA_PA_TX_EN=46 ; CPS - GC1109 PA mode (HIGH=full PA, LOW=bypass)
|
||||||
-D LORA_TX_POWER=10 ;If it is configured as 10 here, the final output will be 22 dbm.
|
-D LORA_TX_POWER=10 ; 10dBm + ~11dB GC1109 gain = ~21dBm output
|
||||||
-D MAX_LORA_TX_POWER=22 ;Max SX1262 output
|
-D MAX_LORA_TX_POWER=22 ; Max SX1262 output -> ~28dBm at antenna
|
||||||
-D SX126X_DIO2_AS_RF_SWITCH=true
|
-D SX126X_DIO2_AS_RF_SWITCH=true
|
||||||
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
||||||
-D SX126X_CURRENT_LIMIT=140
|
-D SX126X_CURRENT_LIMIT=140
|
||||||
-D SX126X_RX_BOOSTED_GAIN=1
|
-D SX126X_RX_BOOSTED_GAIN=1
|
||||||
|
-D SX126X_REGISTER_PATCH=1
|
||||||
-D PIN_BOARD_SDA=5
|
-D PIN_BOARD_SDA=5
|
||||||
-D PIN_BOARD_SCL=6
|
-D PIN_BOARD_SCL=6
|
||||||
-D PIN_USER_BTN=0
|
-D PIN_USER_BTN=0
|
||||||
|
|||||||
@@ -7,19 +7,26 @@ void HeltecV4Board::begin() {
|
|||||||
pinMode(PIN_ADC_CTRL, OUTPUT);
|
pinMode(PIN_ADC_CTRL, OUTPUT);
|
||||||
digitalWrite(PIN_ADC_CTRL, LOW); // Initially inactive
|
digitalWrite(PIN_ADC_CTRL, LOW); // Initially inactive
|
||||||
|
|
||||||
|
// Set up digital GPIO registers before releasing RTC hold. The hold latches
|
||||||
|
// the pad state including function select, so register writes accumulate
|
||||||
|
// without affecting the pad. On hold release, all changes apply atomically
|
||||||
|
// (IO MUX switches to digital GPIO with output already HIGH — no glitch).
|
||||||
pinMode(P_LORA_PA_POWER, OUTPUT);
|
pinMode(P_LORA_PA_POWER, OUTPUT);
|
||||||
digitalWrite(P_LORA_PA_POWER,HIGH);
|
digitalWrite(P_LORA_PA_POWER,HIGH);
|
||||||
|
rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_POWER);
|
||||||
|
|
||||||
rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_EN);
|
|
||||||
pinMode(P_LORA_PA_EN, OUTPUT);
|
pinMode(P_LORA_PA_EN, OUTPUT);
|
||||||
digitalWrite(P_LORA_PA_EN,HIGH);
|
digitalWrite(P_LORA_PA_EN,HIGH);
|
||||||
|
rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_EN);
|
||||||
pinMode(P_LORA_PA_TX_EN, OUTPUT);
|
pinMode(P_LORA_PA_TX_EN, OUTPUT);
|
||||||
digitalWrite(P_LORA_PA_TX_EN,LOW);
|
digitalWrite(P_LORA_PA_TX_EN,LOW);
|
||||||
|
|
||||||
|
esp_reset_reason_t reason = esp_reset_reason();
|
||||||
|
if (reason != ESP_RST_DEEPSLEEP) {
|
||||||
|
delay(1); // GC1109 startup time after cold power-on
|
||||||
|
}
|
||||||
|
|
||||||
periph_power.begin();
|
periph_power.begin();
|
||||||
|
|
||||||
esp_reset_reason_t reason = esp_reset_reason();
|
|
||||||
if (reason == ESP_RST_DEEPSLEEP) {
|
if (reason == ESP_RST_DEEPSLEEP) {
|
||||||
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
||||||
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
|
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
|
||||||
@@ -50,7 +57,9 @@ void HeltecV4Board::begin() {
|
|||||||
|
|
||||||
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
|
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
|
||||||
|
|
||||||
rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_EN); //It also needs to be enabled in receive mode
|
// Hold GC1109 FEM pins during sleep to keep LNA active for RX wake
|
||||||
|
rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_POWER);
|
||||||
|
rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_EN);
|
||||||
|
|
||||||
if (pin_wake_btn < 0) {
|
if (pin_wake_btn < 0) {
|
||||||
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
|
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ build_flags =
|
|||||||
-D P_LORA_PA_TX_EN=46 ; PA CPS - GC1109 TX PA full(High) / bypass(Low)
|
-D P_LORA_PA_TX_EN=46 ; PA CPS - GC1109 TX PA full(High) / bypass(Low)
|
||||||
-D PIN_USER_BTN=0
|
-D PIN_USER_BTN=0
|
||||||
-D PIN_VEXT_EN=36
|
-D PIN_VEXT_EN=36
|
||||||
-D PIN_VEXT_EN_ACTIVE=LOW
|
-D PIN_VEXT_EN_ACTIVE=HIGH
|
||||||
-D LORA_TX_POWER=10 ;If it is configured as 10 here, the final output will be 22 dbm.
|
-D LORA_TX_POWER=10 ;If it is configured as 10 here, the final output will be 22 dbm.
|
||||||
-D MAX_LORA_TX_POWER=22 ; Max SX1262 output
|
-D MAX_LORA_TX_POWER=22 ; Max SX1262 output
|
||||||
-D SX126X_REGISTER_PATCH=1 ; Patch register 0x8B5 for improved RX
|
-D SX126X_REGISTER_PATCH=1 ; Patch register 0x8B5 for improved RX
|
||||||
@@ -54,8 +54,6 @@ build_flags =
|
|||||||
-D PIN_BOARD_SDA=17
|
-D PIN_BOARD_SDA=17
|
||||||
-D PIN_BOARD_SCL=18
|
-D PIN_BOARD_SCL=18
|
||||||
-D PIN_OLED_RESET=21
|
-D PIN_OLED_RESET=21
|
||||||
-D ENV_PIN_SDA=4
|
|
||||||
-D ENV_PIN_SCL=3
|
|
||||||
build_src_filter= ${Heltec_lora32_v4.build_src_filter}
|
build_src_filter= ${Heltec_lora32_v4.build_src_filter}
|
||||||
lib_deps = ${Heltec_lora32_v4.lib_deps}
|
lib_deps = ${Heltec_lora32_v4.lib_deps}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
DISPLAY_CLASS display(&(board.periph_power));
|
DISPLAY_CLASS display(NULL);
|
||||||
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
|
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
[ikoka_handheld_nrf]
|
[ikoka_handheld_nrf]
|
||||||
extends = nrf52_base
|
extends = nrf52_base
|
||||||
|
board = seeed-xiao-afruitnrf52-nrf52840
|
||||||
|
board_build.ldscript = boards/nrf52840_s140_v7.ld
|
||||||
build_flags = ${nrf52_base.build_flags}
|
build_flags = ${nrf52_base.build_flags}
|
||||||
${sensor_base.build_flags}
|
${sensor_base.build_flags}
|
||||||
-I lib/nrf52/s140_nrf52_7.3.0_API/include
|
-I lib/nrf52/s140_nrf52_7.3.0_API/include
|
||||||
@@ -48,7 +50,8 @@ build_src_filter = ${ikoka_handheld_nrf.build_src_filter}
|
|||||||
+<../examples/companion_radio/*.cpp>
|
+<../examples/companion_radio/*.cpp>
|
||||||
|
|
||||||
[env:ikoka_handheld_nrf_e22_30dbm_096_companion_radio_ble]
|
[env:ikoka_handheld_nrf_e22_30dbm_096_companion_radio_ble]
|
||||||
extends = ikoka_nrf52
|
extends = ikoka_handheld_nrf
|
||||||
|
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
|
||||||
build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags}
|
build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags}
|
||||||
-D BLE_PIN_CODE=123456
|
-D BLE_PIN_CODE=123456
|
||||||
-D LORA_TX_POWER=20
|
-D LORA_TX_POWER=20
|
||||||
@@ -56,7 +59,8 @@ build_src_filter = ${ikoka_handheld_nrf_ssd1306_companion.build_src_filter}
|
|||||||
+<helpers/nrf52/SerialBLEInterface.cpp>
|
+<helpers/nrf52/SerialBLEInterface.cpp>
|
||||||
|
|
||||||
[env:ikoka_handheld_nrf_e22_30dbm_096_rotated_companion_radio_ble]
|
[env:ikoka_handheld_nrf_e22_30dbm_096_rotated_companion_radio_ble]
|
||||||
extends = ikoka_nrf52
|
extends = ikoka_handheld_nrf
|
||||||
|
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
|
||||||
build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags}
|
build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags}
|
||||||
-D BLE_PIN_CODE=123456
|
-D BLE_PIN_CODE=123456
|
||||||
-D LORA_TX_POWER=20
|
-D LORA_TX_POWER=20
|
||||||
@@ -65,20 +69,22 @@ build_src_filter = ${ikoka_handheld_nrf_ssd1306_companion.build_src_filter}
|
|||||||
+<helpers/nrf52/SerialBLEInterface.cpp>
|
+<helpers/nrf52/SerialBLEInterface.cpp>
|
||||||
|
|
||||||
[env:ikoka_handheld_nrf_e22_30dbm_096_companion_radio_usb]
|
[env:ikoka_handheld_nrf_e22_30dbm_096_companion_radio_usb]
|
||||||
extends = ikoka_nrf52
|
extends = ikoka_handheld_nrf
|
||||||
|
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
|
||||||
build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags}
|
build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags}
|
||||||
-D LORA_TX_POWER=20
|
-D LORA_TX_POWER=20
|
||||||
build_src_filter = ${ikoka_handheld_nrf_ssd1306_companion.build_src_filter}
|
build_src_filter = ${ikoka_handheld_nrf_ssd1306_companion.build_src_filter}
|
||||||
|
|
||||||
[env:ikoka_handheld_nrf_e22_30dbm_096_rotated_companion_radio_usb]
|
[env:ikoka_handheld_nrf_e22_30dbm_096_rotated_companion_radio_usb]
|
||||||
extends = ikoka_nrf52
|
extends = ikoka_handheld_nrf
|
||||||
|
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
|
||||||
build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags}
|
build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags}
|
||||||
-D LORA_TX_POWER=20
|
-D LORA_TX_POWER=20
|
||||||
-D DISPLAY_ROTATION=2
|
-D DISPLAY_ROTATION=2
|
||||||
build_src_filter = ${ikoka_handheld_nrf_ssd1306_companion.build_src_filter}
|
build_src_filter = ${ikoka_handheld_nrf_ssd1306_companion.build_src_filter}
|
||||||
|
|
||||||
[env:ikoka_handheld_nrf_e22_30dbm_repeater]
|
[env:ikoka_handheld_nrf_e22_30dbm_repeater]
|
||||||
extends = ikoka_nrf52
|
extends = ikoka_handheld_nrf
|
||||||
build_flags =
|
build_flags =
|
||||||
${ikoka_handheld_nrf.build_flags}
|
${ikoka_handheld_nrf.build_flags}
|
||||||
-D ADVERT_NAME='"ikoka_handheld Repeater"'
|
-D ADVERT_NAME='"ikoka_handheld Repeater"'
|
||||||
@@ -91,7 +97,7 @@ build_src_filter = ${ikoka_handheld_nrf.build_src_filter}
|
|||||||
+<../examples/simple_repeater/*.cpp>
|
+<../examples/simple_repeater/*.cpp>
|
||||||
|
|
||||||
[env:ikoka_handheld_nrf_e22_30dbm_room_server]
|
[env:ikoka_handheld_nrf_e22_30dbm_room_server]
|
||||||
extends = ikoka_nrf52
|
extends = ikoka_handheld_nrf
|
||||||
build_flags =
|
build_flags =
|
||||||
${ikoka_handheld_nrf.build_flags}
|
${ikoka_handheld_nrf.build_flags}
|
||||||
-D ADVERT_NAME='"ikoka_handheld Room"'
|
-D ADVERT_NAME='"ikoka_handheld Room"'
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ build_src_filter = ${esp32_base.build_src_filter}
|
|||||||
+<helpers/ui/SH1106Display.cpp>
|
+<helpers/ui/SH1106Display.cpp>
|
||||||
+<helpers/esp32/TBeamBoard.cpp>
|
+<helpers/esp32/TBeamBoard.cpp>
|
||||||
+<helpers/sensors>
|
+<helpers/sensors>
|
||||||
board_build.partitions = min_spiffs.csv ; get around 4mb flash limit
|
board_build.partitions = default_8MB.csv
|
||||||
|
board_upload.flash_size = 8MB
|
||||||
|
board_upload.maximum_size = 8388608
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${esp32_base.lib_deps}
|
${esp32_base.lib_deps}
|
||||||
lewisxhe/XPowersLib @ ^0.2.7
|
lewisxhe/XPowersLib @ ^0.2.7
|
||||||
@@ -131,3 +133,27 @@ build_src_filter = ${T_Beam_S3_Supreme_SX1262.build_src_filter}
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
${T_Beam_S3_Supreme_SX1262.lib_deps}
|
${T_Beam_S3_Supreme_SX1262.lib_deps}
|
||||||
densaugeo/base64 @ ~1.4.0
|
densaugeo/base64 @ ~1.4.0
|
||||||
|
|
||||||
|
[env:T_Beam_S3_Supreme_SX1262_companion_radio_wifi]
|
||||||
|
extends = T_Beam_S3_Supreme_SX1262
|
||||||
|
build_flags =
|
||||||
|
${T_Beam_S3_Supreme_SX1262.build_flags}
|
||||||
|
-I examples/companion_radio/ui-new
|
||||||
|
-D MAX_CONTACTS=350
|
||||||
|
-D MAX_GROUP_CHANNELS=40
|
||||||
|
-D OFFLINE_QUEUE_SIZE=256
|
||||||
|
-D WIFI_SSID='"WIFI_SSID"'
|
||||||
|
-D WIFI_PWD='"Password"'
|
||||||
|
; -D WIFI_DEBUG_LOGGING=1
|
||||||
|
; -D MESH_PACKET_LOGGING=8
|
||||||
|
; -D MESH_DEBUG=1
|
||||||
|
; -D ARDUHAL_LOG_LEVEL=4
|
||||||
|
; -D CORE_DEBUG_LEVEL=4
|
||||||
|
build_src_filter = ${T_Beam_S3_Supreme_SX1262.build_src_filter}
|
||||||
|
+<helpers/esp32/*.cpp>
|
||||||
|
+<helpers/ui/MomentaryButton.cpp>
|
||||||
|
+<../examples/companion_radio/*.cpp>
|
||||||
|
+<../examples/companion_radio/ui-new/*.cpp>
|
||||||
|
lib_deps =
|
||||||
|
${T_Beam_S3_Supreme_SX1262.lib_deps}
|
||||||
|
densaugeo/base64 @ ~1.4.0
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ build_flags =
|
|||||||
-D P_LORA_SCLK=5 ; SPI clock
|
-D P_LORA_SCLK=5 ; SPI clock
|
||||||
-D P_LORA_MISO=19 ; SPI MISO
|
-D P_LORA_MISO=19 ; SPI MISO
|
||||||
-D P_LORA_MOSI=27 ; SPI MOSI
|
-D P_LORA_MOSI=27 ; SPI MOSI
|
||||||
-D P_LORA_TX_LED=2 ; LED pin for TX indication
|
-D P_LORA_TX_LED=25 ; LED pin for TX indication
|
||||||
-D PIN_BOARD_SDA=21
|
-D PIN_BOARD_SDA=21
|
||||||
-D PIN_BOARD_SCL=22
|
-D PIN_BOARD_SCL=22
|
||||||
-D PIN_VBAT_READ=35 ; Battery voltage reading (analog pin)
|
-D PIN_VBAT_READ=35 ; Battery voltage reading (analog pin)
|
||||||
@@ -65,7 +65,7 @@ build_flags =
|
|||||||
; -D MESH_PACKET_LOGGING=1
|
; -D MESH_PACKET_LOGGING=1
|
||||||
; -D MESH_DEBUG=1
|
; -D MESH_DEBUG=1
|
||||||
build_src_filter = ${LilyGo_TLora_V2_1_1_6.build_src_filter}
|
build_src_filter = ${LilyGo_TLora_V2_1_1_6.build_src_filter}
|
||||||
+<../examples/simple_repeater>
|
+<../examples/simple_secure_chat/main.cpp>
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${LilyGo_TLora_V2_1_1_6.lib_deps}
|
${LilyGo_TLora_V2_1_1_6.lib_deps}
|
||||||
densaugeo/base64 @ ~1.4.0
|
densaugeo/base64 @ ~1.4.0
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ board_build.partitions = min_spiffs.csv ; get around 4mb flash limit
|
|||||||
build_flags =
|
build_flags =
|
||||||
${esp32c6_base.build_flags}
|
${esp32c6_base.build_flags}
|
||||||
${sensor_base.build_flags}
|
${sensor_base.build_flags}
|
||||||
-I variants/M5Stack_Unit_C6L
|
-I variants/m5stack_unit_c6l
|
||||||
-D P_LORA_TX_LED=15
|
-D P_LORA_TX_LED=15
|
||||||
-D P_LORA_SCLK=20
|
-D P_LORA_SCLK=20
|
||||||
-D P_LORA_MISO=22
|
-D P_LORA_MISO=22
|
||||||
@@ -94,6 +94,8 @@ build_flags = ${M5Stack_Unit_C6L.build_flags}
|
|||||||
-D MAX_CONTACTS=350
|
-D MAX_CONTACTS=350
|
||||||
-D MAX_GROUP_CHANNELS=40
|
-D MAX_GROUP_CHANNELS=40
|
||||||
-D OFFLINE_QUEUE_SIZE=256
|
-D OFFLINE_QUEUE_SIZE=256
|
||||||
|
-D ARDUINO_USB_CDC_ON_BOOT=1
|
||||||
|
-D ARDUINO_USB_MODE=1
|
||||||
build_src_filter = ${M5Stack_Unit_C6L.build_src_filter}
|
build_src_filter = ${M5Stack_Unit_C6L.build_src_filter}
|
||||||
+<helpers/esp32/*.cpp>
|
+<helpers/esp32/*.cpp>
|
||||||
-<helpers/esp32/ESPNOWRadio.cpp>
|
-<helpers/esp32/ESPNOWRadio.cpp>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ build_flags =
|
|||||||
-I variants/rak3112
|
-I variants/rak3112
|
||||||
-D RAK_3112=1
|
-D RAK_3112=1
|
||||||
-D ESP32_CPU_FREQ=80
|
-D ESP32_CPU_FREQ=80
|
||||||
|
-D ARDUINO_USB_CDC_ON_BOOT=1
|
||||||
-D P_LORA_DIO_1=47
|
-D P_LORA_DIO_1=47
|
||||||
-D P_LORA_NSS=7
|
-D P_LORA_NSS=7
|
||||||
-D P_LORA_RESET=8
|
-D P_LORA_RESET=8
|
||||||
@@ -131,14 +132,14 @@ lib_deps =
|
|||||||
extends = rak3112
|
extends = rak3112
|
||||||
build_flags =
|
build_flags =
|
||||||
${rak3112.build_flags}
|
${rak3112.build_flags}
|
||||||
-I examples/companion_radio/ui-new
|
-I examples/companion_radio/ui-orig
|
||||||
-D MAX_CONTACTS=350
|
-D MAX_CONTACTS=350
|
||||||
-D MAX_GROUP_CHANNELS=40
|
-D MAX_GROUP_CHANNELS=40
|
||||||
; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1
|
; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1
|
||||||
; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1
|
; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1
|
||||||
build_src_filter = ${rak3112.build_src_filter}
|
build_src_filter = ${rak3112.build_src_filter}
|
||||||
+<../examples/companion_radio/*.cpp>
|
+<../examples/companion_radio/*.cpp>
|
||||||
+<../examples/companion_radio/ui-new/*.cpp>
|
+<../examples/companion_radio/ui-orig/*.cpp>
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${rak3112.lib_deps}
|
${rak3112.lib_deps}
|
||||||
densaugeo/base64 @ ~1.4.0
|
densaugeo/base64 @ ~1.4.0
|
||||||
@@ -147,7 +148,7 @@ lib_deps =
|
|||||||
extends = rak3112
|
extends = rak3112
|
||||||
build_flags =
|
build_flags =
|
||||||
${rak3112.build_flags}
|
${rak3112.build_flags}
|
||||||
-I examples/companion_radio/ui-new
|
-I examples/companion_radio/ui-orig
|
||||||
-D MAX_CONTACTS=350
|
-D MAX_CONTACTS=350
|
||||||
-D MAX_GROUP_CHANNELS=40
|
-D MAX_GROUP_CHANNELS=40
|
||||||
-D BLE_PIN_CODE=123456 ; dynamic, random PIN
|
-D BLE_PIN_CODE=123456 ; dynamic, random PIN
|
||||||
@@ -159,7 +160,7 @@ build_flags =
|
|||||||
build_src_filter = ${rak3112.build_src_filter}
|
build_src_filter = ${rak3112.build_src_filter}
|
||||||
+<helpers/esp32/*.cpp>
|
+<helpers/esp32/*.cpp>
|
||||||
+<../examples/companion_radio/*.cpp>
|
+<../examples/companion_radio/*.cpp>
|
||||||
+<../examples/companion_radio/ui-new/*.cpp>
|
+<../examples/companion_radio/ui-orig/*.cpp>
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${rak3112.lib_deps}
|
${rak3112.lib_deps}
|
||||||
densaugeo/base64 @ ~1.4.0
|
densaugeo/base64 @ ~1.4.0
|
||||||
@@ -168,7 +169,7 @@ lib_deps =
|
|||||||
extends = rak3112
|
extends = rak3112
|
||||||
build_flags =
|
build_flags =
|
||||||
${rak3112.build_flags}
|
${rak3112.build_flags}
|
||||||
-I examples/companion_radio/ui-new
|
-I examples/companion_radio/ui-orig
|
||||||
-D MAX_CONTACTS=350
|
-D MAX_CONTACTS=350
|
||||||
-D MAX_GROUP_CHANNELS=40
|
-D MAX_GROUP_CHANNELS=40
|
||||||
-D WIFI_DEBUG_LOGGING=1
|
-D WIFI_DEBUG_LOGGING=1
|
||||||
@@ -180,7 +181,7 @@ build_flags =
|
|||||||
build_src_filter = ${rak3112.build_src_filter}
|
build_src_filter = ${rak3112.build_src_filter}
|
||||||
+<helpers/esp32/*.cpp>
|
+<helpers/esp32/*.cpp>
|
||||||
+<../examples/companion_radio/*.cpp>
|
+<../examples/companion_radio/*.cpp>
|
||||||
+<../examples/companion_radio/ui-new/*.cpp>
|
+<../examples/companion_radio/ui-orig/*.cpp>
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${rak3112.lib_deps}
|
${rak3112.lib_deps}
|
||||||
densaugeo/base64 @ ~1.4.0
|
densaugeo/base64 @ ~1.4.0
|
||||||
|
|||||||
@@ -20,13 +20,29 @@ void RAK3401Board::begin() {
|
|||||||
|
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
|
// PIN_3V3_EN (WB_IO2, P0.34) controls the 3V3_S switched peripheral rail
|
||||||
|
// AND the 5V boost regulator (U5) on the RAK13302 that powers the SKY66122 PA.
|
||||||
|
// Must stay HIGH during radio operation — do not toggle for power saving.
|
||||||
pinMode(PIN_3V3_EN, OUTPUT);
|
pinMode(PIN_3V3_EN, OUTPUT);
|
||||||
digitalWrite(PIN_3V3_EN, HIGH);
|
digitalWrite(PIN_3V3_EN, HIGH);
|
||||||
|
|
||||||
#ifdef P_LORA_PA_EN
|
// Enable SKY66122-11 FEM on the RAK13302 module.
|
||||||
// Initialize RAK13302 1W LoRa transceiver module PA control pin
|
// CSD and CPS are tied together on the RAK13302 PCB, routed to IO3 (P0.21).
|
||||||
pinMode(P_LORA_PA_EN, OUTPUT);
|
// HIGH = FEM active (LNA for RX, PA path available for TX).
|
||||||
digitalWrite(P_LORA_PA_EN, LOW); // Start with PA disabled
|
// TX/RX switching (CTX) is handled by SX1262 DIO2 via SetDIO2AsRfSwitchCtrl.
|
||||||
delay(10); // Allow PA module to initialize
|
pinMode(SX126X_POWER_EN, OUTPUT);
|
||||||
#endif
|
digitalWrite(SX126X_POWER_EN, HIGH);
|
||||||
|
delay(1); // SKY66122 turn-on settling time (tON = 3us typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NRF52_POWER_MANAGEMENT
|
||||||
|
void RAK3401Board::initiateShutdown(uint8_t reason) {
|
||||||
|
// Disable SKY66122 FEM (CSD+CPS LOW = shutdown, <1 uA)
|
||||||
|
digitalWrite(SX126X_POWER_EN, LOW);
|
||||||
|
|
||||||
|
// Disable 3V3 switched peripherals and 5V boost
|
||||||
|
digitalWrite(PIN_3V3_EN, LOW);
|
||||||
|
|
||||||
|
enterSystemOff(reason);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -38,13 +38,6 @@ public:
|
|||||||
return "RAK 3401";
|
return "RAK 3401";
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef P_LORA_PA_EN
|
// TX/RX switching is handled by SX1262 DIO2 -> SKY66122 CTX (hardware-timed).
|
||||||
void onBeforeTransmit() override {
|
// No onBeforeTransmit/onAfterTransmit overrides needed.
|
||||||
digitalWrite(P_LORA_PA_EN, HIGH); // Enable PA before transmission
|
|
||||||
}
|
|
||||||
|
|
||||||
void onAfterTransmit() override {
|
|
||||||
digitalWrite(P_LORA_PA_EN, LOW); // Disable PA after transmission to save power
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ build_flags = ${nrf52_base.build_flags}
|
|||||||
-D LORA_TX_POWER=22
|
-D LORA_TX_POWER=22
|
||||||
-D SX126X_CURRENT_LIMIT=140
|
-D SX126X_CURRENT_LIMIT=140
|
||||||
-D SX126X_RX_BOOSTED_GAIN=1
|
-D SX126X_RX_BOOSTED_GAIN=1
|
||||||
|
-D SX126X_REGISTER_PATCH=1 ; Patch register 0x8B5 for improved RX with SKY66122 FEM
|
||||||
build_src_filter = ${nrf52_base.build_src_filter}
|
build_src_filter = ${nrf52_base.build_src_filter}
|
||||||
+<../variants/rak3401>
|
+<../variants/rak3401>
|
||||||
+<helpers/sensors>
|
+<helpers/sensors>
|
||||||
|
|||||||
@@ -147,8 +147,15 @@ static const uint8_t AREF = PIN_AREF;
|
|||||||
#define SX126X_BUSY (9)
|
#define SX126X_BUSY (9)
|
||||||
#define SX126X_RESET (4)
|
#define SX126X_RESET (4)
|
||||||
|
|
||||||
#define SX126X_POWER_EN (21)
|
// SKY66122-11 FEM control on the RAK13302 module:
|
||||||
// DIO2 controlls an antenna switch and the TCXO voltage is controlled by DIO3
|
// CSD + CPS are tied together on the PCB, routed to WisBlock IO3 (P0.21).
|
||||||
|
// Setting IO3 HIGH enables the FEM (LNA for RX, PA path for TX).
|
||||||
|
// CTX is connected to SX1262 DIO2 — the radio handles TX/RX switching
|
||||||
|
// in hardware via SetDIO2AsRfSwitchCtrl (microsecond-accurate, no GPIO needed).
|
||||||
|
// The 5V boost for the PA is enabled by WB_IO2 (P0.34 = PIN_3V3_EN).
|
||||||
|
#define SX126X_POWER_EN (21) // P0.21 = IO3 -> SKY66122 CSD+CPS (FEM enable)
|
||||||
|
|
||||||
|
// CTX is driven by SX1262 DIO2, not a GPIO
|
||||||
#define SX126X_DIO2_AS_RF_SWITCH
|
#define SX126X_DIO2_AS_RF_SWITCH
|
||||||
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
|
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
|
||||||
|
|
||||||
@@ -159,7 +166,6 @@ static const uint8_t AREF = PIN_AREF;
|
|||||||
#define P_LORA_DIO_1 SX126X_DIO1
|
#define P_LORA_DIO_1 SX126X_DIO1
|
||||||
#define P_LORA_BUSY SX126X_BUSY
|
#define P_LORA_BUSY SX126X_BUSY
|
||||||
#define P_LORA_RESET SX126X_RESET
|
#define P_LORA_RESET SX126X_RESET
|
||||||
#define P_LORA_PA_EN 31
|
|
||||||
|
|
||||||
// enables 3.3V periphery like GPS or IO Module
|
// enables 3.3V periphery like GPS or IO Module
|
||||||
// Do not toggle this for GPS power savings
|
// Do not toggle this for GPS power savings
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ extern "C"
|
|||||||
|
|
||||||
// Power management boot protection threshold (millivolts)
|
// Power management boot protection threshold (millivolts)
|
||||||
// Set to 0 to disable boot protection
|
// Set to 0 to disable boot protection
|
||||||
#define PWRMGT_VOLTAGE_BOOTLOCK 3100 // Won't boot below this voltage (mV)
|
#define PWRMGT_VOLTAGE_BOOTLOCK 3300 // Won't boot below this voltage (mV)
|
||||||
// LPCOMP wake configuration (voltage recovery from SYSTEMOFF)
|
// LPCOMP wake configuration (voltage recovery from SYSTEMOFF)
|
||||||
// AIN3 = P0.05 = PIN_A0 / PIN_VBAT_READ
|
// AIN3 = P0.05 = PIN_A0 / PIN_VBAT_READ
|
||||||
#define PWRMGT_LPCOMP_AIN 3
|
#define PWRMGT_LPCOMP_AIN 3
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ build_flags = ${WioTrackerL1.build_flags}
|
|||||||
-D PIN_BUZZER=12
|
-D PIN_BUZZER=12
|
||||||
-D QSPIFLASH=1
|
-D QSPIFLASH=1
|
||||||
-D ADVERT_NAME='"@@MAC"'
|
-D ADVERT_NAME='"@@MAC"'
|
||||||
|
-D ENV_PIN_SDA=PIN_WIRE1_SDA
|
||||||
|
-D ENV_PIN_SCL=PIN_WIRE1_SCL
|
||||||
; -D MESH_PACKET_LOGGING=1
|
; -D MESH_PACKET_LOGGING=1
|
||||||
; -D MESH_DEBUG=1
|
; -D MESH_DEBUG=1
|
||||||
build_src_filter = ${WioTrackerL1.build_src_filter}
|
build_src_filter = ${WioTrackerL1.build_src_filter}
|
||||||
|
|||||||
Reference in New Issue
Block a user