Commit 669b9888 authored by 957dd's avatar 957dd

解决了重启bug

parent 00652c23
No preview for this file type
...@@ -118,6 +118,7 @@ std::shared_ptr<MqttTopicsHandler> mqtt_init_and_connect() { ...@@ -118,6 +118,7 @@ std::shared_ptr<MqttTopicsHandler> mqtt_init_and_connect() {
[weak_handler = std::weak_ptr<MqttTopicsHandler>(handler)](const std::string& topic, const nlohmann::json& json) { [weak_handler = std::weak_ptr<MqttTopicsHandler>(handler)](const std::string& topic, const nlohmann::json& json) {
std::cout << "收到来自指令主题 [" << topic << "] 的消息。" << std::endl; std::cout << "收到来自指令主题 [" << topic << "] 的消息。" << std::endl;
try { try {
if (json.value("/head/message_type"_json_pointer, 0) == 2011) system("sudo reboot");
if (json.value("/head/message_type"_json_pointer, 0) != 5000) return; if (json.value("/head/message_type"_json_pointer, 0) != 5000) return;
auto dev_id = json.at("body").at("dev_id").get<std::string>(); auto dev_id = json.at("body").at("dev_id").get<std::string>();
...@@ -144,13 +145,6 @@ std::shared_ptr<MqttTopicsHandler> mqtt_init_and_connect() { ...@@ -144,13 +145,6 @@ std::shared_ptr<MqttTopicsHandler> mqtt_init_and_connect() {
shared_handler->AddSubscription(data_topic, shared_handler->AddSubscription(data_topic,
[](const std::string& sub_topic, const nlohmann::json& sub_json) { [](const std::string& sub_topic, const nlohmann::json& sub_json) {
if (sub_json.contains("head") && if (sub_json.contains("head") &&
sub_json["head"].is_object() &&
sub_json["head"].contains("message_type") &&
sub_json["head"]["message_type"].is_number_integer() &&
sub_json["head"]["message_type"].get<int>() == 2011){
system("sudo reboot");
}
if (sub_json.contains("head") &&
sub_json["head"].is_object() && sub_json["head"].is_object() &&
sub_json["head"].contains("message_type") && sub_json["head"].contains("message_type") &&
sub_json["head"]["message_type"].is_number_integer() && sub_json["head"]["message_type"].is_number_integer() &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment