mirror of https://github.com/meshcore-dev/MeshCore
4 changed files with 216 additions and 51 deletions
@ -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. | |
|||
@ -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} |
|||
+<helpers/ui/SSD1306Display.cpp> |
|||
+<../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} |
|||
+<helpers/ui/SSD1306Display.cpp> |
|||
+<../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} |
|||
+<helpers/ui/SSD1306Display.cpp> |
|||
+<../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} |
|||
+<helpers/esp32/*.cpp> |
|||
+<helpers/ui/SSD1306Display.cpp> |
|||
+<../examples/companion_radio> |
|||
lib_deps = |
|||
${LilyGo_T3S3_sx1276.lib_deps} |
|||
densaugeo/base64 @ ~1.4.0 |
|||
@ -0,0 +1,70 @@ |
|||
#include <Arduino.h> |
|||
#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
|
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
#pragma once |
|||
|
|||
#define RADIOLIB_STATIC_ONLY 1 |
|||
#include <RadioLib.h> |
|||
#include <helpers/RadioLibWrappers.h> |
|||
#include <helpers/ESP32Board.h> |
|||
#include <helpers/CustomSX1276Wrapper.h> |
|||
#include <helpers/AutoDiscoverRTCClock.h> |
|||
#include <helpers/SensorManager.h> |
|||
#ifdef DISPLAY_CLASS |
|||
#include <helpers/ui/SSD1306Display.h> |
|||
#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(); |
|||
Loading…
Reference in new issue