Add set_mdns command to allow the flasher to update the mdns name while setting up the device (#62)

This commit is contained in:
Zdzislaw Goik 2024-03-11 17:09:35 +01:00 committed by GitHub
parent df1e09207a
commit bfcc63f19a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 58 additions and 40 deletions

View File

@ -43,10 +43,8 @@ build_flags =
'-DWIFI_AP_PASSWORD=${wifi.ap_password}'
'-DWIFI_AP_CHANNEL=${wifi.adhocchannel}'
-DOTA_SERVER_PORT=${ota.otaserverport}
'-DOTA_PASSWORD=${ota.otapassword}' ; Set the OTA password
'-DOTA_LOGIN=${ota.otalogin}'
'-DOTA_IP=${ota.otaserverip}' ; Set the OTA password
-O2 ; optimize for speed
-DASYNCWEBSERVER_REGEX ; enable regex in asyncwebserver

View File

@ -21,10 +21,8 @@ build_flags = -DENABLE_ADHOC=${wifi.enableadhoc}
'-DWIFI_AP_CHANNEL=${wifi.adhocchannel}'
'-DVERSION=""'
-DOTA_SERVER_PORT=${ota.otaserverport}
'-DOTA_PASSWORD=${ota.otapassword}' ; Set the OTA password
'-DOTA_LOGIN=${ota.otalogin}'
'-DOTA_IP=${ota.otaserverip}' ; Set the OTA password
-O2 ; optimize for speed
-DASYNCWEBSERVER_REGEX ; enable regex in asyncwebserver

View File

@ -13,7 +13,5 @@ enableadhoc = 0
adhocchannel = 1
[ota]
otaserverip = "openiristracker.local"
otalogin = "openiris"
otapassword = "12345678"
otaserverport = 3232

View File

@ -13,17 +13,21 @@ const CommandType CommandManager::getCommandType(Command &command){
return CommandType::None;
}
bool CommandManager::hasHasDataField(Command &command) {
return command.data.containsKey("data");
}
void CommandManager::handleCommand(Command command) {
auto command_type = this->getCommandType(command);
if (!command.data.containsKey("data"))
// malformed command, lacked data field
return;
switch(command_type)
{
case CommandType::SET_WIFI: {
if (!this->hasHasDataField(command))
// malformed command, lacked data field
break;
if(!command.data["data"].containsKey("ssid") || !command.data["data"].containsKey("password"))
break;
@ -45,6 +49,21 @@ void CommandManager::handleCommand(Command command) {
this->deviceConfig->save();
break;
}
case CommandType::SET_MDNS: {
if (!this->hasHasDataField(command))
break;
if(!command.data["data"].containsKey("hostname") || !strlen(command.data["data"]["hostname"]))
break;
this->deviceConfig->setMDNSConfig(
command.data["data"]["hostname"],
"openiristracker",
false
);
break;
}
case CommandType::PING: {
Serial.println("PONG \n\r");
break;

View File

@ -9,6 +9,7 @@ enum CommandType {
None,
PING,
SET_WIFI,
SET_MDNS,
};
@ -22,10 +23,13 @@ private:
const std::unordered_map<std::string, CommandType> commandMap = {
{"ping", CommandType::PING},
{"set_wifi", CommandType::SET_WIFI},
{"set_mdns", CommandType::SET_MDNS},
};
ProjectConfig* deviceConfig;
bool hasHasDataField(Command &command);
public:
CommandManager(ProjectConfig *deviceConfig);
void handleCommand(Command command);

View File

@ -19,6 +19,7 @@ bool MDNSHandler::startMDNS() {
//! Add service needs leading _ on ESP32 implementation for some reason
//! (according to the docs)
MDNS.addServiceTxt(service.c_str(), "_tcp", "stream_port", "80");
MDNS.addServiceTxt(service.c_str(), "_tcp", "api_port", "81");
log_i("MDNS initialized!");
mdnsStateManager.setState(MDNSState_e::MDNSState_Started);
return true;