mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-11-01 14:22:12 +01:00
feat!: remove the old API, ports 8081 and 8080 (step 4a)
Step 4a of docs/SECURITY_PLAN.md. Port 80 keeps the eleven HTTP routes of ADR 0006 and the socket at /ws; everything else moved to protocol 2. - Port 8081 (ApiRoutes) and the socket on 8080 (SocketEmitter) are gone. Protocol 2 owns its frame buffer and loop-task check. - Port 80 drops every route the old web UI called: reads, edits, settings, scans, reboot, /shades.cfg, /discovery. HttpRoutes.cpp holds what stays. - ModelSnapshot, SnapshotSlots and the read documents are gone. The item snapshot types stay, as ItemSnapshot, for events, MQTT and the command replies. - Model edits reply only to their protocol 2 op: requestResult goes. - The settings' toJSON writers, used only by the settings routes, go. - The _espsomfy_rts._tcp mDNS record moves to port 80, with path=/ws. - The memory event reports the loop-rate window it closes. - A deleted room no longer re-publishes its retained MQTT topics. - e2e: the heap check reads the sync's status; the sync is checked on its own instead of against /controller. - README gets an API and ports section. BREAKING CHANGE: ports 8081 and 8080 and the old HTTP routes are gone. Home Assistant needs integration 3.0.0 or newer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c91c20d444
commit
2a954aa158
53 changed files with 613 additions and 3549 deletions
|
|
@ -1,55 +1,5 @@
|
|||
#include "WResp.h"
|
||||
#include "esp_log.h"
|
||||
#include "Timing.h"
|
||||
|
||||
static const char *TAG = "WResp";
|
||||
#define EMIT_SLOW_MS 20
|
||||
void JsonSockEvent::beginEvent(AsyncWebSocket *server, const char *evt, char *buff, size_t buffSize) {
|
||||
this->server = server;
|
||||
this->_evt = evt;
|
||||
this->buff = buff;
|
||||
this->buffSize = buffSize;
|
||||
this->_nocomma = true;
|
||||
this->_closed = false;
|
||||
this->_overflow = false;
|
||||
const int n = snprintf(this->buff, buffSize, "42[%s,", evt);
|
||||
this->_len = n < 0 ? 0 : ((size_t)n < buffSize ? (size_t)n : buffSize - 1);
|
||||
}
|
||||
void JsonSockEvent::closeEvent() {
|
||||
if(!this->_closed) {
|
||||
// The ] and the terminator both have to fit.
|
||||
if(this->_len + 1 < buffSize) this->_appendAt("]", false, 1);
|
||||
else this->_overflow = true;
|
||||
}
|
||||
this->_nocomma = true;
|
||||
this->_closed = true;
|
||||
}
|
||||
void JsonSockEvent::endEvent(uint32_t clientId) {
|
||||
this->closeEvent();
|
||||
// Part of it is missing so clients would only fail to parse it.
|
||||
if(this->_overflow) {
|
||||
ESP_LOGE(TAG, "Socket event too large for %u bytes, not sent: %.32s", (unsigned)this->buffSize, this->buff);
|
||||
return;
|
||||
}
|
||||
ElapsedTimer timer;
|
||||
if(clientId == 0) this->server->textAll(this->buff);
|
||||
else this->server->text(clientId, this->buff);
|
||||
// Sends happen every few seconds, so only the slow ones are worth a line.
|
||||
const uint32_t us = timer.us();
|
||||
if(us < EMIT_SLOW_MS * 1000) return;
|
||||
char what[80];
|
||||
if(clientId == 0) snprintf(what, sizeof(what), "Socket emit %s (%u bytes) to all", this->_evt, (unsigned)this->_len);
|
||||
else snprintf(what, sizeof(what), "Socket emit %s (%u bytes) to %lu", this->_evt, (unsigned)this->_len, (unsigned long)clientId);
|
||||
logElapsed(TAG, what, us);
|
||||
}
|
||||
void JsonSockEvent::_safecat(const char *val, bool escape) {
|
||||
const size_t vlen = escape ? this->calcEscapedLength(val) + 2 : strlen(val);
|
||||
if(this->_len + vlen >= this->buffSize) {
|
||||
this->_overflow = true;
|
||||
return;
|
||||
}
|
||||
this->_appendAt(val, escape, vlen);
|
||||
}
|
||||
void AsyncJsonResp::beginResponse(AsyncWebServerRequest *request, char *buff, size_t buffSize) {
|
||||
this->_request = request;
|
||||
this->buff = buff;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue