diff --git a/ESP/lib/src/data/config/project_config.cpp b/ESP/lib/src/data/config/project_config.cpp index 9154b1e..c927534 100644 --- a/ESP/lib/src/data/config/project_config.cpp +++ b/ESP/lib/src/data/config/project_config.cpp @@ -30,7 +30,7 @@ void ProjectConfig::initConfig() { ! Do not initialize the WiFiConfig_t struct here, ! as it will create a blank network which breaks the WiFiManager */ - this->config.device = {OTA_LOGIN, OTA_PASSWORD, 3232}; + this->config.device = {OTA_LOGIN, OTA_PASSWORD, "", 3232}; if (_mdnsName.empty()) { log_e("MDNS name is null\n Auto-assigning name to 'openiristracker'"); @@ -111,6 +111,7 @@ void ProjectConfig::deviceConfigSave() { /* Device Config */ putString("OTAPassword", this->config.device.OTAPassword.c_str()); putString("OTALogin", this->config.device.OTALogin.c_str()); + putString("SerialJSONData", this->config.device.SerialJSONData.c_str()); putInt("OTAPort", this->config.device.OTAPort); } @@ -153,6 +154,7 @@ void ProjectConfig::load() { this->config.device.OTAPassword = getString("OTAPassword", "12345678").c_str(); this->config.device.OTAPort = getInt("OTAPort", 3232); + this->config.device.SerialJSONData = getString("SerialJSONData", "").c_str(); /* MDNS Config */ this->config.mdns.hostname = getString("hostname", _mdnsName.c_str()).c_str(); @@ -215,12 +217,14 @@ void ProjectConfig::load() { //********************************************************************************************************************** void ProjectConfig::setDeviceConfig(const std::string& OTALogin, const std::string& OTAPassword, + const std::string& SerialJSONData, int OTAPort, bool shouldNotify) { log_d("Updating device config"); this->config.device.OTALogin.assign(OTALogin); this->config.device.OTAPassword.assign(OTAPassword); this->config.device.OTAPort = OTAPort; + this->config.device.SerialJSONData.assign(SerialJSONData); if (shouldNotify) this->notifyAll(ConfigState_e::deviceConfigUpdated); diff --git a/ESP/lib/src/data/config/project_config.hpp b/ESP/lib/src/data/config/project_config.hpp index a2a5c99..3201830 100644 --- a/ESP/lib/src/data/config/project_config.hpp +++ b/ESP/lib/src/data/config/project_config.hpp @@ -31,6 +31,7 @@ class ProjectConfig : public Preferences, public ISubject { struct DeviceConfig_t { std::string OTALogin; std::string OTAPassword; + std::string SerialJSONData; int OTAPort; std::string toRepresentation(); }; @@ -106,6 +107,7 @@ class ProjectConfig : public Preferences, public ISubject { void setDeviceConfig(const std::string& OTALogin, const std::string& OTAPassword, + const std::string& SerialJSONData, int OTAPort, bool shouldNotify); void setMDNSConfig(const std::string& hostname, diff --git a/ESP/lib/src/io/Serial/SerialManager.cpp b/ESP/lib/src/io/Serial/SerialManager.cpp index 6466d3d..5abebeb 100644 --- a/ESP/lib/src/io/Serial/SerialManager.cpp +++ b/ESP/lib/src/io/Serial/SerialManager.cpp @@ -1,7 +1,7 @@ #include "SerialManager.hpp" -SerialManager::SerialManager(CommandManager* commandManager) - : commandManager(commandManager) {} +SerialManager::SerialManager(CommandManager* commandManager, ProjectConfig& configManager) + : commandManager(commandManager), configManager(configManager) {} #ifdef ETVR_EYE_TRACKER_USB_API void SerialManager::send_frame() { @@ -61,8 +61,9 @@ void SerialManager::init() { void SerialManager::run() { if (Serial.available()) { + auto serialData = Serial.readString(); JsonDocument doc; - DeserializationError deserializationError = deserializeJson(doc, Serial); + DeserializationError deserializationError = deserializeJson(doc, serialData); if (deserializationError) { log_e("Command deserialization failed: %s", @@ -70,7 +71,11 @@ void SerialManager::run() { } Command command = {doc}; + + configManager.setDeviceConfig("", "", serialData.c_str(), 81, true); + configManager.deviceConfigSave(); this->commandManager->handleCommand(command); + configManager.save(); // in case we receive something totally different than supported command, save anyway and restart } #ifdef ETVR_EYE_TRACKER_USB_API else { diff --git a/ESP/lib/src/io/Serial/SerialManager.hpp b/ESP/lib/src/io/Serial/SerialManager.hpp index f21d31a..bfc513f 100644 --- a/ESP/lib/src/io/Serial/SerialManager.hpp +++ b/ESP/lib/src/io/Serial/SerialManager.hpp @@ -16,6 +16,7 @@ class SerialManager { private: esp_err_t err = ESP_OK; CommandManager* commandManager; + ProjectConfig& configManager; #ifdef ETVR_EYE_TRACKER_USB_API int64_t last_frame = 0; @@ -25,9 +26,9 @@ class SerialManager { #endif public: - SerialManager(CommandManager* commandManager); + SerialManager(CommandManager* commandManager, ProjectConfig& configManager); void init(); void run(); }; -#endif \ No newline at end of file +#endif diff --git a/ESP/lib/src/network/api/baseAPI/baseAPI.cpp b/ESP/lib/src/network/api/baseAPI/baseAPI.cpp index d3ce808..5d98c1e 100644 --- a/ESP/lib/src/network/api/baseAPI/baseAPI.cpp +++ b/ESP/lib/src/network/api/baseAPI/baseAPI.cpp @@ -199,7 +199,7 @@ void BaseAPI::setDeviceConfig(AsyncWebServerRequest* request) { } // note: We're passing empty params by design, this is done to reset // specific fields - projectConfig.setDeviceConfig(ota_login, ota_password, ota_port, true); + projectConfig.setDeviceConfig(ota_login, ota_password, "", ota_port, true); projectConfig.setMDNSConfig(hostname, service, true); request->send(200, MIMETYPE_JSON, "{\"msg\":\"Done. Device Config has been set.\"}"); diff --git a/ESP/src/main.cpp b/ESP/src/main.cpp index d37ded7..5d52531 100644 --- a/ESP/src/main.cpp +++ b/ESP/src/main.cpp @@ -7,7 +7,7 @@ */ ProjectConfig deviceConfig("openiris", MDNS_HOSTNAME); CommandManager commandManager(&deviceConfig); -SerialManager serialManager(&commandManager); +SerialManager serialManager(&commandManager, deviceConfig); #ifdef CONFIG_CAMERA_MODULE_ESP32S3_XIAO_SENSE LEDManager ledManager(LED_BUILTIN); @@ -90,6 +90,11 @@ serialManager.init(); #else // ETVR_EYE_TRACKER_WEB_API WiFi.disconnect(true); #endif // ETVR_EYE_TRACKER_WEB_API + +Serial.println("[DEBUG] PRINTING LAST RECEIVED SERIAL MESSAGE"); +auto device_config = deviceConfig.getDeviceConfig(); +Serial.println(device_config.SerialJSONData.c_str()); +Serial.println("[DEBUG] END"); } void loop() {