Keep T-Beam companion available without radio
This commit is contained in:
1 parent
bd2e668961
commit
8b4e57b1e5
11 files changed
+310
-53
No files matched your search
+44
-3
@@ -35,6 +35,28 @@ static uint32_t scaleCADDelayForQueue(uint32_t normal_delay, int ready_count,
|
||||
return scaled < floor ? floor : scaled;
|
||||
}
|
||||
|
||||
void Dispatcher::setRadioAvailable(bool available) {
|
||||
if (radio_available == available) return;
|
||||
|
||||
radio_available = available;
|
||||
if (!dispatcher_started || !radio_available) return;
|
||||
|
||||
const unsigned long now = _ms->getMillis();
|
||||
radio_nonrx_start = now;
|
||||
next_floor_calib_time = now;
|
||||
next_agc_reset_time = now;
|
||||
_radio->begin();
|
||||
prev_isrecv_mode = _radio->isInRecvMode();
|
||||
last_observed_radio_irq = _radio->getLastRadioInterruptMillis();
|
||||
#ifdef RADIO_LIVENESS_SOFT_ONLY
|
||||
last_radio_activity_ms = now;
|
||||
#else
|
||||
radio_liveness.begin(now);
|
||||
nonrx_soft_recovery_attempted = false;
|
||||
#endif
|
||||
MESH_DEBUG_PRINTLN("Dispatcher: radio transport activated");
|
||||
}
|
||||
|
||||
void Dispatcher::begin() {
|
||||
n_sent_flood = n_sent_direct = 0;
|
||||
n_recv_flood = n_recv_direct = 0;
|
||||
@@ -49,10 +71,17 @@ void Dispatcher::begin() {
|
||||
tx_budget_ms = (unsigned long)(duty_cycle_window_ms * duty_cycle);
|
||||
last_budget_update = _ms->getMillis();
|
||||
|
||||
_radio->begin();
|
||||
prev_isrecv_mode = _radio->isInRecvMode();
|
||||
const unsigned long now = _ms->getMillis();
|
||||
last_observed_radio_irq = _radio->getLastRadioInterruptMillis();
|
||||
dispatcher_started = true;
|
||||
if (radio_available) {
|
||||
_radio->begin();
|
||||
prev_isrecv_mode = _radio->isInRecvMode();
|
||||
last_observed_radio_irq = _radio->getLastRadioInterruptMillis();
|
||||
} else {
|
||||
prev_isrecv_mode = false;
|
||||
last_observed_radio_irq = 0;
|
||||
MESH_DEBUG_PRINTLN("Dispatcher: starting without a radio transport");
|
||||
}
|
||||
#ifdef RADIO_LIVENESS_SOFT_ONLY
|
||||
last_radio_activity_ms = now;
|
||||
#else
|
||||
@@ -267,6 +296,14 @@ uint32_t Dispatcher::getRadioWatchdogMillis() const {
|
||||
#endif
|
||||
|
||||
void Dispatcher::loop() {
|
||||
if (!radio_available) {
|
||||
// Keep packet-manager cleanup alive, but never touch an uninitialized or
|
||||
// physically unavailable radio. sendPacket() rejects new outbound work
|
||||
// while this state is active, so no queue can silently fill up.
|
||||
releaseDroppedOutbound();
|
||||
return;
|
||||
}
|
||||
|
||||
if (millisHasNowPassed(next_floor_calib_time)) {
|
||||
_radio->triggerNoiseFloorCalibrate(getInterferenceThreshold());
|
||||
_radio->setCADEnabled(getCADEnabled());
|
||||
@@ -713,6 +750,10 @@ void Dispatcher::releasePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
bool Dispatcher::queueOutboundPacket(Packet* packet, uint8_t priority, uint32_t delay_millis) {
|
||||
if (!radio_available) {
|
||||
MESH_DEBUG_PRINTLN("%s Dispatcher::sendPacket(): radio unavailable", getLogDateTime());
|
||||
return false;
|
||||
}
|
||||
if (!Packet::isValidPathLen(packet->path_len) || packet->payload_len > MAX_PACKET_PAYLOAD) {
|
||||
MESH_DEBUG_PRINTLN("%s Dispatcher::sendPacket(): ERROR: invalid packet... path_len=%d, payload_len=%d", getLogDateTime(), (uint32_t) packet->path_len, (uint32_t) packet->payload_len);
|
||||
return false;
|
||||
|
||||
@@ -245,6 +245,8 @@ class Dispatcher {
|
||||
unsigned long radio_nonrx_start;
|
||||
unsigned long next_floor_calib_time, next_agc_reset_time;
|
||||
bool prev_isrecv_mode;
|
||||
bool radio_available;
|
||||
bool dispatcher_started;
|
||||
bool outbound_radio_retry_pending;
|
||||
bool outbound_radio_retry_used;
|
||||
#ifndef RADIO_LIVENESS_SOFT_ONLY
|
||||
@@ -286,6 +288,8 @@ protected:
|
||||
_err_flags = 0;
|
||||
radio_nonrx_start = 0;
|
||||
prev_isrecv_mode = true;
|
||||
radio_available = true;
|
||||
dispatcher_started = false;
|
||||
tx_budget_ms = 0;
|
||||
last_budget_update = 0;
|
||||
duty_cycle_window_ms = 3600000;
|
||||
@@ -346,6 +350,8 @@ protected:
|
||||
}
|
||||
bool queueOutboundPacket(Packet* packet, uint8_t priority, uint32_t delay_millis);
|
||||
bool tryParsePacket(Packet* pkt, const uint8_t* raw, int len);
|
||||
void setRadioAvailable(bool available);
|
||||
bool isRadioAvailable() const { return radio_available; }
|
||||
|
||||
public:
|
||||
void begin();
|
||||
|
||||
@@ -585,17 +585,31 @@ bool WebConfigServer::startSetupMode(char reply[]) {
|
||||
// AP_STA (not pure AP) so the WiFi scan for the SSID picker works while
|
||||
// the AP is up. STA stays unconnected - the bridge won't touch WiFi
|
||||
// while wifi_ssid is empty, and `start webconfig ap` requires it stopped.
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
bool mode_ok = WiFi.mode(WIFI_AP_STA);
|
||||
// Setup mode has no login. Drop any STA association so the open setup API is
|
||||
// reachable only from the setup AP, not from the operator's LAN.
|
||||
WiFi.setAutoReconnect(false);
|
||||
WiFi.disconnect(false, true);
|
||||
bool disconnect_ok = WiFi.disconnect(false, true);
|
||||
delay(100);
|
||||
snprintf(_ap_ssid, sizeof(_ap_ssid), "MeshCore-Setup-%02X%02X", _pub_key[0], _pub_key[1]);
|
||||
bool ap_ok = false;
|
||||
for (uint8_t attempt = 1; attempt <= 6 && !ap_ok; ++attempt) {
|
||||
#ifdef WEBCONFIG_AP_PASSWORD
|
||||
bool ap_ok = WiFi.softAP(_ap_ssid, WEBCONFIG_AP_PASSWORD);
|
||||
ap_ok = WiFi.softAP(_ap_ssid, WEBCONFIG_AP_PASSWORD);
|
||||
#else
|
||||
bool ap_ok = WiFi.softAP(_ap_ssid);
|
||||
ap_ok = WiFi.softAP(_ap_ssid);
|
||||
#endif
|
||||
if (ap_ok) break;
|
||||
|
||||
Serial.printf(
|
||||
"WebConfig AP attempt %u failed: mode_ok=%d disconnect_ok=%d mode=%d heap=%u largest=%u\n",
|
||||
(unsigned)attempt, mode_ok, disconnect_ok, (int)WiFi.getMode(),
|
||||
(unsigned)ESP.getFreeHeap(),
|
||||
(unsigned)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL));
|
||||
WiFi.softAPdisconnect(true);
|
||||
delay(250);
|
||||
mode_ok = WiFi.mode(WIFI_AP_STA);
|
||||
}
|
||||
if (!ap_ok) {
|
||||
if (!promote_lan) WiFi.mode(WIFI_OFF);
|
||||
strcpy(reply, "Err: failed to start AP");
|
||||
@@ -782,7 +796,11 @@ void WebConfigServer::tick(uint32_t now) {
|
||||
} else if (_connect_deadline && (int32_t)(now - _connect_deadline) >= 0) {
|
||||
Serial.printf("WebConfig: WiFi '%s' unavailable; opening setup AP\n", _wifi_ssid);
|
||||
const bool retry_saved_wifi = _wifi_ssid[0] != 0;
|
||||
WiFi.disconnect(true);
|
||||
// Keep the WiFi driver running while changing from STA to AP+STA.
|
||||
// Powering it off here and starting an AP immediately can race the
|
||||
// asynchronous ESP32-S3 netif teardown and make softAP() return false.
|
||||
WiFi.disconnect(false, false);
|
||||
delay(50);
|
||||
_mode = MODE_OFF;
|
||||
_connect_deadline = 0;
|
||||
char ignored[160];
|
||||
|
||||
Reference in new issue
Block a user