* more experiments

This commit is contained in:
Scott Powell 2025-03-25 01:26:46 +11:00
parent 7bd7bfb14a
commit 8355543366
6 changed files with 112 additions and 7 deletions

View file

@ -7,8 +7,11 @@
#include <SPIFFS.h>
#endif
#ifdef WRAPPER_CLASS
#define RADIOLIB_STATIC_ONLY 1
#include <RadioLib.h>
#endif
#include <helpers/ArduinoHelpers.h>
#include <helpers/StaticPoolPacketManager.h>
#include <helpers/SimpleMeshTables.h>
@ -108,9 +111,13 @@ struct ClientInfo {
#define CLI_REPLY_DELAY_MILLIS 1500
class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
RadioLibWrapper* my_radio;
FILESYSTEM* _fs;
#ifdef WRAPPER_CLASS
RadioLibWrapper* my_radio;
RADIO_CLASS* _phy;
#else
ESPNOWRadio* my_radio;
#endif
mesh::MainBoard* _board;
unsigned long next_local_advert, next_flood_advert;
bool _logging;
@ -474,9 +481,15 @@ protected:
}
public:
MyMesh(RADIO_CLASS& phy, mesh::MainBoard& board, RadioLibWrapper& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables)
#ifdef WRAPPER_CLASS
MyMesh(RADIO_CLASS& phy, mesh::MainBoard& board, RadioLibWrapper& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables)
: mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables),
_phy(&phy), _board(&board), _cli(board, this, &_prefs, this)
#else
MyMesh(mesh::MainBoard& board, ESPNOWRadio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables)
: mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables),
_board(&board), _cli(board, this, &_prefs, this)
#endif
{
my_radio = &radio;
memset(known_clients, 0, sizeof(known_clients));
@ -510,11 +523,13 @@ public:
// load persisted prefs
_cli.loadPrefs(_fs);
#ifdef WRAPPER_CLASS
_phy->setFrequency(_prefs.freq);
_phy->setSpreadingFactor(_prefs.sf);
_phy->setBandwidth(_prefs.bw);
_phy->setCodingRate(_prefs.cr);
_phy->setOutputPower(_prefs.tx_power_dbm);
#endif
updateAdvertTimer();
updateFloodAdvertTimer();
@ -582,7 +597,9 @@ public:
}
void setTxPower(uint8_t power_dbm) override {
#ifdef WRAPPER_CLASS
_phy->setOutputPower(power_dbm);
#endif
}
void loop() {
@ -616,7 +633,11 @@ VolatileRTCClock fallback_clock;
#endif
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#ifdef WRAPPER_CLASS
MyMesh the_mesh(radio, board, *new WRAPPER_CLASS(radio, board), *new ArduinoMillis(), fast_rng, rtc_clock, tables);
#else
MyMesh the_mesh(board, radio, *new ArduinoMillis(), fast_rng, rtc_clock, tables);
#endif
void halt() {
while (1) ;
@ -636,7 +657,11 @@ void setup() {
if (!radio_init()) { halt(); }
#ifdef WRAPPER_CLASS
fast_rng.begin(radio.random(0x7FFFFFFF));
#else
fast_rng.begin(radio.intID());
#endif
FILESYSTEM* fs;
#if defined(NRF52_PLATFORM)
@ -652,7 +677,11 @@ void setup() {
#endif
if (!store.load("_main", the_mesh.self_id)) {
MESH_DEBUG_PRINTLN("Generating new keypair");
#ifdef WRAPPER_CLASS
RadioNoiseListener rng(radio);
#else
#define rng fast_rng
#endif
the_mesh.self_id = mesh::LocalIdentity(&rng); // create new random identity
store.save("_main", the_mesh.self_id);
}

View file

@ -7,8 +7,11 @@
#include <SPIFFS.h>
#endif
#ifdef WRAPPER_CLASS
#define RADIOLIB_STATIC_ONLY 1
#include <RadioLib.h>
#endif
#include <helpers/ArduinoHelpers.h>
#include <helpers/StaticPoolPacketManager.h>
#include <helpers/SimpleMeshTables.h>
@ -141,9 +144,13 @@ struct ServerStats {
};
class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
RadioLibWrapper* my_radio;
FILESYSTEM* _fs;
#ifdef WRAPPER_CLASS
RadioLibWrapper* my_radio;
RADIO_CLASS* _phy;
#else
ESPNOWRadio* my_radio;
#endif
mesh::MainBoard* _board;
unsigned long next_local_advert, next_flood_advert;
NodePrefs _prefs;
@ -593,9 +600,15 @@ protected:
}
public:
#ifdef WRAPPER_CLASS
MyMesh(RADIO_CLASS& phy, mesh::MainBoard& board, RadioLibWrapper& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables)
: mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables),
_phy(&phy), _board(&board), _cli(board, this, &_prefs, this)
#else
MyMesh(mesh::MainBoard& board, ESPNOWRadio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables)
: mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables),
_board(&board), _cli(board, this, &_prefs, this)
#endif
{
my_radio = &radio;
next_local_advert = next_flood_advert = 0;
@ -638,11 +651,13 @@ public:
// load persisted prefs
_cli.loadPrefs(_fs);
#ifdef WRAPPER_CLASS
_phy->setFrequency(_prefs.freq);
_phy->setSpreadingFactor(_prefs.sf);
_phy->setBandwidth(_prefs.bw);
_phy->setCodingRate(_prefs.cr);
_phy->setOutputPower(_prefs.tx_power_dbm);
#endif
updateAdvertTimer();
}
@ -695,7 +710,9 @@ public:
void dumpLogFile() override { /* no-op */ }
void setTxPower(uint8_t power_dbm) override {
#ifdef WRAPPER_CLASS
_phy->setOutputPower(power_dbm);
#endif
}
void loop() {
@ -764,7 +781,11 @@ VolatileRTCClock fallback_clock;
#endif
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#ifdef WRAPPER_CLASS
MyMesh the_mesh(radio, board, *new WRAPPER_CLASS(radio, board), *new ArduinoMillis(), fast_rng, rtc_clock, tables);
#else
MyMesh the_mesh(board, radio, *new ArduinoMillis(), fast_rng, rtc_clock, tables);
#endif
void halt() {
while (1) ;
@ -784,7 +805,11 @@ void setup() {
if (!radio_init()) { halt(); }
#ifdef WRAPPER_CLASS
fast_rng.begin(radio.random(0x7FFFFFFF));
#else
fast_rng.begin(radio.intID());
#endif
FILESYSTEM* fs;
#if defined(NRF52_PLATFORM)
@ -799,7 +824,11 @@ void setup() {
#error "need to define filesystem"
#endif
if (!store.load("_main", the_mesh.self_id)) {
#ifdef WRAPPER_CLASS
RadioNoiseListener rng(radio);
#else
#define rng fast_rng
#endif
the_mesh.self_id = mesh::LocalIdentity(&rng); // create new random identity
store.save("_main", the_mesh.self_id);
}

View file

@ -543,7 +543,11 @@ void setup() {
#ifdef WRAPPER_CLASS
fast_rng.begin(radio.random(0x7FFFFFFF));
#else
fast_rng.begin(rand());
char c = 0;
while (c != '\n') { // wait for ENTER to be pressed
if (Serial.available()) c = Serial.read();
}
fast_rng.begin(millis());
#endif
#if defined(NRF52_PLATFORM)

View file

@ -47,6 +47,17 @@ void ESPNOWRadio::begin() {
}
}
uint32_t ESPNOWRadio::intID() {
uint8_t mac[8];
memset(mac, 0, sizeof(mac));
esp_efuse_mac_get_default(mac);
uint32_t n, m;
memcpy(&n, &mac[0], 4);
memcpy(&m, &mac[4], 4);
return n * m;
}
void ESPNOWRadio::startSendRaw(const uint8_t* bytes, int len) {
// Send message via ESP-NOW
is_send_complete = false;
@ -79,5 +90,5 @@ int ESPNOWRadio::recvRaw(uint8_t* bytes, int sz) {
}
uint32_t ESPNOWRadio::getEstAirtimeFor(int len_bytes) {
return 100; // TODO
return 2; // Fast AF
}

View file

@ -22,6 +22,7 @@ public:
virtual float getLastSNR() const override;
float packetScore(float snr, int packet_len) override { return 0; }
uint32_t intID();
};
#if ESPNOW_DEBUG_LOGGING && ARDUINO

View file

@ -3,11 +3,14 @@
[env:Generic_C3_ESPNOW_terminal_chat]
extends = esp32_base
;board = esp32-c3-devkitm-1
board = esp32-s3-devkitc-1
board = esp32-c3-devkitm-1
;board = esp32-s3-devkitc-1
build_flags =
${esp32_base.build_flags}
-I variants/espnow_c3
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
-D ESP32_CPU_FREQ=80
-D MAX_CONTACTS=100
-D MAX_GROUP_CHANNELS=1
-D ESPNOW_DEBUG_LOGGING=1
@ -23,3 +26,31 @@ build_src_filter = ${esp32_base.build_src_filter}
lib_deps =
${esp32_base.lib_deps}
densaugeo/base64 @ ~1.4.0
[env:Generic_C3_ESPNOW_repeater]
extends = esp32_base
board = esp32-c3-devkitm-1
;board = esp32-s3-devkitc-1
build_flags =
${esp32_base.build_flags}
-I variants/espnow_c3
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
-D ESP32_CPU_FREQ=80
-D ESPNOW_DEBUG_LOGGING=1
; -D P_LORA_TX_LED=8
; -D P_LORA_TX_LED=35
-D PIN_USER_BTN=0
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
-D ADVERT_NAME='"ESPNOW Repeater"'
-D ADVERT_LAT=-37.0
-D ADVERT_LON=145.0
-D ADMIN_PASSWORD='"password"'
build_src_filter = ${esp32_base.build_src_filter}
+<../examples/simple_repeater/main.cpp>
+<helpers/esp32/ESPNowRadio.cpp>
+<../variants/espnow_c3>
lib_deps =
${esp32_base.lib_deps}
densaugeo/base64 @ ~1.4.0