fix: only let wifiStrength broadcasts move the RSSI baseline

The emit to a newly connected client also stored the RSSI and time, which
restarted the 10s hold-off and hid a real change from the clients already
connected.  The baseline moves into RssiBroadcast, which ignores
per-client emits, with unit tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cjkas 2026-10-12 18:34:45 +02:00
parent c4472ba8e8
commit e47381b19e
5 changed files with 72 additions and 11 deletions

View file

@ -180,8 +180,8 @@ bool ESPNetwork::changeAP(const uint8_t *bssid, const int32_t channel) {
void ESPNetwork::emitSockets() {
this->emitHeap();
if(this->needsBroadcast ||
(this->connType == conn_types_t::wifi && rssiNeedsEmit(WiFi.RSSI(), this->lastRSSI, WiFi.channel(), this->lastChannel,
millis() - this->lastRSSIEmit, RSSI_EMIT_MIN_DBM, RSSI_EMIT_MIN_MS))) {
(this->connType == conn_types_t::wifi &&
this->rssiBroadcast.due(WiFi.RSSI(), WiFi.channel(), millis(), RSSI_EMIT_MIN_DBM, RSSI_EMIT_MIN_MS))) {
this->emitSockets(255);
sockEmit.loop();
this->needsBroadcast = false;
@ -209,9 +209,7 @@ void ESPNetwork::emitSockets(uint8_t num) {
json->addElem("channel", (int32_t)this->channel);
json->endObject();
sockEmit.endEmit(num);
this->lastRSSI = WiFi.RSSI();
this->lastChannel = WiFi.channel();
this->lastRSSIEmit = millis();
this->rssiBroadcast.sent(num == 255, WiFi.RSSI(), WiFi.channel(), millis());
}
else {
JsonSockEvent *json = sockEmit.beginEmit("wifiStrength");
@ -229,9 +227,7 @@ void ESPNetwork::emitSockets(uint8_t num) {
json->addElem("fullduplex", false);
json->endObject();
sockEmit.endEmit(num);
this->lastRSSI = -100;
this->lastChannel = -1;
this->lastRSSIEmit = millis();
this->rssiBroadcast.sent(num == 255, -100, -1, millis());
}
}
// A broadcast comes from emitSockets(), which has already sent memStatus.