mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-19 14:33:45 +02:00
Minor cleanup, add missing command for updating OTA credentials
This commit is contained in:
@@ -5,10 +5,9 @@ std::unordered_map<std::string, CommandType> commandTypeMap = {
|
||||
{"set_wifi", CommandType::SET_WIFI},
|
||||
{"update_wifi", CommandType::UPDATE_WIFI},
|
||||
{"set_streaming_mode", CommandType::SET_STREAMING_MODE},
|
||||
{"update_device", CommandType::UPDATE_DEVICE},
|
||||
{"update_ota_credentials", CommandType::UPDATE_OTA_CREDENTIALS},
|
||||
{"delete_network", CommandType::DELETE_NETWORK},
|
||||
{"update_ap_wifi", CommandType::UPDATE_AP_WIFI},
|
||||
{"update_mdns", CommandType::UPDATE_MDNS},
|
||||
{"set_mdns", CommandType::SET_MDNS},
|
||||
{"update_camera", CommandType::UPDATE_CAMERA},
|
||||
{"restart_camera", CommandType::RESTART_CAMERA},
|
||||
@@ -18,13 +17,15 @@ std::unordered_map<std::string, CommandType> commandTypeMap = {
|
||||
{"restart_device", CommandType::RESTART_DEVICE},
|
||||
};
|
||||
|
||||
std::function<CommandResult()> CommandManager::createCommand(CommandType type, std::string_view json) const {
|
||||
std::function<CommandResult()> CommandManager::createCommand(const CommandType type, std::string_view json) const {
|
||||
switch (type)
|
||||
{
|
||||
case CommandType::PING:
|
||||
return { PingCommand };
|
||||
case CommandType::SET_STREAMING_MODE:
|
||||
case CommandType::SET_STREAMING_MODE:
|
||||
return [this, json] {return setDeviceModeCommand(this->registry, json); };
|
||||
case CommandType::UPDATE_OTA_CREDENTIALS:
|
||||
return [this, json] { return updateOTACredentialsCommand(this->registry, json); };
|
||||
case CommandType::SET_WIFI:
|
||||
return [this, json] { return setWiFiCommand(this->registry, json); };
|
||||
case CommandType::UPDATE_WIFI:
|
||||
@@ -35,9 +36,6 @@ std::function<CommandResult()> CommandManager::createCommand(CommandType type, s
|
||||
return [this, json] { return deleteWiFiCommand(this->registry, json); };
|
||||
case CommandType::SET_MDNS:
|
||||
return [this, json] { return setMDNSCommand(this->registry, json); };
|
||||
// updating the mnds name is essentially the same operation
|
||||
case CommandType::UPDATE_MDNS:
|
||||
return [this, json] { return setMDNSCommand(this->registry, json); };
|
||||
case CommandType::UPDATE_CAMERA:
|
||||
return [this, json] { return updateCameraCommand(this->registry, json); };
|
||||
case CommandType::RESTART_CAMERA:
|
||||
|
||||
@@ -24,12 +24,11 @@ enum class CommandType
|
||||
None,
|
||||
PING,
|
||||
SET_WIFI,
|
||||
UPDATE_DEVICE,
|
||||
UPDATE_OTA_CREDENTIALS,
|
||||
SET_STREAMING_MODE,
|
||||
UPDATE_WIFI,
|
||||
DELETE_NETWORK,
|
||||
UPDATE_AP_WIFI,
|
||||
UPDATE_MDNS,
|
||||
SET_MDNS,
|
||||
UPDATE_CAMERA,
|
||||
RESTART_CAMERA,
|
||||
|
||||
@@ -27,6 +27,39 @@ CommandResult setDeviceModeCommand(std::shared_ptr<DependencyRegistry> registry,
|
||||
return CommandResult::getSuccessResult("Device mode set");
|
||||
}
|
||||
|
||||
CommandResult updateOTACredentialsCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload) {
|
||||
const auto parsedJson = cJSON_Parse(jsonPayload.data());
|
||||
|
||||
if (parsedJson == nullptr) {
|
||||
return CommandResult::getErrorResult("Invalid payload");
|
||||
}
|
||||
|
||||
const auto projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config);
|
||||
const auto oldDeviceConfig = projectConfig->getDeviceConfig();
|
||||
auto OTALogin = oldDeviceConfig.OTALogin;
|
||||
auto OTAPassword = oldDeviceConfig.OTAPassword;
|
||||
auto OTAPort = oldDeviceConfig.OTAPort;
|
||||
|
||||
if (const auto OTALoginObject = cJSON_GetObjectItem(parsedJson, "login"); OTALoginObject != nullptr) {
|
||||
if (const auto newLogin = OTALoginObject->valuestring; strcmp(newLogin, "") != 0) {
|
||||
OTALogin = newLogin;
|
||||
}
|
||||
}
|
||||
|
||||
if (const auto OTAPasswordObject = cJSON_GetObjectItem(parsedJson, s"password"); OTAPasswordObject != nullptr) {
|
||||
OTAPassword = OTAPasswordObject->valuestring;
|
||||
}
|
||||
|
||||
if (const auto OTAPortObject = cJSON_GetObjectItem(parsedJson, "port"); OTAPortObject != nullptr) {
|
||||
if (const auto newPort = OTAPortObject->valueint; newPort >= 82) {
|
||||
OTAPort = newPort;
|
||||
}
|
||||
}
|
||||
|
||||
projectConfig->setDeviceConfig(OTALogin, OTAPassword, OTAPort);
|
||||
return CommandResult::getSuccessResult("OTA Config set");
|
||||
}
|
||||
|
||||
CommandResult restartDeviceCommand() {
|
||||
OpenIrisTasks::ScheduleRestart(2000);
|
||||
return CommandResult::getSuccessResult("Device restarted");
|
||||
|
||||
@@ -4,4 +4,6 @@
|
||||
|
||||
CommandResult setDeviceModeCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
||||
|
||||
CommandResult updateOTACredentialsCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload);
|
||||
|
||||
CommandResult restartDeviceCommand();
|
||||
Reference in New Issue
Block a user