feat: add Bluetooth-controlled LoRa OTA

Add the framed BLE mOTA transport and companion control path, complete the full-profile build and runtime fixes, and document and test the OTA workflow.
This commit is contained in:
mikecarper committed 2026-08-27 01:22:18 -07:00
1 parent 91870e4bb0
commit e5fd77e53f
79 files changed
+3178 -304

No files matched your search

+2 -1
View File
@@ -11,6 +11,7 @@ bool FolderMotaStore::readByteT(uint8_t& b) const {
while ((millis() - t0) < _to) {
int c = _io.read();
if (c >= 0) { b = (uint8_t)c; return true; }
delay(1); // let BLE/WiFi callbacks deliver the response
}
return false;
}
@@ -43,7 +44,7 @@ bool FolderMotaStore::txn(uint8_t op, const uint8_t* args, uint16_t arglen,
uint32_t t0 = millis(); bool got = false; uint8_t prev = 0;
while ((millis() - t0) < _to) { // scan for response magic 'm' 's' (tolerate noise)
int c = _io.read();
if (c < 0) continue;
if (c < 0) { delay(1); continue; }
if (prev == MOTA_SEEDER_RSP_MAGIC0 && (uint8_t)c == MOTA_SEEDER_RSP_MAGIC1) { got = true; break; }
prev = (uint8_t)c;
}
+2 -1
View File
@@ -11,6 +11,7 @@ bool SerialMotaSource::readByteT(uint8_t& b) {
while ((millis() - t0) < _to) {
int c = _io.read();
if (c >= 0) { b = (uint8_t)c; return true; }
delay(1); // let BLE/WiFi callbacks deliver the response
}
return false;
}
@@ -43,7 +44,7 @@ bool SerialMotaSource::txn(uint8_t op, const uint8_t* args, uint8_t arglen,
uint8_t prev = 0;
while ((millis() - t0) < _to) {
int c = _io.read();
if (c < 0) continue;
if (c < 0) { delay(1); continue; }
if (prev == MOTA_SEEDER_RSP_MAGIC0 && (uint8_t)c == MOTA_SEEDER_RSP_MAGIC1) { got = true; break; }
prev = (uint8_t)c;
}
+10 -1
View File
@@ -321,8 +321,17 @@ struct OtaContext {
FOLDER_LINK_NONE = 0,
FOLDER_LINK_SERIAL,
FOLDER_LINK_TCP,
FOLDER_LINK_BLE,
};
FolderLink folderLink() const { return _folder_link; }
static const char* folderLinkName(FolderLink link) {
switch (link) {
case FOLDER_LINK_SERIAL: return "serial";
case FOLDER_LINK_TCP: return "tcp";
case FOLDER_LINK_BLE: return "ble";
default: return "none";
}
}
bool folderSourceStats(uint16_t& offered, uint16_t& advertised) const {
return manager.sourceStats(_folder_source, offered, advertised);
}
@@ -337,7 +346,7 @@ struct OtaContext {
}
if (folder_active && _folder_link != link) {
snprintf(msg, cap, "ERR folder already attached via %s",
_folder_link == FOLDER_LINK_TCP ? "tcp" : "serial");
folderLinkName(_folder_link));
return false;
}
if (folder_active && _folder_source == source) {
+5 -1
View File
@@ -447,6 +447,7 @@ public:
FetchError fetchError() const { return _fetch_error; }
uint32_t blocksHave() const { return _have; }
uint32_t blocksTotal() const { return _fbc; }
uint32_t packetsSent() const { return _packets_sent; }
uint8_t fetchPipelineWidth() const { return _pipeline_width; }
static constexpr uint8_t fetchPipelineCapacity() { return OTA_FETCH_PIPELINE; }
uint32_t fetchRetryTimeoutMs() const;
@@ -482,7 +483,9 @@ private:
bool expandCatalog();
bool emit(const uint8_t* b, uint16_t n, bool flood) {
return _send && n && _send(_ctx, b, n, flood);
const bool sent = _send && n && _send(_ctx, b, n, flood);
if (sent) _packets_sent++;
return sent;
}
void handleAdv(const uint8_t* m, uint16_t n); // beacon -> sources table (+ query if interested)
void handleQuery(const uint8_t* m, uint16_t n); // serve: reply OTA_HAVE catalog
@@ -655,6 +658,7 @@ private:
uint32_t _radio_packet_airtime_ms = 0; // measured for MAX_TRANS_UNIT at active SF/BW
uint16_t _tx_spacing_permille = 2000; // 1/duty-cycle; default airtime factor 1 => 50% TX
uint8_t _observed_path_transmissions = 0; // source + relays; 0 falls back to configured max_hops+1
uint32_t _packets_sent = 0; // OTA packets accepted by the radio adapter (wrap-safe)
// multi-fragment manifest reassembly (a signed v2 manifest exceeds one packet)
uint8_t _mf_buf[OTA_MF_MAXFRAG * OTA_MF_FRAG]; // sized to the fragment cap so no valid manifest is silently dropped
uint16_t _mf_retries = 0; // GET_MANIFEST retries while WANT_MANIFEST (give up after a cap)