Merge PR 2864 LoRa OTA into Keymind
This commit is contained in:
commit
4c0dbe707d
94 files changed
+12959
-123
No files matched your search
@@ -12,7 +12,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef FIRMWARE_VERSION
|
||||
#define FIRMWARE_VERSION "v1.16.0"
|
||||
#define FIRMWARE_VERSION "v1.17.0"
|
||||
#endif
|
||||
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
|
||||
@@ -116,6 +116,90 @@ void halt() {
|
||||
unsigned long last_wifi_reconnect_attempt = 0;
|
||||
#endif
|
||||
|
||||
/* WIFI OTA SEEDER — relay a host folder of .mota over WiFi (motatool `serve --tcp`), on a DEDICATED port
|
||||
separate from the companion (TCP_PORT), so a phone app stays connected while motatool feeds updates. */
|
||||
#if defined(ESP32) && defined(WIFI_SSID) && defined(ENABLE_OTA)
|
||||
#include <helpers/ota/OtaContext.h>
|
||||
#include <helpers/ota/MotaSourceSerial.h>
|
||||
#include <helpers/ota/FolderMotaStore.h> // `ota pull <#> folder` destination over this same connection
|
||||
#ifndef OTA_SEEDER_TCP_PORT
|
||||
#define OTA_SEEDER_TCP_PORT 5001
|
||||
#endif
|
||||
static WiFiServer ota_seeder_server(OTA_SEEDER_TCP_PORT);
|
||||
static WiFiClient ota_seeder_client; // the live seeder connection (reused)
|
||||
static mesh::ota::SerialMotaSource ota_seeder_source(ota_seeder_client, 3000); // SERVE: read folder -> relay
|
||||
static mesh::ota::FolderMotaStore ota_folder_store(ota_seeder_client, 3000); // PULL: capture .mota -> folder
|
||||
static bool ota_seeder_attached = false;
|
||||
|
||||
// Accept one motatool connection at a time. While connected, the same link both SERVES the host folder
|
||||
// over LoRa (register it as a source) and is offered as a `folder` PULL destination (`ota pull <#> folder`
|
||||
// captures a fetched .mota back to that folder). Drop both the moment the connection closes.
|
||||
static void ota_seeder_loop() {
|
||||
if (ota_seeder_client && ota_seeder_client.connected()) return; // still serving the current client
|
||||
if (ota_seeder_attached) { // previous client just disconnected
|
||||
mesh::ota::ota_ctx().detach_folder();
|
||||
mesh::ota::ota_ctx().clear_folder_dest(); // the `folder` pull destination is gone too
|
||||
mesh::ota::ota_ctx().manager.announce(); // served set shrank back to our own fw -> re-advertise
|
||||
ota_seeder_attached = false;
|
||||
WIFI_DEBUG_PRINTLN("OTA seeder: client disconnected, relay stopped");
|
||||
}
|
||||
WiFiClient c = ota_seeder_server.available();
|
||||
if (c) {
|
||||
ota_seeder_client = c; // rebind the persistent Stream to it
|
||||
if (mesh::ota::ota_ctx().manager.add_source(&ota_seeder_source)) {
|
||||
ota_seeder_attached = true;
|
||||
char di[24]; snprintf(di, sizeof di, "tcp %s", ota_seeder_client.remoteIP().toString().c_str());
|
||||
mesh::ota::ota_ctx().set_folder_dest(&ota_folder_store, di); // offer `ota pull <#> folder`
|
||||
// if a folder pull PAUSED when the link dropped, the host still holds the partial: rescan + resume
|
||||
if (mesh::ota::ota_ctx().manager.fetchState() == mesh::ota::OtaManager::PAUSED)
|
||||
mesh::ota::ota_ctx().manager.resumeStaged(nullptr);
|
||||
mesh::ota::ota_ctx().manager.announce(); // new served set -> advertise the folder's fw to peers
|
||||
WIFI_DEBUG_PRINTLN("OTA seeder: client connected (%s) — relay + folder pull-dest ready", di);
|
||||
} else {
|
||||
ota_seeder_client.stop(); // no free source slot
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* WIFI OTA CONSOLE — a tiny text CLI for OTA over WiFi. A WiFi companion has no serial text console, so
|
||||
without this its OTA is only reachable through the phone app. Connect with e.g. `nc <ip> 5002` and type
|
||||
`ota status` / `ota ls` / `ota announce` / ... — one client at a time, on a DEDICATED port separate from
|
||||
the companion (5000) and the seeder (5001). */
|
||||
#if defined(ESP32) && defined(WIFI_SSID) && defined(ENABLE_OTA)
|
||||
#include <helpers/ota/OtaCli.h> // mesh::ota::handle_ota_command(line, reply, board)
|
||||
#ifndef OTA_CONSOLE_TCP_PORT
|
||||
#define OTA_CONSOLE_TCP_PORT 5002
|
||||
#endif
|
||||
static WiFiServer ota_console_server(OTA_CONSOLE_TCP_PORT);
|
||||
static WiFiClient ota_console_client;
|
||||
static char ota_console_line[128];
|
||||
static uint8_t ota_console_len = 0;
|
||||
|
||||
static void ota_console_loop() {
|
||||
if (!ota_console_client || !ota_console_client.connected()) {
|
||||
WiFiClient c = ota_console_server.available();
|
||||
if (c) { ota_console_client = c; ota_console_len = 0;
|
||||
ota_console_client.print("OTA console — type `ota ...` (e.g. ota status / ota ls / ota announce)\r\n> "); }
|
||||
return;
|
||||
}
|
||||
while (ota_console_client.available()) {
|
||||
char ch = (char)ota_console_client.read();
|
||||
if (ch == '\r' || ch == '\n') {
|
||||
if (ota_console_len == 0) continue; // ignore blanks / the CRLF pair
|
||||
ota_console_line[ota_console_len] = 0;
|
||||
char reply[160]; reply[0] = 0;
|
||||
if (!mesh::ota::handle_ota_command(ota_console_line, reply, board))
|
||||
strcpy(reply, "only `ota ...` commands are supported on this console");
|
||||
ota_console_client.print(" -> "); ota_console_client.print(reply); ota_console_client.print("\r\n> ");
|
||||
ota_console_len = 0;
|
||||
} else if (ota_console_len < sizeof(ota_console_line) - 1) {
|
||||
ota_console_line[ota_console_len++] = ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
@@ -213,13 +297,24 @@ void setup() {
|
||||
WIFI_DEBUG_PRINTLN("WiFi disconnected. Flagging for reconnect...");
|
||||
wifi_needs_reconnect = true;
|
||||
} else if (event == ARDUINO_EVENT_WIFI_STA_GOT_IP) {
|
||||
WIFI_DEBUG_PRINTLN("WiFi connected successfully!");
|
||||
WIFI_DEBUG_PRINTLN("connected! IP %s (companion app on :%d)",
|
||||
WiFi.localIP().toString().c_str(), TCP_PORT);
|
||||
wifi_needs_reconnect = false;
|
||||
}
|
||||
});
|
||||
|
||||
WiFi.begin(WIFI_SSID, WIFI_PWD);
|
||||
// Disable WiFi modem power-save: its periodic modem/light-sleep stalls the SX1262 SPI+DIO servicing,
|
||||
// which makes the LoRa radio go deaf (no TX/RX) while WiFi is associated. Required for LoRa+WiFi to
|
||||
// coexist on this ESP32 — the small extra idle current is well worth a working radio.
|
||||
WiFi.setSleep(false);
|
||||
serial_interface.begin(TCP_PORT);
|
||||
#ifdef ENABLE_OTA
|
||||
ota_seeder_server.begin(); // dedicated OTA seeder port for `motatool serve --tcp` (relay over LoRa)
|
||||
WIFI_DEBUG_PRINTLN("OTA seeder listening on :%d (motatool serve --tcp)", OTA_SEEDER_TCP_PORT);
|
||||
ota_console_server.begin(); // dedicated OTA text-console port (`nc <ip> 5002` -> `ota ...`)
|
||||
WIFI_DEBUG_PRINTLN("OTA console listening on :%d (nc <ip> %d, type `ota ...`)", OTA_CONSOLE_TCP_PORT, OTA_CONSOLE_TCP_PORT);
|
||||
#endif
|
||||
#elif defined(BLE_PIN_CODE)
|
||||
serial_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin());
|
||||
#elif defined(SERIAL_RX)
|
||||
@@ -297,6 +392,10 @@ void loop() {
|
||||
}
|
||||
|
||||
#if defined(ESP32) && defined(WIFI_SSID)
|
||||
#ifdef ENABLE_OTA
|
||||
ota_seeder_loop(); // accept/drop a motatool `serve --tcp` connection on the dedicated seeder port
|
||||
ota_console_loop(); // service the OTA text console (port 5002)
|
||||
#endif
|
||||
// Safely attempt to reconnect every 10 seconds if flagged
|
||||
if (wifi_needs_reconnect && (millis() - last_wifi_reconnect_attempt > 10000)) {
|
||||
WIFI_DEBUG_PRINTLN("Attempting manual WiFi reconnect...");
|
||||
|
||||
@@ -2328,8 +2328,10 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
|
||||
memset(default_scope.key, 0, sizeof(default_scope.key));
|
||||
}
|
||||
|
||||
// OTA mesh-integration (receive/begin/loop) is centralized in mesh::Mesh — no per-example wiring.
|
||||
|
||||
void MyMesh::begin(FILESYSTEM *fs) {
|
||||
mesh::Mesh::begin();
|
||||
mesh::Mesh::begin(); // also starts OTA (ota_ctx().begin) for all roles
|
||||
_fs = fs;
|
||||
// load persisted prefs
|
||||
_cli.loadPrefs(_fs);
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Mesh.h>
|
||||
#if defined(ENABLE_OTA)
|
||||
#include <helpers/ota/OtaContext.h>
|
||||
#endif
|
||||
#include <RTClib.h>
|
||||
#include <CayenneLPP.h>
|
||||
#include <target.h>
|
||||
@@ -85,7 +88,7 @@ struct NeighbourInfo {
|
||||
#endif
|
||||
|
||||
#ifndef FIRMWARE_VERSION
|
||||
#define FIRMWARE_VERSION "v1.16.0"
|
||||
#define FIRMWARE_VERSION "v1.17.0"
|
||||
#endif
|
||||
|
||||
#define FIRMWARE_ROLE "repeater"
|
||||
@@ -249,6 +252,9 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
||||
void formatScheduledRadioSetting(char* reply, int setting_idx, int display_idx) const;
|
||||
|
||||
protected:
|
||||
#if defined(ENABLE_OTA)
|
||||
bool isTempRadioActive() const override { return hasStartedScheduledTempRadio(); }
|
||||
#endif
|
||||
float getAirtimeBudgetFactor() const override {
|
||||
return _prefs.airtime_factor;
|
||||
}
|
||||
@@ -316,6 +322,7 @@ protected:
|
||||
void onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_idx, const uint8_t* secret, uint8_t* data, size_t len) override;
|
||||
bool onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override;
|
||||
void onControlDataRecv(mesh::Packet* packet) override;
|
||||
// OTA mesh-integration is centralized in mesh::Mesh (no per-example onOtaRecv / send adapter / tick).
|
||||
|
||||
void sendFloodReply(mesh::Packet* packet, unsigned long delay_millis, uint8_t path_hash_size);
|
||||
void sendClientReply(ClientInfo* client, mesh::Packet* packet, unsigned long delay_millis, uint8_t path_hash_size);
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef FIRMWARE_VERSION
|
||||
#define FIRMWARE_VERSION "v1.16.0"
|
||||
#define FIRMWARE_VERSION "v1.17.0"
|
||||
#endif
|
||||
|
||||
#ifndef LORA_FREQ
|
||||
@@ -139,6 +139,9 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
||||
int handleRequest(ClientInfo* sender, uint32_t sender_timestamp, uint8_t* payload, size_t payload_len);
|
||||
|
||||
protected:
|
||||
#if defined(ENABLE_OTA)
|
||||
bool isTempRadioActive() const override { return set_radio_at == 0 && revert_radio_at != 0; }
|
||||
#endif
|
||||
float getAirtimeBudgetFactor() const override {
|
||||
return _prefs.airtime_factor;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef FIRMWARE_VERSION
|
||||
#define FIRMWARE_VERSION "v1.16.0"
|
||||
#define FIRMWARE_VERSION "v1.17.0"
|
||||
#endif
|
||||
|
||||
#define FIRMWARE_ROLE "sensor"
|
||||
@@ -82,6 +82,9 @@ public:
|
||||
float getTelemValue(uint8_t channel, uint8_t type);
|
||||
|
||||
protected:
|
||||
#if defined(ENABLE_OTA)
|
||||
bool isTempRadioActive() const override { return set_radio_at == 0 && revert_radio_at != 0; }
|
||||
#endif
|
||||
// current telemetry data queries
|
||||
float getVoltage(uint8_t channel) { return getTelemValue(channel, LPP_VOLTAGE); }
|
||||
float getCurrent(uint8_t channel) { return getTelemValue(channel, LPP_CURRENT); }
|
||||
|
||||
Reference in new issue
Block a user