diff --git a/DeviceActivate/bin/init b/DeviceActivate/bin/init index a8d35ec..9876def 100755 Binary files a/DeviceActivate/bin/init and b/DeviceActivate/bin/init differ diff --git a/DeviceActivate/src/main.cpp b/DeviceActivate/src/main.cpp index 59e3cee..561ee47 100644 --- a/DeviceActivate/src/main.cpp +++ b/DeviceActivate/src/main.cpp @@ -22,10 +22,12 @@ const string envPath = "/home/orangepi/RKApp/InitAuth/conf/.env"; // MQTT相关配置 const string mqtt_url = "tcp://192.168.12.1:1883"; const string clientId = "RK3588_SubTest"; -const string Topic = "/bsd_camera/cmd"; +const string TopicRecv = "/bsd_camera/cmd"; // 接收手机传来的信息 +const string TopicSend = "/bsd_camera/init"; // 发送的话题 const int Qos = 1; atomic isRunning(true); +atomic Deactivate(false); // 激活标志 mqtt::async_client client(mqtt_url, clientId); @@ -45,12 +47,17 @@ void messageCallback(mqtt::const_message_ptr msg); // 检测设备是否已进行初始化 bool checkUUID(); +// 退出程序,开始进行设备验证 +void StartCheck(); + int main() { - if (checkUUID()) + Deactivate = checkUUID(); // 判断是否已被激活 + if (Deactivate) { // 设备已被激活,调用验证程序,退出本程序 - + cout << "设备已激活,开始验证" << endl; + StartCheck(); return 0; } @@ -64,6 +71,14 @@ int main() return 0; } +// 退出程序,开始进行设备验证 +void StartCheck() +{ + isRunning = false; // 退出程序 + string cmd = "../../softWareInit/bin/wifi "; + system(cmd.c_str()); +} + // 检测设备是否已经激活 bool checkUUID() { @@ -98,19 +113,21 @@ void messageCallback(mqtt::const_message_ptr msg) { // 接受App传来的密文,并保存在配置文件中 auto buffer = msg->to_string(); - cout << "msg: " << buffer << endl; + // cout << "Topic:" << msg->get_topic() << ",msg:" << buffer << endl; if (buffer.find("Activate") != string::npos) { // 接受请求,发送SIM卡号 string ICCID = GetSimICCID(); - client.publish(Topic, ICCID, Qos, false); // 不保存 + string deviceId = format("{\"deviceUid\":\"{}\"}", ICCID); + // cout << "ICCID:" << deviceId << endl; + client.publish(TopicSend, deviceId, Qos, false); // 不保存 } else if (buffer.find("ServerPwd") != string::npos) { // 接受UUID,保存至配置文件中,退出程序,调用设备验证程序 auto res = nlohmann::json::parse(buffer); // 准备解析接受到的秘钥 - auto pwd = res["Data"]; - cout << pwd << endl; + auto pwd = res["Data"]; + // cout << pwd << endl; // 写入文件 ReadFile rf(envPath); @@ -127,16 +144,23 @@ void messageCallback(mqtt::const_message_ptr msg) { WriteFile wf(envPath); string out; - out.resize(1024); + out.reserve(1024); for (size_t i = 0; i < lines.size(); ++i) { out += lines[i]; if (i + 1 < lines.size()) out += "\n"; } - wf.overwriteText(out); }) + wf.overwriteText(out); + + Deactivate =true; }) .detach(); } + + if (Deactivate) + { // 已激活 + StartCheck(); + } } // 连接成功的回调 @@ -150,8 +174,8 @@ void mqttInit() client.set_message_callback(messageCallback); client.set_connected_handler(connectCallback); - client.connect()->wait(); // 进行连接 - client.subscribe(Topic, Qos)->wait(); // 订阅话题 + client.connect()->wait(); // 进行连接 + client.subscribe(TopicRecv, Qos)->wait(); // 订阅话题 } // 获取SIM卡号 diff --git a/InitAuth/conf/.env b/InitAuth/conf/.env index 8c99c7e..9921c4a 100644 --- a/InitAuth/conf/.env +++ b/InitAuth/conf/.env @@ -2,7 +2,7 @@ UUID:null #以下配置用于获取云端发送秘钥 -ServerPwd:null +ServerPwd:"17227ca72f30f8bca8158bb78f25b43e" #以下配置存储报警输出高低电平 outSignal:low \ No newline at end of file diff --git a/ApCreate/NetraLib/README.md b/softWareInit/NetraLib/README.md similarity index 100% rename from ApCreate/NetraLib/README.md rename to softWareInit/NetraLib/README.md diff --git a/ApCreate/NetraLib/include/NetRequest.hpp b/softWareInit/NetraLib/include/NetRequest.hpp similarity index 100% rename from ApCreate/NetraLib/include/NetRequest.hpp rename to softWareInit/NetraLib/include/NetRequest.hpp diff --git a/ApCreate/NetraLib/include/Netra.hpp b/softWareInit/NetraLib/include/Netra.hpp similarity index 100% rename from ApCreate/NetraLib/include/Netra.hpp rename to softWareInit/NetraLib/include/Netra.hpp diff --git a/ApCreate/NetraLib/include/QCL_Include.hpp b/softWareInit/NetraLib/include/QCL_Include.hpp similarity index 100% rename from ApCreate/NetraLib/include/QCL_Include.hpp rename to softWareInit/NetraLib/include/QCL_Include.hpp diff --git a/ApCreate/NetraLib/include/README.md b/softWareInit/NetraLib/include/README.md similarity index 100% rename from ApCreate/NetraLib/include/README.md rename to softWareInit/NetraLib/include/README.md diff --git a/ApCreate/NetraLib/include/encrypt.hpp b/softWareInit/NetraLib/include/encrypt.hpp similarity index 100% rename from ApCreate/NetraLib/include/encrypt.hpp rename to softWareInit/NetraLib/include/encrypt.hpp diff --git a/ApCreate/NetraLib/include/httplib.h b/softWareInit/NetraLib/include/httplib.h similarity index 100% rename from ApCreate/NetraLib/include/httplib.h rename to softWareInit/NetraLib/include/httplib.h diff --git a/ApCreate/NetraLib/src/NetRequest.cpp b/softWareInit/NetraLib/src/NetRequest.cpp similarity index 100% rename from ApCreate/NetraLib/src/NetRequest.cpp rename to softWareInit/NetraLib/src/NetRequest.cpp diff --git a/ApCreate/NetraLib/src/Netra.cpp b/softWareInit/NetraLib/src/Netra.cpp similarity index 100% rename from ApCreate/NetraLib/src/Netra.cpp rename to softWareInit/NetraLib/src/Netra.cpp diff --git a/ApCreate/NetraLib/src/encrypt.cpp b/softWareInit/NetraLib/src/encrypt.cpp similarity index 100% rename from ApCreate/NetraLib/src/encrypt.cpp rename to softWareInit/NetraLib/src/encrypt.cpp diff --git a/ApCreate/RTSPServer/LICENSE b/softWareInit/RTSPServer/LICENSE similarity index 100% rename from ApCreate/RTSPServer/LICENSE rename to softWareInit/RTSPServer/LICENSE diff --git a/ApCreate/RTSPServer/mediamtx b/softWareInit/RTSPServer/mediamtx similarity index 100% rename from ApCreate/RTSPServer/mediamtx rename to softWareInit/RTSPServer/mediamtx diff --git a/ApCreate/RTSPServer/mediamtx.yml b/softWareInit/RTSPServer/mediamtx.yml similarity index 100% rename from ApCreate/RTSPServer/mediamtx.yml rename to softWareInit/RTSPServer/mediamtx.yml diff --git a/ApCreate/RTSPServer/mediamtx_v1.13.1_linux_arm64.tar.gz b/softWareInit/RTSPServer/mediamtx_v1.13.1_linux_arm64.tar.gz similarity index 100% rename from ApCreate/RTSPServer/mediamtx_v1.13.1_linux_arm64.tar.gz rename to softWareInit/RTSPServer/mediamtx_v1.13.1_linux_arm64.tar.gz diff --git a/ApCreate/bin/ap b/softWareInit/bin/ap similarity index 100% rename from ApCreate/bin/ap rename to softWareInit/bin/ap diff --git a/ApCreate/bin/wifi b/softWareInit/bin/wifi similarity index 100% rename from ApCreate/bin/wifi rename to softWareInit/bin/wifi diff --git a/ApCreate/src/createAp.cpp b/softWareInit/src/createAp.cpp similarity index 100% rename from ApCreate/src/createAp.cpp rename to softWareInit/src/createAp.cpp diff --git a/ApCreate/src/main.cpp b/softWareInit/src/main.cpp similarity index 85% rename from ApCreate/src/main.cpp rename to softWareInit/src/main.cpp index b1fe8e0..145d940 100644 --- a/ApCreate/src/main.cpp +++ b/softWareInit/src/main.cpp @@ -1,8 +1,9 @@ /* -本程序提供以下功能: -1.初始化4G模块,提供网络功能 -2.进行RTSP推流 -3.进行设备验证,通过后,启动系统各项服务 +本程序用于设备验证 +验证通过执行以下功能: +1.启动RTSP推流 +2.启动系统各项服务,用于和双目交互 +3.启动mqtt,与App进行数据交互 */ #include @@ -73,7 +74,7 @@ string GetSimICCID(const string &tty = "/dev/ttyUSB2"); // 发送cpu序列号和SIM卡号 void SendCardInfo(mqtt::async_client &client); -// 进行验证 +// 开始进行设备验证 bool verification(); // 解析接收的数据 @@ -106,39 +107,33 @@ void mqttInit(); // 接收消息回调 void getMsgCallback(mqtt::const_message_ptr msg); -/* -parames: -argv[1] - SSID of the WiFi network to connect to -argv[2] - Password for the WiFi network (if applicable) -*/ int main(int argc, char *argv[]) { // 开启4G模块 - StartNet(); - - this_thread::sleep_for(chrono::seconds(2)); + // StartNet(); + // this_thread::sleep_for(chrono::seconds(2)); // 关闭全部信号 blockAllSignals(); signal(SIGINT, Exit); // 捕获Ctrl+C信号 - // 初始化mqtt服务器 + // 初始化mqtt mqttInit(); - // // 开启服务器 - // 如果没有进行过初始化,发送物联网卡信息进行认证 - if (ConfirmInit() == false) - { - SendCardInfo(client); - } - else - { - if (verification() == false) - { - cerr << "验证失败" << endl; - return 0; - } - } + // // // 开启服务器 + // // 如果没有进行过初始化,发送物联网卡信息进行认证 + // if (ConfirmInit() == false) + // { + // SendCardInfo(client); + // } + // else + // { + // if (verification() == false) + // { + // cerr << "验证失败" << endl; + // return 0; + // } + // } // 开启服务 thread(StartService).detach(); @@ -325,68 +320,13 @@ void StartNet() // 进行验证 bool verification() { - // 读取文件密文 - ReadFile *rf = new ReadFile(passwd); - bool flag = false; - auto pass = rf->ReadLines(); - // 若为空:改写初始化标志位false,重认证 - if (pass.empty()) - { - WriteFile *wf = new WriteFile(filepath); - wf->overwriteAtPos("no", wf->countBytesPattern("InitOrNot:", true), 3); - return 0; - } + bool flag = false; // 是否通过验证 - for (auto &ii : pass) - { - // 不为空,线上发送密文开始认证 - auto pos = format(R"({{"cardNo":"{}"}})", ii); + // 获取ICCID + string ICCID = GetSimICCID(); - auto res = NetRequest::QuickPostJson(url, pos); + auto res = NetRequest::QuickPostJson(url,ICCID); - int code = -1; - if (res) - { - try - { - code = nlohmann::json::parse(res->body).value("code", -1); - } - catch (const std::exception &e) - { - std::cerr << "JSON解析失败: " << e.what() << std::endl; - } - } - - if (res && code == 200) - { - cout << "线上:认证成功" << endl; - flag = true; - } - else - { - try - { - // 进行线下认证 - // 获取cpu序列号和SIM卡号 - string CardID = GetCardInfo(); - string SIMID = GetSimICCID(); - string info = CardID + SIMID; - // 进行MD5加密 - string md5 = MD5(info); - cout << md5 << endl; - if (md5.compare(ii) == 0) - { - cout << "线下:认证成功" << endl; - flag = true; - } - } - catch (const std::exception &e) - { - std::cerr << e.what() << '\n'; - } - } - } - cout << "结束" << endl; return flag; } diff --git a/ApCreate/src/main.cpp.bak b/softWareInit/src/main.cpp.bak similarity index 100% rename from ApCreate/src/main.cpp.bak rename to softWareInit/src/main.cpp.bak diff --git a/ApCreate/src/makefile b/softWareInit/src/makefile similarity index 100% rename from ApCreate/src/makefile rename to softWareInit/src/makefile