提交 7bbcd69a authored 作者: tobyfan1980's avatar tobyfan1980

correct mqtt response msg when not rebooting

上级 3c7c2d91
...@@ -787,12 +787,14 @@ void handle_mqtt_req(MqttHelper *hlp, const void * const data, int len, string t ...@@ -787,12 +787,14 @@ void handle_mqtt_req(MqttHelper *hlp, const void * const data, int len, string t
/// implementation of cmds /// implementation of cmds
if(cmd == consts::kMsgCmdConfig) { if(cmd == consts::kMsgCmdConfig) {
bool needReboot = false; bool needReboot = false;
// verify configuration
// if request 'data' is empty, it is getting the config, just return current config saved in gJsonConfig
if(data.size() == 0) { if(data.size() == 0) {
MqttMgr::report_response_args(gMqttClient, consts::pub_topic_response + rid, 0, "OK", cmd, rid, gJsonConfig); MqttMgr::report_response_args(gMqttClient, consts::pub_topic_response + rid, 0, "OK", cmd, rid, gJsonConfig);
rlogger->info("local config sent"); rlogger->info("local config sent");
return; return;
} }
// verify configuration
auto rv = verify_config(data); auto rv = verify_config(data);
if(!rv.empty()) { if(!rv.empty()) {
rlogger->error("failed to apply config: {}, {}", rv, data.to_string()); rlogger->error("failed to apply config: {}, {}", rv, data.to_string());
...@@ -806,7 +808,8 @@ void handle_mqtt_req(MqttHelper *hlp, const void * const data, int len, string t ...@@ -806,7 +808,8 @@ void handle_mqtt_req(MqttHelper *hlp, const void * const data, int len, string t
} }
else { else {
// apply diff to tmp and verify // apply diff to tmp and verify
rlogger->info("json diff: {}", patch.to_string()); rlogger->info("config json diff: {}", patch.to_string());
// if mqtt server, file upload server, video gateway url, or detection region is changed, we need to reboot camera
auto strP = patch.to_string(); auto strP = patch.to_string();
if(strP.find("mqtt") != string::npos || strP.find("upload") != string::npos || strP.find("vgw") != string::npos || strP.find("region") != string::npos) { if(strP.find("mqtt") != string::npos || strP.find("upload") != string::npos || strP.find("vgw") != string::npos || strP.find("region") != string::npos) {
needReboot = true; needReboot = true;
...@@ -822,12 +825,15 @@ void handle_mqtt_req(MqttHelper *hlp, const void * const data, int len, string t ...@@ -822,12 +825,15 @@ void handle_mqtt_req(MqttHelper *hlp, const void * const data, int len, string t
MqttMgr::report_response_args(gMqttClient, consts::pub_topic_response + rid, EV_MSG_ERROR_INVALID_PARAM, rc, cmd, rid, data); MqttMgr::report_response_args(gMqttClient, consts::pub_topic_response + rid, EV_MSG_ERROR_INVALID_PARAM, rc, cmd, rid, data);
} }
else { else {
MqttMgr::report_response_args(gMqttClient, consts::pub_topic_response + rid, 0, "rebooting to apply new config", cmd, rid, data);
/// TODO: using json diff to apply change without reboot /// TODO: using json diff to apply change without reboot
save_configuration(data); save_configuration(data);
if(needReboot) { if(needReboot) {
MqttMgr::report_response_args(gMqttClient, consts::pub_topic_response + rid, 0, "rebooting to apply new config", cmd, rid, data);
rlogger->info("rebooting to apply new configuration"); rlogger->info("rebooting to apply new configuration");
LibXmMaQue_System_reboot(); LibXmMaQue_System_reboot();
} else {
MqttMgr::report_response_args(gMqttClient, consts::pub_topic_response + rid, 0, "config change apply without reboot", cmd, rid, patch);
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论