New logger & removed old unused files
This commit is contained in:
@@ -86,11 +86,11 @@ bool SessionAPI<T>::handleMessage(websockets::WebsocketsClient &client, MessageC
|
||||
switch (code)
|
||||
{
|
||||
case MessageCode::START_SESSION:
|
||||
Serial.println("SessionAPI: starting measurement session");
|
||||
LOG_INFO("SessionAPI: starting measurement session");
|
||||
this->sessionManager_.startMeasurements();
|
||||
return true;
|
||||
case MessageCode::STOP_SESSION:
|
||||
Serial.println("SessionAPI: stopping measurement session");
|
||||
LOG_INFO("SessionAPI: stopping measurement session");
|
||||
this->sessionManager_.stopMeasurements();
|
||||
return true;
|
||||
case MessageCode::TARE:
|
||||
|
||||
@@ -48,15 +48,14 @@ public:
|
||||
|
||||
if (server_.poll())
|
||||
{
|
||||
Serial.printf("new websocket connection, storing at pos %d - occupancy: ", nextFreeClient_);
|
||||
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)
|
||||
Serial.print((clients_[i].available()) ? "x" : "o");
|
||||
Serial.print("\n");
|
||||
LOG_INFO((clients_[i].available()) ? "x" : "o");
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_WEBSOCKET_CONNECTIONS; ++i)
|
||||
|
||||
@@ -35,21 +35,21 @@ bool WifiAPI::handleMessage(websockets::WebsocketsClient &client, MessageCode co
|
||||
}
|
||||
if (json.containsKey("reset_to_provisioning") && json["reset_to_provisioning"].as<bool>())
|
||||
{
|
||||
Serial.println("wifi: reset_to_provisioning");
|
||||
LOG_INFO("wifi: reset_to_provisioning");
|
||||
wifiManager_.resetToApProvisioning();
|
||||
restartScheduled_ = true;
|
||||
return true;
|
||||
}
|
||||
else if (json.containsKey("ap_password"))
|
||||
{
|
||||
Serial.println("wifi: ap_password");
|
||||
LOG_INFO("wifi: ap_password");
|
||||
wifiManager_.setApCredentials(json["ap_password"].as<const char *>());
|
||||
restartScheduled_ = true;
|
||||
return true;
|
||||
}
|
||||
else if (json.containsKey("sta_ssid") && json.containsKey("sta_password"))
|
||||
{
|
||||
Serial.println("wifi: sta_ssid");
|
||||
LOG_INFO("wifi: sta_ssid");
|
||||
wifiManager_.setStaCredentials(json["sta_ssid"].as<const char *>(), //
|
||||
json["sta_password"].as<const char *>());
|
||||
restartScheduled_ = true;
|
||||
|
||||
@@ -36,7 +36,7 @@ void WifiAPI::iteration(TServer &server)
|
||||
{
|
||||
if (restartScheduled_)
|
||||
{
|
||||
Serial.print("Restart triggered by WifiAPI");
|
||||
LOG_INFO("Restart triggered by WifiAPI");
|
||||
ESP.restart();
|
||||
}
|
||||
reportScanResultIfAvailable(server);
|
||||
|
||||
@@ -14,19 +14,20 @@
|
||||
#include "WifiManager.h"
|
||||
#include "MockScale.h"
|
||||
#include "Scale.h"
|
||||
#include "MeasurementSession.h"
|
||||
#include "SessionManager.h"
|
||||
#include "SpiffsStorage.h"
|
||||
#include "SimpleMeasurementSession.h"
|
||||
#include "EspHttp.h"
|
||||
#include "WebDAV.h"
|
||||
#include "UserDB.h"
|
||||
#include "Logger.h"
|
||||
|
||||
|
||||
// Api
|
||||
#include "WebsocketServer.h"
|
||||
#include "SessionAPI.h"
|
||||
#include "WifiAPI.h"
|
||||
|
||||
|
||||
using Session_T = SimpleMeasurementSession<MeasurementT, CONFIG_SESSION_MAX_SIZE>;
|
||||
SessionManager<Session_T> sessionManager;
|
||||
|
||||
@@ -55,20 +56,19 @@ String getIdSuffix()
|
||||
bool firmwareUpdate()
|
||||
{
|
||||
esp_http_client_config_t config;
|
||||
Serial.println((char *)certificate_pem);
|
||||
memset(&config, 0, sizeof(esp_http_client_config_t));
|
||||
config.url = UPDATE_URL;
|
||||
config.cert_pem = (char *)certificate_pem;
|
||||
Serial.println("Starting firmware upgrade");
|
||||
LOG_INFO("Starting firmware upgrade");
|
||||
esp_err_t ret = esp_https_ota(&config);
|
||||
if (ret == ESP_OK)
|
||||
{
|
||||
Serial.println("Firmware upgrade successful - restarting");
|
||||
LOG_INFO("Firmware upgrade successful - restarting");
|
||||
esp_restart();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Firmware upgrade failed");
|
||||
LOG_WARNING("Firmware upgrade failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -108,23 +108,23 @@ void httpSetup(SessionManager<SessionT> *sessionManager, WifiManager *wifiManage
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_send(req, "Session started", -1);
|
||||
sessionManager->startMeasurements();
|
||||
Serial.println("Started session");
|
||||
LOG_INFO("RestAPI: Started session");
|
||||
};
|
||||
auto cbStopSession = [sessionManager](httpd_req_t *req)
|
||||
{
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_send(req, "Session stopped", -1);
|
||||
sessionManager->stopMeasurements();
|
||||
Serial.println("Stopped session");
|
||||
LOG_INFO("RestAPI: Stopped session");
|
||||
};
|
||||
auto cbRestart = [](httpd_req_t *req)
|
||||
{
|
||||
Serial.println("Restarted requested");
|
||||
LOG_INFO("RestAPI: Restarted requested");
|
||||
ESP.restart();
|
||||
};
|
||||
auto cbTare = [sessionManager](httpd_req_t *req)
|
||||
{
|
||||
Serial.println("Tare");
|
||||
LOG_INFO("RestAPI: Tare");
|
||||
sessionManager->tare();
|
||||
};
|
||||
auto cbFirmwareUpdate = [](httpd_req_t *req)
|
||||
@@ -409,11 +409,11 @@ void httpSetup(SessionManager<SessionT> *sessionManager, WifiManager *wifiManage
|
||||
espHttpServer.on("/webdav/*?", HTTP_PROPFIND, webdav);
|
||||
espHttpServer.on("/webdav/*?", HTTP_DELETE, webdav);
|
||||
espHttpServer.on("/webdav/*?", HTTP_OPTIONS, webdav);
|
||||
Serial.println("HTTP setup done");
|
||||
LOG_INFO("HTTP setup done");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("HTTP setup with limited API in provisioning mode");
|
||||
LOG_INFO("HTTP setup with limited API in provisioning mode");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,49 +421,47 @@ void mdnsSetup(const String &fullHostname)
|
||||
{
|
||||
if (!MDNS.begin(fullHostname.c_str()))
|
||||
{
|
||||
Serial.println("Error setting up MDNS responder!");
|
||||
LOG_INFO("Error setting up MDNS responder!");
|
||||
while (true)
|
||||
{
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
Serial.printf("mDNS started %s\n", fullHostname.c_str());
|
||||
LOG_INFO("mDNS started %s", fullHostname.c_str());
|
||||
MDNS.addService("swimtracker", "tcp", 81);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Serial
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
{
|
||||
}
|
||||
Logger::init();
|
||||
|
||||
// File system
|
||||
auto millisBeforeSpiffsInit = millis();
|
||||
bool spiffsResult = SPIFFS.begin(true);
|
||||
if (!spiffsResult)
|
||||
Serial.println("Failed to mount/format SPIFFS file system");
|
||||
LOG_WARNING("Failed to mount/format SPIFFS file system");
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
auto spiffsSetupTimeSecs = (millis() - millisBeforeSpiffsInit) / 1000;
|
||||
|
||||
userStorage.init();
|
||||
Serial.printf("Spiffs size: %d MB, setup time %d secs\n", portablefs::totalBytes() / 1024 / 1024, spiffsSetupTimeSecs);
|
||||
LOG_INFO("Spiffs size: %d MB, setup time %ld secs", portablefs::totalBytes() / 1024 / 1024, spiffsSetupTimeSecs);
|
||||
|
||||
// WiFi
|
||||
Preferences prefs;
|
||||
String uniqueName = "swimtracker" + getIdSuffix();
|
||||
String configuredHostname = prefs.getString("hostname", CONFIG_HOSTNAME + getIdSuffix());
|
||||
wifiManager.begin(configuredHostname, uniqueName);
|
||||
Serial.print("Connected to WiFi. IP:");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.printf("WIFI state: %s\n", wifiManager.stateStr());
|
||||
const auto ip = WiFi.localIP();
|
||||
LOG_INFO("Connected to WiFi. IP: %u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
|
||||
LOG_INFO("WIFI state: %s", wifiManager.stateStr());
|
||||
|
||||
mdnsSetup(configuredHostname);
|
||||
|
||||
sessionManagerSetup();
|
||||
Logger::setNtpTime(sessionManager.getNtpTime());
|
||||
sessionManager.tare();
|
||||
|
||||
// HTTP & Websocket server
|
||||
|
||||
Reference in New Issue
Block a user