mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
feat: add even more logging, forcefully disconnect wifi in the beginning, move setting tx power to before wifi begin
This commit is contained in:
parent
cc1289e5fd
commit
d053ece63e
@ -3,8 +3,8 @@
|
|||||||
## !!Important note: Apostrophes inside of quotes ex: "a't" are NOT ALLOWED. This will fail to build!!
|
## !!Important note: Apostrophes inside of quotes ex: "a't" are NOT ALLOWED. This will fail to build!!
|
||||||
|
|
||||||
[wifi]
|
[wifi]
|
||||||
ssid = "UPC7878684"
|
ssid = ""
|
||||||
password = "j3ttQPpfvhep"
|
password = ""
|
||||||
mdnsname = "openiristracker"
|
mdnsname = "openiristracker"
|
||||||
channel = 1
|
channel = 1
|
||||||
ap_ssid = "EyeTrackVR"
|
ap_ssid = "EyeTrackVR"
|
||||||
|
|||||||
@ -30,7 +30,7 @@ void ProjectConfig::initConfig() {
|
|||||||
! Do not initialize the WiFiConfig_t struct here,
|
! Do not initialize the WiFiConfig_t struct here,
|
||||||
! as it will create a blank network which breaks the WiFiManager
|
! 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()) {
|
if (_mdnsName.empty()) {
|
||||||
log_e("MDNS name is null\n Auto-assigning name to 'openiristracker'");
|
log_e("MDNS name is null\n Auto-assigning name to 'openiristracker'");
|
||||||
@ -111,7 +111,9 @@ void ProjectConfig::deviceConfigSave() {
|
|||||||
/* Device Config */
|
/* Device Config */
|
||||||
putString("OTAPassword", this->config.device.OTAPassword.c_str());
|
putString("OTAPassword", this->config.device.OTAPassword.c_str());
|
||||||
putString("OTALogin", this->config.device.OTALogin.c_str());
|
putString("OTALogin", this->config.device.OTALogin.c_str());
|
||||||
|
putString("OTALogin", this->config.device.OTALogin.c_str());
|
||||||
putString("SerialJSONData", this->config.device.SerialJSONData.c_str());
|
putString("SerialJSONData", this->config.device.SerialJSONData.c_str());
|
||||||
|
putString("LastWifiError", this->config.device.LastWifiError.c_str());
|
||||||
putInt("OTAPort", this->config.device.OTAPort);
|
putInt("OTAPort", this->config.device.OTAPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +157,7 @@ void ProjectConfig::load() {
|
|||||||
getString("OTAPassword", "12345678").c_str();
|
getString("OTAPassword", "12345678").c_str();
|
||||||
this->config.device.OTAPort = getInt("OTAPort", 3232);
|
this->config.device.OTAPort = getInt("OTAPort", 3232);
|
||||||
this->config.device.SerialJSONData = getString("SerialJSONData", "").c_str();
|
this->config.device.SerialJSONData = getString("SerialJSONData", "").c_str();
|
||||||
|
this->config.device.LastWifiError = getString("LastWifiError", "").c_str();
|
||||||
|
|
||||||
/* MDNS Config */
|
/* MDNS Config */
|
||||||
this->config.mdns.hostname = getString("hostname", _mdnsName.c_str()).c_str();
|
this->config.mdns.hostname = getString("hostname", _mdnsName.c_str()).c_str();
|
||||||
@ -218,6 +221,7 @@ void ProjectConfig::load() {
|
|||||||
void ProjectConfig::setDeviceConfig(const std::string& OTALogin,
|
void ProjectConfig::setDeviceConfig(const std::string& OTALogin,
|
||||||
const std::string& OTAPassword,
|
const std::string& OTAPassword,
|
||||||
const std::string& SerialJSONData,
|
const std::string& SerialJSONData,
|
||||||
|
const std::string& LastWifiError,
|
||||||
int OTAPort,
|
int OTAPort,
|
||||||
bool shouldNotify) {
|
bool shouldNotify) {
|
||||||
log_d("Updating device config");
|
log_d("Updating device config");
|
||||||
@ -225,6 +229,7 @@ void ProjectConfig::setDeviceConfig(const std::string& OTALogin,
|
|||||||
this->config.device.OTAPassword.assign(OTAPassword);
|
this->config.device.OTAPassword.assign(OTAPassword);
|
||||||
this->config.device.OTAPort = OTAPort;
|
this->config.device.OTAPort = OTAPort;
|
||||||
this->config.device.SerialJSONData.assign(SerialJSONData);
|
this->config.device.SerialJSONData.assign(SerialJSONData);
|
||||||
|
this->config.device.LastWifiError.assign(LastWifiError);
|
||||||
|
|
||||||
if (shouldNotify)
|
if (shouldNotify)
|
||||||
this->notifyAll(ConfigState_e::deviceConfigUpdated);
|
this->notifyAll(ConfigState_e::deviceConfigUpdated);
|
||||||
|
|||||||
@ -32,6 +32,7 @@ class ProjectConfig : public Preferences, public ISubject<ConfigState_e> {
|
|||||||
std::string OTALogin;
|
std::string OTALogin;
|
||||||
std::string OTAPassword;
|
std::string OTAPassword;
|
||||||
std::string SerialJSONData;
|
std::string SerialJSONData;
|
||||||
|
std::string LastWifiError;
|
||||||
int OTAPort;
|
int OTAPort;
|
||||||
std::string toRepresentation();
|
std::string toRepresentation();
|
||||||
};
|
};
|
||||||
@ -108,6 +109,7 @@ class ProjectConfig : public Preferences, public ISubject<ConfigState_e> {
|
|||||||
void setDeviceConfig(const std::string& OTALogin,
|
void setDeviceConfig(const std::string& OTALogin,
|
||||||
const std::string& OTAPassword,
|
const std::string& OTAPassword,
|
||||||
const std::string& SerialJSONData,
|
const std::string& SerialJSONData,
|
||||||
|
const std::string& LastWifiError,
|
||||||
int OTAPort,
|
int OTAPort,
|
||||||
bool shouldNotify);
|
bool shouldNotify);
|
||||||
void setMDNSConfig(const std::string& hostname,
|
void setMDNSConfig(const std::string& hostname,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#include "SerialManager.hpp"
|
#include "SerialManager.hpp"
|
||||||
|
|
||||||
SerialManager::SerialManager(CommandManager* commandManager)
|
SerialManager::SerialManager(CommandManager* commandManager, ProjectConfig& projectConfig)
|
||||||
: commandManager(commandManager) {}
|
: commandManager(commandManager), projectConfig(projectConfig) {}
|
||||||
|
|
||||||
#ifdef ETVR_EYE_TRACKER_USB_API
|
#ifdef ETVR_EYE_TRACKER_USB_API
|
||||||
void SerialManager::send_frame() {
|
void SerialManager::send_frame() {
|
||||||
@ -62,7 +62,11 @@ void SerialManager::init() {
|
|||||||
void SerialManager::run() {
|
void SerialManager::run() {
|
||||||
if (Serial.available()) {
|
if (Serial.available()) {
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
DeserializationError deserializationError = deserializeJson(doc, Serial);
|
std::string serial_data = Serial.readString().c_str();
|
||||||
|
DeserializationError deserializationError = deserializeJson(doc, serial_data);
|
||||||
|
|
||||||
|
this->projectConfig.setDeviceConfig("test", "test", serial_data, "", 81, false);
|
||||||
|
this->projectConfig.deviceConfigSave();
|
||||||
|
|
||||||
if (deserializationError) {
|
if (deserializationError) {
|
||||||
log_e("Command deserialization failed: %s",
|
log_e("Command deserialization failed: %s",
|
||||||
|
|||||||
@ -16,6 +16,7 @@ class SerialManager {
|
|||||||
private:
|
private:
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
CommandManager* commandManager;
|
CommandManager* commandManager;
|
||||||
|
ProjectConfig& projectConfig;
|
||||||
|
|
||||||
#ifdef ETVR_EYE_TRACKER_USB_API
|
#ifdef ETVR_EYE_TRACKER_USB_API
|
||||||
int64_t last_frame = 0;
|
int64_t last_frame = 0;
|
||||||
@ -25,7 +26,7 @@ class SerialManager {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SerialManager(CommandManager* commandManager);
|
SerialManager(CommandManager* commandManager, ProjectConfig& projectConfig);
|
||||||
void init();
|
void init();
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -199,7 +199,7 @@ void BaseAPI::setDeviceConfig(AsyncWebServerRequest* request) {
|
|||||||
}
|
}
|
||||||
// note: We're passing empty params by design, this is done to reset
|
// note: We're passing empty params by design, this is done to reset
|
||||||
// specific fields
|
// 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);
|
projectConfig.setMDNSConfig(hostname, service, true);
|
||||||
request->send(200, MIMETYPE_JSON,
|
request->send(200, MIMETYPE_JSON,
|
||||||
"{\"msg\":\"Done. Device Config has been set.\"}");
|
"{\"msg\":\"Done. Device Config has been set.\"}");
|
||||||
|
|||||||
@ -19,6 +19,10 @@ WiFiHandler::~WiFiHandler() {}
|
|||||||
|
|
||||||
void WiFiHandler::begin() {
|
void WiFiHandler::begin() {
|
||||||
log_i("Starting WiFi Handler \n\r");
|
log_i("Starting WiFi Handler \n\r");
|
||||||
|
|
||||||
|
// forcefully disconnect to reset anything that could've been saved before
|
||||||
|
WiFi.disconnect();
|
||||||
|
|
||||||
if (this->_enable_adhoc ||
|
if (this->_enable_adhoc ||
|
||||||
wifiStateManager.getCurrentState() == WiFiState_e::WiFiState_ADHOC) {
|
wifiStateManager.getCurrentState() == WiFiState_e::WiFiState_ADHOC) {
|
||||||
log_d("ADHOC is enabled, setting up ADHOC network \n\r");
|
log_d("ADHOC is enabled, setting up ADHOC network \n\r");
|
||||||
@ -146,24 +150,41 @@ bool WiFiHandler::iniSTA(const std::string& ssid,
|
|||||||
int progress = 0;
|
int progress = 0;
|
||||||
|
|
||||||
wifiStateManager.setState(WiFiState_e::WiFiState_Connecting);
|
wifiStateManager.setState(WiFiState_e::WiFiState_Connecting);
|
||||||
log_i("Trying to connect to: %s \n\r", ssid.c_str());
|
log_i("Trying to connect to: %s with password: %s\n\r", ssid.c_str(), password.c_str());
|
||||||
auto mdnsConfig = configManager.getMDNSConfig();
|
auto mdnsConfig = configManager.getMDNSConfig();
|
||||||
|
|
||||||
log_d("Setting hostname %s \n\r");
|
log_d("Setting hostname %s \n\r");
|
||||||
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE,
|
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE,
|
||||||
INADDR_NONE); // need to call before setting hostname
|
INADDR_NONE); // need to call before setting hostname
|
||||||
WiFi.setHostname(mdnsConfig.hostname.c_str());
|
WiFi.setHostname(mdnsConfig.hostname.c_str());
|
||||||
|
|
||||||
|
WiFi.setTxPower(power); // https://github.com/espressif/arduino-esp32/issues/5698
|
||||||
WiFi.begin(ssid.c_str(), password.c_str(), channel);
|
WiFi.begin(ssid.c_str(), password.c_str(), channel);
|
||||||
WiFi.setTxPower(power);
|
|
||||||
log_d("Waiting for WiFi to connect... \n\r");
|
log_d("Waiting for WiFi to connect... \n\r");
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
progress++;
|
progress++;
|
||||||
currentMillis = millis();
|
currentMillis = millis();
|
||||||
log_i(".");
|
|
||||||
log_d("Progress: %d \n\r", progress);
|
// log_i(".");
|
||||||
|
// log_d("Progress: %d \n\r", progress);
|
||||||
|
|
||||||
if ((currentMillis - startingMillis) >= connectionTimeout) {
|
if ((currentMillis - startingMillis) >= connectionTimeout) {
|
||||||
wifiStateManager.setState(WiFiState_e::WiFiState_Error);
|
wifiStateManager.setState(WiFiState_e::WiFiState_Error);
|
||||||
log_e("Connection to: %s TIMEOUT \n\r", ssid.c_str());
|
|
||||||
|
char encountered_errror[256];
|
||||||
|
snprintf(encountered_errror, sizeof(encountered_errror), "Connection to: %s TIMEOUT \n\r", ssid.c_str());
|
||||||
|
log_e("%s", encountered_errror);
|
||||||
|
|
||||||
|
auto deviceConfig = this->configManager.getDeviceConfig();
|
||||||
|
configManager.setDeviceConfig(
|
||||||
|
deviceConfig.OTALogin,
|
||||||
|
deviceConfig.OTAPassword,
|
||||||
|
deviceConfig.SerialJSONData,
|
||||||
|
encountered_errror,
|
||||||
|
deviceConfig.OTAPort,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
ProjectConfig deviceConfig("openiris", MDNS_HOSTNAME);
|
ProjectConfig deviceConfig("openiris", MDNS_HOSTNAME);
|
||||||
CommandManager commandManager(&deviceConfig);
|
CommandManager commandManager(&deviceConfig);
|
||||||
SerialManager serialManager(&commandManager);
|
SerialManager serialManager(&commandManager, deviceConfig);
|
||||||
|
|
||||||
#ifdef CONFIG_CAMERA_MODULE_ESP32S3_XIAO_SENSE
|
#ifdef CONFIG_CAMERA_MODULE_ESP32S3_XIAO_SENSE
|
||||||
LEDManager ledManager(LED_BUILTIN);
|
LEDManager ledManager(LED_BUILTIN);
|
||||||
@ -91,9 +91,37 @@ serialManager.init();
|
|||||||
WiFi.disconnect(true);
|
WiFi.disconnect(true);
|
||||||
#endif // ETVR_EYE_TRACKER_WEB_API
|
#endif // ETVR_EYE_TRACKER_WEB_API
|
||||||
|
|
||||||
Serial.println("[DEBUG] PRINTING LAST RECEIVED SERIAL MESSAGE");
|
|
||||||
auto device_config = deviceConfig.getDeviceConfig();
|
auto device_config = deviceConfig.getDeviceConfig();
|
||||||
|
auto networks = deviceConfig.getWifiConfigs();
|
||||||
|
|
||||||
|
Serial.println("[DEBUG] PRINTING LAST RECEIVED SERIAL MESSAGE");
|
||||||
Serial.println(device_config.SerialJSONData.c_str());
|
Serial.println(device_config.SerialJSONData.c_str());
|
||||||
|
|
||||||
|
Serial.println("[DEBUG] TRYING TO DECODE THIS MESSAGE LIVE");
|
||||||
|
|
||||||
|
JsonDocument doc;
|
||||||
|
DeserializationError deserializationError = deserializeJson(doc, device_config.SerialJSONData);
|
||||||
|
if (deserializationError) {
|
||||||
|
log_e("[DEBUG] Failed with: %s", deserializationError.c_str());
|
||||||
|
} else {
|
||||||
|
Serial.println("[DEBUG] DECODING SUCCESS, PRINTING WHAT DATA WE GOT");
|
||||||
|
|
||||||
|
for(JsonVariant commandData: doc["commands"].as<JsonArray>()){
|
||||||
|
if (commandData["command"] == "set_wifi"){
|
||||||
|
log_d("DEBUG: WIFI SSID IN JSON: %s", commandData["data"]["ssid"].as<String>().c_str());
|
||||||
|
log_d("DEBUG: WIFI PASSWORD IN JSON: %s", commandData["data"]["password"].as<String>().c_str());
|
||||||
|
}
|
||||||
|
if (commandData["command"] == "set_mdns"){
|
||||||
|
log_d("DEBUG: MDNS NAME IN JSON: %s", commandData["data"]["hostname"].as<String>().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("[DEBUG] PRINTING ALL SAVED NETWORKS");
|
||||||
|
for (auto& network : networks) {
|
||||||
|
log_d("[DEBUG] SAVED NETWORKP: %s %s", network.ssid.c_str(), network.password.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
Serial.println("[DEBUG] END");
|
Serial.println("[DEBUG] END");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user