Cleanup and fixes

This commit is contained in:
Martin Bauer
2023-09-14 16:16:17 +02:00
parent 4900c36e0b
commit 5e56ede55c
14 changed files with 258 additions and 23 deletions

View File

@@ -36,14 +36,13 @@ class LoggingAPI
if(running_)
{
const Logger * logger = Logger::getInstance();
const auto beginIt = lastEnd_;
const auto endIt = logger->end();
StaticJsonDocument<512> data;
for(auto it = beginIt; it != endIt; ++it) {
const auto endIt = logger->end();
StaticJsonDocument<1024> data;
for(auto it = lastEnd_; it != endIt; ++it) {
data["time"] = it.time_millis();
data["msg"] = it.message();
server.template sendToAll<512>(MessageCode::LOG_UPDATE, data);
server.template sendToAll<1024>(MessageCode::LOG_UPDATE, data);
}
lastEnd_ = endIt;
}
@@ -52,6 +51,6 @@ class LoggingAPI
private:
bool running_ = false;
Logger::iterator lastEnd_ = Logger::iterator(nullptr);
bool firstCall_ = false;
bool firstCall_ = true;
};

View File

@@ -50,14 +50,18 @@ public:
if (server_.poll())
{
LOG_INFO("new websocket connection, storing at pos %d - occupancy: ", nextFreeClient_);
clients_[nextFreeClient_] = server_.accept();
clients_[nextFreeClient_].onMessage(onMessage);
this->onClientConnectImpl(clients_[nextFreeClient_]);
nextFreeClient_ = (nextFreeClient_ + 1) % MAX_WEBSOCKET_CONNECTIONS;
for (int i = 0; i < MAX_WEBSOCKET_CONNECTIONS; ++i)
LOG_INFO((clients_[i].available()) ? "x" : "o");
if(MAX_WEBSOCKET_CONNECTIONS == 3) {
LOG_INFO("new websocket connection, storing at pos %d - occupancy: %d%d%d", nextFreeClient_, clients_[0].available(), clients_[1].available(), clients_[2].available());
} else {
LOG_INFO("new websocket connection, storing at pos %d - occupancy:", nextFreeClient_);
for (int i = 0; i < MAX_WEBSOCKET_CONNECTIONS; ++i)
LOG_INFO((clients_[i].available()) ? "x" : "o");
}
}
for (int i = 0; i < MAX_WEBSOCKET_CONNECTIONS; ++i)
@@ -69,12 +73,13 @@ public:
template <size_t bufferSize>
void sendToAll(MessageCode msgCode, const JsonDocument &content)
{
static_assert(sizeof(MessageCode) == 1);
char buffer[bufferSize];
buffer[0] = (char)(msgCode);
size_t bytesWritten = serializeMsgPack(content, buffer + sizeof(msgCode), bufferSize - sizeof(msgCode));
for (int i = 0; i < MAX_WEBSOCKET_CONNECTIONS; ++i)
if (clients_[i].available())
clients_[i].sendBinary(buffer, bytesWritten);
clients_[i].sendBinary(buffer, bytesWritten + sizeof(msgCode));
}
void sendToAll(MessageCode msgCode, const JsonDocument &content)

View File

@@ -433,6 +433,10 @@ void mdnsSetup(const String &fullHostname)
void setup()
{
Serial.begin(115200);
while (!Serial)
{
}
// Serial
Logger::init();