mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
Add set_mdns command to allow the flasher to update the mdns name while setting up the device (#62)
This commit is contained in:
parent
df1e09207a
commit
bfcc63f19a
@ -43,10 +43,8 @@ build_flags =
|
|||||||
'-DWIFI_AP_PASSWORD=${wifi.ap_password}'
|
'-DWIFI_AP_PASSWORD=${wifi.ap_password}'
|
||||||
'-DWIFI_AP_CHANNEL=${wifi.adhocchannel}'
|
'-DWIFI_AP_CHANNEL=${wifi.adhocchannel}'
|
||||||
|
|
||||||
-DOTA_SERVER_PORT=${ota.otaserverport}
|
|
||||||
'-DOTA_PASSWORD=${ota.otapassword}' ; Set the OTA password
|
'-DOTA_PASSWORD=${ota.otapassword}' ; Set the OTA password
|
||||||
'-DOTA_LOGIN=${ota.otalogin}'
|
'-DOTA_LOGIN=${ota.otalogin}'
|
||||||
'-DOTA_IP=${ota.otaserverip}' ; Set the OTA password
|
|
||||||
|
|
||||||
-O2 ; optimize for speed
|
-O2 ; optimize for speed
|
||||||
-DASYNCWEBSERVER_REGEX ; enable regex in asyncwebserver
|
-DASYNCWEBSERVER_REGEX ; enable regex in asyncwebserver
|
||||||
|
|||||||
@ -21,10 +21,8 @@ build_flags = -DENABLE_ADHOC=${wifi.enableadhoc}
|
|||||||
'-DWIFI_AP_CHANNEL=${wifi.adhocchannel}'
|
'-DWIFI_AP_CHANNEL=${wifi.adhocchannel}'
|
||||||
'-DVERSION=""'
|
'-DVERSION=""'
|
||||||
|
|
||||||
-DOTA_SERVER_PORT=${ota.otaserverport}
|
|
||||||
'-DOTA_PASSWORD=${ota.otapassword}' ; Set the OTA password
|
'-DOTA_PASSWORD=${ota.otapassword}' ; Set the OTA password
|
||||||
'-DOTA_LOGIN=${ota.otalogin}'
|
'-DOTA_LOGIN=${ota.otalogin}'
|
||||||
'-DOTA_IP=${ota.otaserverip}' ; Set the OTA password
|
|
||||||
|
|
||||||
-O2 ; optimize for speed
|
-O2 ; optimize for speed
|
||||||
-DASYNCWEBSERVER_REGEX ; enable regex in asyncwebserver
|
-DASYNCWEBSERVER_REGEX ; enable regex in asyncwebserver
|
||||||
|
|||||||
@ -13,7 +13,5 @@ enableadhoc = 0
|
|||||||
adhocchannel = 1
|
adhocchannel = 1
|
||||||
|
|
||||||
[ota]
|
[ota]
|
||||||
otaserverip = "openiristracker.local"
|
|
||||||
otalogin = "openiris"
|
otalogin = "openiris"
|
||||||
otapassword = "12345678"
|
otapassword = "12345678"
|
||||||
otaserverport = 3232
|
|
||||||
|
|||||||
@ -13,43 +13,62 @@ const CommandType CommandManager::getCommandType(Command &command){
|
|||||||
return CommandType::None;
|
return CommandType::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CommandManager::hasHasDataField(Command &command) {
|
||||||
|
return command.data.containsKey("data");
|
||||||
|
}
|
||||||
|
|
||||||
void CommandManager::handleCommand(Command command) {
|
void CommandManager::handleCommand(Command command) {
|
||||||
auto command_type = this->getCommandType(command);
|
auto command_type = this->getCommandType(command);
|
||||||
|
|
||||||
if (!command.data.containsKey("data"))
|
|
||||||
// malformed command, lacked data field
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch(command_type)
|
switch(command_type)
|
||||||
{
|
{
|
||||||
case CommandType::SET_WIFI: {
|
case CommandType::SET_WIFI: {
|
||||||
if(!command.data["data"].containsKey("ssid") || !command.data["data"].containsKey("password"))
|
if (!this->hasHasDataField(command))
|
||||||
|
// malformed command, lacked data field
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
if(!command.data["data"].containsKey("ssid") || !command.data["data"].containsKey("password"))
|
||||||
|
break;
|
||||||
|
|
||||||
|
std::string customNetworkName = "main";
|
||||||
|
if (command.data["data"].containsKey("network_name"))
|
||||||
|
customNetworkName = command.data["data"]["network_name"].as<std::string>();
|
||||||
|
|
||||||
|
this->deviceConfig->setWifiConfig(
|
||||||
|
customNetworkName,
|
||||||
|
command.data["data"]["ssid"],
|
||||||
|
command.data["data"]["password"],
|
||||||
|
0, // channel, should this be zero?
|
||||||
|
0, // power, should this be zero?
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
// we purposefully save here
|
||||||
|
this->deviceConfig->save();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case CommandType::SET_MDNS: {
|
||||||
|
if (!this->hasHasDataField(command))
|
||||||
|
break;
|
||||||
|
|
||||||
std::string customNetworkName = "main";
|
if(!command.data["data"].containsKey("hostname") || !strlen(command.data["data"]["hostname"]))
|
||||||
if (command.data["data"].containsKey("network_name"))
|
break;
|
||||||
customNetworkName = command.data["data"]["network_name"].as<std::string>();
|
|
||||||
|
|
||||||
this->deviceConfig->setWifiConfig(
|
this->deviceConfig->setMDNSConfig(
|
||||||
customNetworkName,
|
command.data["data"]["hostname"],
|
||||||
command.data["data"]["ssid"],
|
"openiristracker",
|
||||||
command.data["data"]["password"],
|
false
|
||||||
0, // channel, should this be zero?
|
);
|
||||||
0, // power, should this be zero?
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
// we purposefully save here
|
break;
|
||||||
this->deviceConfig->save();
|
}
|
||||||
break;
|
case CommandType::PING: {
|
||||||
}
|
Serial.println("PONG \n\r");
|
||||||
case CommandType::PING: {
|
break;
|
||||||
Serial.println("PONG \n\r");
|
}
|
||||||
break;
|
default:
|
||||||
}
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9,6 +9,7 @@ enum CommandType {
|
|||||||
None,
|
None,
|
||||||
PING,
|
PING,
|
||||||
SET_WIFI,
|
SET_WIFI,
|
||||||
|
SET_MDNS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -22,10 +23,13 @@ private:
|
|||||||
const std::unordered_map<std::string, CommandType> commandMap = {
|
const std::unordered_map<std::string, CommandType> commandMap = {
|
||||||
{"ping", CommandType::PING},
|
{"ping", CommandType::PING},
|
||||||
{"set_wifi", CommandType::SET_WIFI},
|
{"set_wifi", CommandType::SET_WIFI},
|
||||||
|
{"set_mdns", CommandType::SET_MDNS},
|
||||||
};
|
};
|
||||||
|
|
||||||
ProjectConfig* deviceConfig;
|
ProjectConfig* deviceConfig;
|
||||||
|
|
||||||
|
bool hasHasDataField(Command &command);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CommandManager(ProjectConfig *deviceConfig);
|
CommandManager(ProjectConfig *deviceConfig);
|
||||||
void handleCommand(Command command);
|
void handleCommand(Command command);
|
||||||
|
|||||||
@ -19,6 +19,7 @@ bool MDNSHandler::startMDNS() {
|
|||||||
//! Add service needs leading _ on ESP32 implementation for some reason
|
//! Add service needs leading _ on ESP32 implementation for some reason
|
||||||
//! (according to the docs)
|
//! (according to the docs)
|
||||||
MDNS.addServiceTxt(service.c_str(), "_tcp", "stream_port", "80");
|
MDNS.addServiceTxt(service.c_str(), "_tcp", "stream_port", "80");
|
||||||
|
MDNS.addServiceTxt(service.c_str(), "_tcp", "api_port", "81");
|
||||||
log_i("MDNS initialized!");
|
log_i("MDNS initialized!");
|
||||||
mdnsStateManager.setState(MDNSState_e::MDNSState_Started);
|
mdnsStateManager.setState(MDNSState_e::MDNSState_Started);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user