Vhanged pin assignment to avoid 35,36,37 used in QSPI PSRAM
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
#include <webserver.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
static std::map<const std::string, AstroWebServer::c_commandEnum> s_webserverCommands = {
|
||||
{"setTime", AstroWebServer::SET_TIME},
|
||||
};
|
||||
|
||||
void on_ping(TimerHandle_t xTimer)
|
||||
{
|
||||
@@ -32,6 +27,10 @@ AstroWebServer::AstroWebServer(const uint8_t port, fs::FS &filesystem) : m_port(
|
||||
m_websocket.enable(true);
|
||||
|
||||
m_pingTimer = xTimerCreate("wsPingTimer", pdMS_TO_TICKS(2000), pdTRUE, (void *)&m_websocket, on_ping);
|
||||
|
||||
registerWsCommand("setTime", [this](const ArduinoJson::JsonDocument &doc)
|
||||
{ onSetTme(doc); });
|
||||
|
||||
LOG_DEBUG("Webserver Init OK");
|
||||
}
|
||||
|
||||
@@ -50,6 +49,21 @@ void AstroWebServer::sendWsData(const String &data)
|
||||
}
|
||||
}
|
||||
|
||||
void AstroWebServer::registerWsCommand(const std::string &cmd, const WScommand func)
|
||||
{
|
||||
if (cmd.empty() || m_webserverCommands.contains(cmd))
|
||||
return;
|
||||
if (!func)
|
||||
return;
|
||||
m_webserverCommands[cmd] = func;
|
||||
}
|
||||
|
||||
void AstroWebServer::unRegisterWsCommand(const std::string &cmd)
|
||||
{
|
||||
if (m_webserverCommands.contains(cmd))
|
||||
m_webserverCommands.erase(cmd);
|
||||
}
|
||||
|
||||
void AstroWebServer::onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len)
|
||||
{
|
||||
switch (type)
|
||||
@@ -75,38 +89,13 @@ void AstroWebServer::onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *cli
|
||||
LOG_ERROR("WS Client unable to deserialize Json");
|
||||
return;
|
||||
}
|
||||
if (!doc["cmd"].is<std::string>() || !s_webserverCommands.contains(doc["cmd"]))
|
||||
if (!doc["cmd"].is<std::string>() || !m_webserverCommands.contains(doc["cmd"]))
|
||||
{
|
||||
LOG_WARN("WS Client Invalid Json command [", doc["cmd"].as<std::string>().c_str(), "]");
|
||||
return;
|
||||
}
|
||||
std::string buffer;
|
||||
switch (s_webserverCommands.at(doc["cmd"]))
|
||||
{
|
||||
case SET_TIME:
|
||||
{
|
||||
auto epoch = doc["time"].as<time_t>();
|
||||
timeval te{
|
||||
.tv_sec = epoch,
|
||||
.tv_usec = 0,
|
||||
};
|
||||
timezone tz{
|
||||
.tz_minuteswest = 0,
|
||||
.tz_dsttime = DST_MET,
|
||||
};
|
||||
settimeofday(&te, &tz);
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
buffer.resize(64);
|
||||
strftime(buffer.data(), sizeof(buffer), "%Y-%m-%d %H:%M:%S", t);
|
||||
LOG_DEBUG("WS Client set Datetime to: ", buffer.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
// call external command callback
|
||||
break;
|
||||
}
|
||||
// execute callback function
|
||||
m_webserverCommands[doc["cmd"]](doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,3 +153,23 @@ void AstroWebServer::onUploadHandler(AsyncWebServerRequest *request, const Strin
|
||||
LOG_INFO("Uploaded file to LittleFS:", filename.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void AstroWebServer::onSetTme(const ArduinoJson::JsonDocument &doc)
|
||||
{
|
||||
std::string buffer;
|
||||
auto epoch = doc["time"].as<time_t>();
|
||||
timeval te{
|
||||
.tv_sec = epoch,
|
||||
.tv_usec = 0,
|
||||
};
|
||||
timezone tz{
|
||||
.tz_minuteswest = 0,
|
||||
.tz_dsttime = DST_MET,
|
||||
};
|
||||
settimeofday(&te, &tz);
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
buffer.resize(64);
|
||||
strftime(buffer.data(), sizeof(buffer), "%Y-%m-%d %H:%M:%S", t);
|
||||
LOG_DEBUG("WS Client set Datetime to: ", buffer.c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user