From deaa0ec2c86f2bd6c81fdabe705b1019d3fbd143 Mon Sep 17 00:00:00 2001 From: "Bence T." <3326575+tbb98@users.noreply.github.com> Date: Sat, 8 Mar 2025 00:04:43 +0100 Subject: [PATCH 1/3] Create packet_structure.md As mentioned by @mofosyne at issue #72 --- docs/packet_structure.md | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 docs/packet_structure.md diff --git a/docs/packet_structure.md b/docs/packet_structure.md new file mode 100644 index 00000000..a38c43ce --- /dev/null +++ b/docs/packet_structure.md @@ -0,0 +1,50 @@ +# Packet Structure + +| Field | Size (bytes) | Description | +|--------------|------------------------|-------------| +| `header` | 1 | Contains routing type, payload type, and payload version. | +| `payload_len` | 2 | Length of the payload in bytes. | +| `path_len` | 2 | Length of the path field in bytes. | +| `path` | `MAX_PATH_SIZE` | Stores the routing path if applicable. | +| `payload` | `MAX_PACKET_PAYLOAD` | The actual data being transmitted. | + +## Header Breakdown + +| Bits | Mask | Field | Description | +|-------|---------------|----------------|-------------| +| 0-1 | `0x03` | Route Type | Specifies the routing type (Flood, Direct, Reserved). | +| 2-5 | `0x0F` | Payload Type | Specifies the type of payload (Request, Response, Text, ACK, etc.). | +| 6-7 | `0x03` | Payload Version | Versioning of the payload format. | + +## Route Type Values + +| Value | Name | Description | +|--------|-------------------------|-------------| +| `0x00` | `ROUTE_TYPE_RESERVED1` | Reserved for future use. | +| `0x01` | `ROUTE_TYPE_FLOOD` | Flood routing mode (builds up path). | +| `0x02` | `ROUTE_TYPE_DIRECT` | Direct route (path is supplied). | +| `0x03` | `ROUTE_TYPE_RESERVED2` | Reserved for future use. | + +## Payload Type Values + +| Value | Name | Description | +|--------|-------------------------|-------------| +| `0x00` | `PAYLOAD_TYPE_REQ` | Request (destination/source hashes + MAC). | +| `0x01` | `PAYLOAD_TYPE_RESPONSE` | Response to REQ or ANON_REQ. | +| `0x02` | `PAYLOAD_TYPE_TXT_MSG` | Plain text message. | +| `0x03` | `PAYLOAD_TYPE_ACK` | Acknowledgment. | +| `0x04` | `PAYLOAD_TYPE_ADVERT` | Node advertisement. | +| `0x05` | `PAYLOAD_TYPE_GRP_TXT` | Group text message (unverified). | +| `0x06` | `PAYLOAD_TYPE_GRP_DATA` | Group datagram (unverified). | +| `0x07` | `PAYLOAD_TYPE_ANON_REQ` | Anonymous request. | +| `0x08` | `PAYLOAD_TYPE_PATH` | Returned path. | +| `0x0F` | `PAYLOAD_TYPE_RAW_CUSTOM` | Custom packet (raw bytes, custom encryption). | + +## Payload Version Values + +| Value | Name | Description | +|--------|---------------|-------------| +| `0x00` | `PAYLOAD_VER_1` | 1-byte src/dest hashes, 2-byte MAC. | +| `0x01` | `PAYLOAD_VER_2` | Future version (e.g., 2-byte hashes, 4-byte MAC). | +| `0x02` | `PAYLOAD_VER_3` | Future version. | +| `0x03` | `PAYLOAD_VER_4` | Future version. | From a2a9455dc0669f16d0230cb65e80c906ab37555a Mon Sep 17 00:00:00 2001 From: Matthew Sainsbury Date: Thu, 5 Jun 2025 20:16:18 -0700 Subject: [PATCH 2/3] corrections and style --- docs/packet_structure.md | 69 ++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/docs/packet_structure.md b/docs/packet_structure.md index a38c43ce..b02c3c33 100644 --- a/docs/packet_structure.md +++ b/docs/packet_structure.md @@ -1,50 +1,51 @@ # Packet Structure -| Field | Size (bytes) | Description | -|--------------|------------------------|-------------| -| `header` | 1 | Contains routing type, payload type, and payload version. | -| `payload_len` | 2 | Length of the payload in bytes. | -| `path_len` | 2 | Length of the path field in bytes. | -| `path` | `MAX_PATH_SIZE` | Stores the routing path if applicable. | -| `payload` | `MAX_PACKET_PAYLOAD` | The actual data being transmitted. | +| Field | Size (bytes) | Description | +|----------|----------------------------------|-----------------------------------------------------------| +| header | 1 | Contains routing type, payload type, and payload version. | +| path_len | 1 | Length of the path field in bytes. | +| path | up to 64 (`MAX_PATH_SIZE`) | Stores the routing path if applicable. | +| payload | up to 184 (`MAX_PACKET_PAYLOAD`) | The actual data being transmitted. | + +Note: see the [payloads doc](./payloads.md) for more information about the content of payload. ## Header Breakdown -| Bits | Mask | Field | Description | -|-------|---------------|----------------|-------------| -| 0-1 | `0x03` | Route Type | Specifies the routing type (Flood, Direct, Reserved). | -| 2-5 | `0x0F` | Payload Type | Specifies the type of payload (Request, Response, Text, ACK, etc.). | -| 6-7 | `0x03` | Payload Version | Versioning of the payload format. | +| Bits | Mask | Field | Description | +|-------|--------|-----------------|-----------------------------------------------| +| 0-1 | `0x03` | Route Type | Flood, Direct, Reserved - see below. | +| 2-5 | `0x0F` | Payload Type | Request, Response, ACK, etc. - see below. | +| 6-7 | `0x03` | Payload Version | Versioning of the payload format - see below. | ## Route Type Values -| Value | Name | Description | -|--------|-------------------------|-------------| -| `0x00` | `ROUTE_TYPE_RESERVED1` | Reserved for future use. | +| Value | Name | Description | +|--------|------------------------|--------------------------------------| +| `0x00` | `ROUTE_TYPE_RESERVED1` | Reserved for future use. | | `0x01` | `ROUTE_TYPE_FLOOD` | Flood routing mode (builds up path). | -| `0x02` | `ROUTE_TYPE_DIRECT` | Direct route (path is supplied). | -| `0x03` | `ROUTE_TYPE_RESERVED2` | Reserved for future use. | +| `0x02` | `ROUTE_TYPE_DIRECT` | Direct route (path is supplied). | +| `0x03` | `ROUTE_TYPE_RESERVED2` | Reserved for future use. | ## Payload Type Values -| Value | Name | Description | -|--------|-------------------------|-------------| -| `0x00` | `PAYLOAD_TYPE_REQ` | Request (destination/source hashes + MAC). | -| `0x01` | `PAYLOAD_TYPE_RESPONSE` | Response to REQ or ANON_REQ. | -| `0x02` | `PAYLOAD_TYPE_TXT_MSG` | Plain text message. | -| `0x03` | `PAYLOAD_TYPE_ACK` | Acknowledgment. | -| `0x04` | `PAYLOAD_TYPE_ADVERT` | Node advertisement. | -| `0x05` | `PAYLOAD_TYPE_GRP_TXT` | Group text message (unverified). | -| `0x06` | `PAYLOAD_TYPE_GRP_DATA` | Group datagram (unverified). | -| `0x07` | `PAYLOAD_TYPE_ANON_REQ` | Anonymous request. | -| `0x08` | `PAYLOAD_TYPE_PATH` | Returned path. | +| Value | Name | Description | +|--------|---------------------------|-----------------------------------------------| +| `0x00` | `PAYLOAD_TYPE_REQ` | Request (destination/source hashes + MAC). | +| `0x01` | `PAYLOAD_TYPE_RESPONSE` | Response to REQ or ANON_REQ. | +| `0x02` | `PAYLOAD_TYPE_TXT_MSG` | Plain text message. | +| `0x03` | `PAYLOAD_TYPE_ACK` | Acknowledgment. | +| `0x04` | `PAYLOAD_TYPE_ADVERT` | Node advertisement. | +| `0x05` | `PAYLOAD_TYPE_GRP_TXT` | Group text message (unverified). | +| `0x06` | `PAYLOAD_TYPE_GRP_DATA` | Group datagram (unverified). | +| `0x07` | `PAYLOAD_TYPE_ANON_REQ` | Anonymous request. | +| `0x08` | `PAYLOAD_TYPE_PATH` | Returned path. | | `0x0F` | `PAYLOAD_TYPE_RAW_CUSTOM` | Custom packet (raw bytes, custom encryption). | ## Payload Version Values -| Value | Name | Description | -|--------|---------------|-------------| -| `0x00` | `PAYLOAD_VER_1` | 1-byte src/dest hashes, 2-byte MAC. | -| `0x01` | `PAYLOAD_VER_2` | Future version (e.g., 2-byte hashes, 4-byte MAC). | -| `0x02` | `PAYLOAD_VER_3` | Future version. | -| `0x03` | `PAYLOAD_VER_4` | Future version. | +| Value | Version | Description | +|--------|---------|---------------------------------------------------| +| `0x00` | 1 | 1-byte src/dest hashes, 2-byte MAC. | +| `0x01` | 2 | Future version (e.g., 2-byte hashes, 4-byte MAC). | +| `0x02` | 3 | Future version. | +| `0x03` | 4 | Future version. | From fca86d93f3319d19683b0e86dfceaf4bf2d0b0d0 Mon Sep 17 00:00:00 2001 From: Alex Wolden Date: Tue, 10 Jun 2025 22:07:47 -0700 Subject: [PATCH 3/3] Added support for t3s3 sx1276 --- docs/packet_structure.md | 51 --------- variants/lilygo_t3s3_sx1276/platformio.ini | 119 +++++++++++++++++++++ variants/lilygo_t3s3_sx1276/target.cpp | 70 ++++++++++++ variants/lilygo_t3s3_sx1276/target.h | 27 +++++ 4 files changed, 216 insertions(+), 51 deletions(-) delete mode 100644 docs/packet_structure.md create mode 100644 variants/lilygo_t3s3_sx1276/platformio.ini create mode 100644 variants/lilygo_t3s3_sx1276/target.cpp create mode 100644 variants/lilygo_t3s3_sx1276/target.h diff --git a/docs/packet_structure.md b/docs/packet_structure.md deleted file mode 100644 index b02c3c33..00000000 --- a/docs/packet_structure.md +++ /dev/null @@ -1,51 +0,0 @@ -# Packet Structure - -| Field | Size (bytes) | Description | -|----------|----------------------------------|-----------------------------------------------------------| -| header | 1 | Contains routing type, payload type, and payload version. | -| path_len | 1 | Length of the path field in bytes. | -| path | up to 64 (`MAX_PATH_SIZE`) | Stores the routing path if applicable. | -| payload | up to 184 (`MAX_PACKET_PAYLOAD`) | The actual data being transmitted. | - -Note: see the [payloads doc](./payloads.md) for more information about the content of payload. - -## Header Breakdown - -| Bits | Mask | Field | Description | -|-------|--------|-----------------|-----------------------------------------------| -| 0-1 | `0x03` | Route Type | Flood, Direct, Reserved - see below. | -| 2-5 | `0x0F` | Payload Type | Request, Response, ACK, etc. - see below. | -| 6-7 | `0x03` | Payload Version | Versioning of the payload format - see below. | - -## Route Type Values - -| Value | Name | Description | -|--------|------------------------|--------------------------------------| -| `0x00` | `ROUTE_TYPE_RESERVED1` | Reserved for future use. | -| `0x01` | `ROUTE_TYPE_FLOOD` | Flood routing mode (builds up path). | -| `0x02` | `ROUTE_TYPE_DIRECT` | Direct route (path is supplied). | -| `0x03` | `ROUTE_TYPE_RESERVED2` | Reserved for future use. | - -## Payload Type Values - -| Value | Name | Description | -|--------|---------------------------|-----------------------------------------------| -| `0x00` | `PAYLOAD_TYPE_REQ` | Request (destination/source hashes + MAC). | -| `0x01` | `PAYLOAD_TYPE_RESPONSE` | Response to REQ or ANON_REQ. | -| `0x02` | `PAYLOAD_TYPE_TXT_MSG` | Plain text message. | -| `0x03` | `PAYLOAD_TYPE_ACK` | Acknowledgment. | -| `0x04` | `PAYLOAD_TYPE_ADVERT` | Node advertisement. | -| `0x05` | `PAYLOAD_TYPE_GRP_TXT` | Group text message (unverified). | -| `0x06` | `PAYLOAD_TYPE_GRP_DATA` | Group datagram (unverified). | -| `0x07` | `PAYLOAD_TYPE_ANON_REQ` | Anonymous request. | -| `0x08` | `PAYLOAD_TYPE_PATH` | Returned path. | -| `0x0F` | `PAYLOAD_TYPE_RAW_CUSTOM` | Custom packet (raw bytes, custom encryption). | - -## Payload Version Values - -| Value | Version | Description | -|--------|---------|---------------------------------------------------| -| `0x00` | 1 | 1-byte src/dest hashes, 2-byte MAC. | -| `0x01` | 2 | Future version (e.g., 2-byte hashes, 4-byte MAC). | -| `0x02` | 3 | Future version. | -| `0x03` | 4 | Future version. | diff --git a/variants/lilygo_t3s3_sx1276/platformio.ini b/variants/lilygo_t3s3_sx1276/platformio.ini new file mode 100644 index 00000000..1bcbbbf9 --- /dev/null +++ b/variants/lilygo_t3s3_sx1276/platformio.ini @@ -0,0 +1,119 @@ +[LilyGo_T3S3_sx1276] +extends = esp32_base +board = t3_s3_v1_x +build_flags = + ${esp32_base.build_flags} + -I variants/lilygo_t3s3_sx1276 + -D LILYGO_T3S3 + -D P_LORA_DIO_0=9 + -D P_LORA_DIO_1=33 + -D P_LORA_NSS=7 + -D P_LORA_RESET=8 + -D P_LORA_SCLK=5 + -D P_LORA_MISO=3 + -D P_LORA_MOSI=6 + -D P_LORA_TX_LED=37 + -D PIN_VBAT_READ=1 + -D PIN_USER_BTN=0 + -D PIN_BOARD_SDA=18 + -D PIN_BOARD_SCL=17 + -D PIN_OLED_RESET=21 + -D RADIO_CLASS=CustomSX1276 + -D WRAPPER_CLASS=CustomSX1276Wrapper + -D SX127X_CURRENT_LIMIT=120 + -D LORA_TX_POWER=20 +build_src_filter = ${esp32_base.build_src_filter} + +<../variants/lilygo_t3s3_sx1276> +lib_deps = + ${esp32_base.lib_deps} + adafruit/Adafruit SSD1306 @ ^2.5.13 + +; === LilyGo T3S3 with SX1276 environments === +[env:LilyGo_T3S3_sx1276_Repeater] +extends = LilyGo_T3S3_sx1276 +build_flags = + ${LilyGo_T3S3_sx1276.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D ADVERT_NAME='"T3S3-1276 Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=8 + ; -D MESH_PACKET_LOGGING=1 + ; -D MESH_DEBUG=1 +build_src_filter = ${LilyGo_T3S3_sx1276.build_src_filter} + + + +<../examples/simple_repeater> +lib_deps = + ${LilyGo_T3S3_sx1276.lib_deps} + ${esp32_ota.lib_deps} + +[env:LilyGo_T3S3_sx1276_terminal_chat] +extends = LilyGo_T3S3_sx1276 +build_flags = + ${LilyGo_T3S3_sx1276.build_flags} + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${LilyGo_T3S3_sx1276.build_src_filter} + +<../examples/simple_secure_chat/main.cpp> +lib_deps = + ${LilyGo_T3S3_sx1276.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:LilyGo_T3S3_sx1276_room_server] +extends = LilyGo_T3S3_sx1276 +build_flags = + ${LilyGo_T3S3_sx1276.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D ADVERT_NAME='"T3S3-1276 Room"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D ROOM_PASSWORD='"hello"' +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${LilyGo_T3S3_sx1276.build_src_filter} + + + +<../examples/simple_room_server> +lib_deps = + ${LilyGo_T3S3_sx1276.lib_deps} + ${esp32_ota.lib_deps} + +[env:LilyGo_T3S3_sx1276_companion_radio_usb] +extends = LilyGo_T3S3_sx1276 +upload_speed = 115200 +build_flags = + ${LilyGo_T3S3_sx1276.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=8 + -D MESH_PACKET_LOGGING=1 + -D MESH_DEBUG=1 +build_src_filter = ${LilyGo_T3S3_sx1276.build_src_filter} + + + +<../examples/companion_radio> +lib_deps = + ${LilyGo_T3S3_sx1276.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:LilyGo_T3S3_sx1276_companion_radio_ble] +extends = LilyGo_T3S3_sx1276 +build_flags = + ${LilyGo_T3S3_sx1276.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=8 + -D BLE_PIN_CODE=123456 + -D BLE_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${LilyGo_T3S3_sx1276.build_src_filter} + + + + + +<../examples/companion_radio> +lib_deps = + ${LilyGo_T3S3_sx1276.lib_deps} + densaugeo/base64 @ ~1.4.0 \ No newline at end of file diff --git a/variants/lilygo_t3s3_sx1276/target.cpp b/variants/lilygo_t3s3_sx1276/target.cpp new file mode 100644 index 00000000..db11433a --- /dev/null +++ b/variants/lilygo_t3s3_sx1276/target.cpp @@ -0,0 +1,70 @@ +#include +#include "target.h" + +ESP32Board board; + +#if defined(P_LORA_SCLK) + static SPIClass spi; + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1); +#endif + +WRAPPER_CLASS radio_driver(radio, board); + +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); +SensorManager sensors; + +#ifdef DISPLAY_CLASS + DISPLAY_CLASS display; +#endif + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + +#if defined(P_LORA_SCLK) + spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); +#endif + int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8); + if (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + +#ifdef SX127X_CURRENT_LIMIT + radio.setCurrentLimit(SX127X_CURRENT_LIMIT); +#endif + + radio.setCRC(1); + + radio.setRfSwitchPins(21, 10); + + return true; // success +} + +uint32_t radio_get_rng_seed() { + return radio.random(0x7FFFFFFF); +} + +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { + radio.setFrequency(freq); + radio.setSpreadingFactor(sf); + radio.setBandwidth(bw); + radio.setCodingRate(cr); +} + +void radio_set_tx_power(uint8_t dbm) { + radio.setOutputPower(dbm); +} + +mesh::LocalIdentity radio_new_identity() { + RadioNoiseListener rng(radio); + return mesh::LocalIdentity(&rng); // create new random identity +} \ No newline at end of file diff --git a/variants/lilygo_t3s3_sx1276/target.h b/variants/lilygo_t3s3_sx1276/target.h new file mode 100644 index 00000000..c5fc0be0 --- /dev/null +++ b/variants/lilygo_t3s3_sx1276/target.h @@ -0,0 +1,27 @@ +#pragma once + +#define RADIOLIB_STATIC_ONLY 1 +#include +#include +#include +#include +#include +#include +#ifdef DISPLAY_CLASS + #include +#endif + +extern ESP32Board board; +extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; +extern SensorManager sensors; + +#ifdef DISPLAY_CLASS + extern DISPLAY_CLASS display; +#endif + +bool radio_init(); +uint32_t radio_get_rng_seed(); +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); +void radio_set_tx_power(uint8_t dbm); +mesh::LocalIdentity radio_new_identity(); \ No newline at end of file