mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-09-26 23:29:14 +08:00
fix: minor bugs related to the Wifi logging
This commit is contained in:
parent
72559dbcb5
commit
dca378c048
@ -81,7 +81,7 @@ void ProjectConfig::wifiConfigSave() {
|
|||||||
std::string ssid = "ssid";
|
std::string ssid = "ssid";
|
||||||
std::string password = "pass";
|
std::string password = "pass";
|
||||||
std::string channel = "channel";
|
std::string channel = "channel";
|
||||||
std::string power = "power";
|
std::string power = "txpower";
|
||||||
for (int i = 0; i < this->config.networks.size(); i++) {
|
for (int i = 0; i < this->config.networks.size(); i++) {
|
||||||
char buffer[2];
|
char buffer[2];
|
||||||
std::string iter_str = Helpers::itoa(i, buffer, 10);
|
std::string iter_str = Helpers::itoa(i, buffer, 10);
|
||||||
@ -122,7 +122,7 @@ void ProjectConfig::mdnsConfigSave() {
|
|||||||
|
|
||||||
void ProjectConfig::wifiTxPowerConfigSave() {
|
void ProjectConfig::wifiTxPowerConfigSave() {
|
||||||
/* Device Config */
|
/* Device Config */
|
||||||
putInt("power", this->config.txpower.power);
|
putInt("txpower", this->config.txpower.power);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectConfig::cameraConfigSave() {
|
void ProjectConfig::cameraConfigSave() {
|
||||||
@ -159,14 +159,16 @@ void ProjectConfig::load() {
|
|||||||
this->config.mdns.service = getString("service").c_str();
|
this->config.mdns.service = getString("service").c_str();
|
||||||
|
|
||||||
/* Wifi TX Power Config */
|
/* Wifi TX Power Config */
|
||||||
this->config.txpower.power = getUInt("power", 52);
|
// 11dBm is the default value
|
||||||
|
this->config.txpower.power = getUInt("txpower", 52);
|
||||||
|
|
||||||
/* WiFi Config */
|
/* WiFi Config */
|
||||||
int networkCount = getInt("networkCount", 0);
|
int networkCount = getInt("networkCount", 0);
|
||||||
std::string name = "name";
|
std::string name = "name";
|
||||||
std::string ssid = "ssid";
|
std::string ssid = "ssid";
|
||||||
std::string password = "pass";
|
std::string password = "pass";
|
||||||
std::string channel = "channel";
|
std::string channel = "channel";
|
||||||
std::string power = "power";
|
std::string power = "txpower";
|
||||||
for (int i = 0; i < networkCount; i++) {
|
for (int i = 0; i < networkCount; i++) {
|
||||||
char buffer[2];
|
char buffer[2];
|
||||||
std::string iter_str = Helpers::itoa(i, buffer, 10);
|
std::string iter_str = Helpers::itoa(i, buffer, 10);
|
||||||
@ -280,7 +282,7 @@ void ProjectConfig::setWifiConfig(const std::string& networkName,
|
|||||||
|
|
||||||
if (shouldNotify) {
|
if (shouldNotify) {
|
||||||
wifiStateManager.setState(WiFiState_e::WiFiState_Disconnected);
|
wifiStateManager.setState(WiFiState_e::WiFiState_Disconnected);
|
||||||
//WiFi.disconnect();
|
// WiFi.disconnect();
|
||||||
this->wifiConfigSave();
|
this->wifiConfigSave();
|
||||||
this->notifyAll(ConfigState_e::networksConfigUpdated);
|
this->notifyAll(ConfigState_e::networksConfigUpdated);
|
||||||
}
|
}
|
||||||
@ -309,7 +311,7 @@ void ProjectConfig::setWifiConfig(const std::string& networkName,
|
|||||||
|
|
||||||
if (shouldNotify) {
|
if (shouldNotify) {
|
||||||
wifiStateManager.setState(WiFiState_e::WiFiState_None);
|
wifiStateManager.setState(WiFiState_e::WiFiState_None);
|
||||||
//WiFi.disconnect();
|
// WiFi.disconnect();
|
||||||
this->wifiConfigSave();
|
this->wifiConfigSave();
|
||||||
this->notifyAll(ConfigState_e::networksConfigUpdated);
|
this->notifyAll(ConfigState_e::networksConfigUpdated);
|
||||||
}
|
}
|
||||||
@ -342,7 +344,6 @@ void ProjectConfig::deleteWifiConfig(const std::string& networkName,
|
|||||||
|
|
||||||
void ProjectConfig::setWiFiTxPower(uint8_t power, bool shouldNotify) {
|
void ProjectConfig::setWiFiTxPower(uint8_t power, bool shouldNotify) {
|
||||||
this->config.txpower.power = power;
|
this->config.txpower.power = power;
|
||||||
|
|
||||||
log_d("Updating wifi tx power");
|
log_d("Updating wifi tx power");
|
||||||
if (shouldNotify)
|
if (shouldNotify)
|
||||||
this->notifyAll(ConfigState_e::wifiTxPowerUpdated);
|
this->notifyAll(ConfigState_e::wifiTxPowerUpdated);
|
||||||
|
@ -100,7 +100,7 @@ void BaseAPI::setWiFi(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.setWifiConfig(networkName, ssid, password, channel, power,
|
projectConfig.setWifiConfig(networkName, ssid, password, channel, power,
|
||||||
adhoc, true);
|
adhoc, true);
|
||||||
|
|
||||||
/* if (WiFiStateManager->getCurrentState() ==
|
/* if (WiFiStateManager->getCurrentState() ==
|
||||||
WiFiState_e::WiFiState_ADHOC)
|
WiFiState_e::WiFiState_ADHOC)
|
||||||
@ -118,8 +118,7 @@ void BaseAPI::setWiFi(AsyncWebServerRequest* request) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DELETE: {
|
case DELETE: {
|
||||||
projectConfig.deleteWifiConfig(request->arg("networkName").c_str(),
|
projectConfig.deleteWifiConfig(request->arg("networkName").c_str(), true);
|
||||||
true);
|
|
||||||
request->send(200, MIMETYPE_JSON,
|
request->send(200, MIMETYPE_JSON,
|
||||||
"{\"msg\":\"Done. Wifi Creds have been deleted.\"}");
|
"{\"msg\":\"Done. Wifi Creds have been deleted.\"}");
|
||||||
break;
|
break;
|
||||||
@ -210,23 +209,7 @@ void BaseAPI::setDeviceConfig(AsyncWebServerRequest* request) {
|
|||||||
|
|
||||||
void BaseAPI::setWiFiTXPower(AsyncWebServerRequest* request) {
|
void BaseAPI::setWiFiTXPower(AsyncWebServerRequest* request) {
|
||||||
switch (_networkMethodsMap_enum[request->method()]) {
|
switch (_networkMethodsMap_enum[request->method()]) {
|
||||||
case GET: {
|
case GET:
|
||||||
int params = request->params();
|
|
||||||
|
|
||||||
uint8_t txPower = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < params; i++) {
|
|
||||||
AsyncWebParameter* param = request->getParam(i);
|
|
||||||
if (param->name() == "txPower") {
|
|
||||||
txPower = atoi(param->value().c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
projectConfig.setWiFiTxPower(txPower, true);
|
|
||||||
projectConfig.wifiTxPowerConfigSave();
|
|
||||||
request->send(200, MIMETYPE_JSON,
|
|
||||||
"{\"msg\":\"Done. TX Power has been set.\"}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case POST: {
|
case POST: {
|
||||||
int params = request->params();
|
int params = request->params();
|
||||||
|
|
||||||
@ -234,7 +217,7 @@ void BaseAPI::setWiFiTXPower(AsyncWebServerRequest* request) {
|
|||||||
|
|
||||||
for (int i = 0; i < params; i++) {
|
for (int i = 0; i < params; i++) {
|
||||||
AsyncWebParameter* param = request->getParam(i);
|
AsyncWebParameter* param = request->getParam(i);
|
||||||
if (param->name() == "txPower") {
|
if (param->name() == "txpower" || param->name() == "txPower") {
|
||||||
txPower = atoi(param->value().c_str());
|
txPower = atoi(param->value().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -308,8 +291,8 @@ void BaseAPI::setCamera(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.setCameraConfig(temp_camera_vflip, temp_camera_framesize,
|
projectConfig.setCameraConfig(temp_camera_vflip, temp_camera_framesize,
|
||||||
temp_camera_hflip, temp_camera_quality,
|
temp_camera_hflip, temp_camera_quality,
|
||||||
temp_camera_brightness, true);
|
temp_camera_brightness, true);
|
||||||
|
|
||||||
request->send(200, MIMETYPE_JSON,
|
request->send(200, MIMETYPE_JSON,
|
||||||
"{\"msg\":\"Done. Camera Settings have been set.\"}");
|
"{\"msg\":\"Done. Camera Settings have been set.\"}");
|
||||||
@ -330,7 +313,7 @@ void BaseAPI::restartCamera(AsyncWebServerRequest* request) {
|
|||||||
request->send(200, MIMETYPE_JSON,
|
request->send(200, MIMETYPE_JSON,
|
||||||
"{\"msg\":\"Done. Camera had been restarted.\"}");
|
"{\"msg\":\"Done. Camera had been restarted.\"}");
|
||||||
}
|
}
|
||||||
#endif // SIM_ENABLED
|
#endif // SIM_ENABLED
|
||||||
|
|
||||||
//*********************************************************************************************
|
//*********************************************************************************************
|
||||||
//! General Command Functions
|
//! General Command Functions
|
||||||
|
@ -56,7 +56,7 @@ void WiFiHandler::begin() {
|
|||||||
for (auto& network : networks) {
|
for (auto& network : networks) {
|
||||||
log_i("Trying to connect to network: %s \n\r", network.ssid.c_str());
|
log_i("Trying to connect to network: %s \n\r", network.ssid.c_str());
|
||||||
if (this->iniSTA(network.ssid, network.password, network.channel,
|
if (this->iniSTA(network.ssid, network.password, network.channel,
|
||||||
(wifi_power_t)txpower.power)) {
|
(wifi_power_t)network.power)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ bool WiFiHandler::iniSTA(const std::string& ssid,
|
|||||||
wifi_power_t power) {
|
wifi_power_t power) {
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
unsigned long startingMillis = currentMillis;
|
unsigned long startingMillis = currentMillis;
|
||||||
int connectionTimeout = 30000; // 30 seconds
|
int connectionTimeout = 45000; // 30 seconds
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
|
|
||||||
wifiStateManager.setState(WiFiState_e::WiFiState_Connecting);
|
wifiStateManager.setState(WiFiState_e::WiFiState_Connecting);
|
||||||
@ -142,6 +142,7 @@ bool WiFiHandler::iniSTA(const std::string& ssid,
|
|||||||
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.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++;
|
||||||
@ -157,7 +158,6 @@ bool WiFiHandler::iniSTA(const std::string& ssid,
|
|||||||
wifiStateManager.setState(WiFiState_e::WiFiState_Connected);
|
wifiStateManager.setState(WiFiState_e::WiFiState_Connected);
|
||||||
log_i("Successfully connected to %s \n\r", ssid.c_str());
|
log_i("Successfully connected to %s \n\r", ssid.c_str());
|
||||||
log_i("Setting TX power to: %d \n\r", (uint8_t)power);
|
log_i("Setting TX power to: %d \n\r", (uint8_t)power);
|
||||||
WiFi.setTxPower(power);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user