2024-10-22 19:04:25 +08:00
|
|
|
|
#include "thread_func.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
#include <sys/sysinfo.h>
|
|
|
|
|
|
#include <dirent.h>
|
2024-10-23 09:22:06 +08:00
|
|
|
|
#include <map>
|
2024-10-23 19:51:01 +08:00
|
|
|
|
#include <zlog.h>
|
2024-10-23 22:25:03 +08:00
|
|
|
|
#include "mqttclient/mqtt_client.h"
|
2024-10-23 09:22:06 +08:00
|
|
|
|
#include "uart/uart.hpp"
|
|
|
|
|
|
#include "common/common_func.hpp"
|
2024-10-23 22:25:03 +08:00
|
|
|
|
#include "jsonparse/communication_cmd.hpp"
|
2024-10-23 09:22:06 +08:00
|
|
|
|
#include "wifi_5g/wpa_client.h"
|
2024-10-22 19:04:25 +08:00
|
|
|
|
|
2024-10-23 20:33:05 +08:00
|
|
|
|
extern zlog_category_t *zct;
|
|
|
|
|
|
extern zlog_category_t *zbt;
|
2024-10-22 19:04:25 +08:00
|
|
|
|
|
|
|
|
|
|
void CheckThread() {
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_info(zbt, "ENTER CHECK THREAD ");
|
2024-10-23 19:51:01 +08:00
|
|
|
|
|
2024-10-22 19:04:25 +08:00
|
|
|
|
int heart_count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
int time_check = 0;
|
|
|
|
|
|
int reset_flag = 0;
|
|
|
|
|
|
int online_check = 0;
|
|
|
|
|
|
int HardStatus = 0;
|
|
|
|
|
|
int logClean = 0;
|
|
|
|
|
|
int Battery = 0;
|
|
|
|
|
|
int commSignal = 0;
|
|
|
|
|
|
int loose_check = 0;
|
|
|
|
|
|
int mqttresend = 0;
|
|
|
|
|
|
int ModifyAddr = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while (GlobalConfig::QuitFlag_G) {
|
|
|
|
|
|
GlobalConfig::threadStatus = 1;
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
if (GlobalConfig::EnterZigBeeWaveTransmittingFlag_G == ENTER_TRANSMITTING_STATUS) {
|
|
|
|
|
|
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G++;
|
|
|
|
|
|
if (GlobalConfig::EnterZigBeeWaveTransmittingCnt_G >= 180) {
|
|
|
|
|
|
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
|
|
|
|
|
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_error(zct, "[---- ZigBee error--!] ZigBee PanID is 9999 over time for 3 minutes !");
|
2024-10-22 19:04:25 +08:00
|
|
|
|
// 重新写入 0x8888
|
|
|
|
|
|
uart_inst::instance().modify_LocalAddr(0x8888);
|
|
|
|
|
|
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
|
|
|
|
|
// 延时1秒
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
// 重新读回 GlobalConfig::ZigbeeInfo_G.PanID
|
|
|
|
|
|
uart_inst::instance().UpdateZigbeeInfoCtrl();
|
|
|
|
|
|
uart_inst::instance().bUpdateconfig = false;
|
|
|
|
|
|
uart_inst::instance().bUpdate = false;
|
|
|
|
|
|
uart_inst::instance().bSendTimeStamp = false;
|
|
|
|
|
|
// 延时1秒
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
std::string str("8888");
|
|
|
|
|
|
if (GlobalConfig::ZigbeeInfo_G.MyAddr.compare(str) == 0) {
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_warn(zct, "[---- ZigBee INFO ----!] ZigBee PanID come back to be 8888 !");
|
2024-10-22 19:04:25 +08:00
|
|
|
|
} else {
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_error(zct, "[---- ZigBee error--!] ZigBee PanID cannot come back to be 8888 !");
|
2024-10-22 19:04:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (10 == heart_count) {
|
|
|
|
|
|
if (GlobalConfig::LinkCount > 30) {
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_error(zct, "MQTT connect failed ");
|
2024-10-22 19:04:25 +08:00
|
|
|
|
#ifdef IMX6UL_GATEWAY
|
|
|
|
|
|
char connect[10] = {0x00};
|
2024-11-04 21:35:50 +08:00
|
|
|
|
readStringValue("config", "connect", connect, (char *)GlobalConfig::Config_G.c_str());
|
2024-10-22 19:04:25 +08:00
|
|
|
|
if (atoi(connect)) {
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_error(zct, "MQTT connect failed,reboot");
|
2024-10-22 19:04:25 +08:00
|
|
|
|
exit(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
std::string ipTemp = IpAddrInit();
|
2024-10-24 17:04:14 +08:00
|
|
|
|
GlobalConfig::IpAddr_G = ipTemp;
|
2024-10-22 19:04:25 +08:00
|
|
|
|
heart_count = 0;
|
|
|
|
|
|
}
|
2024-11-05 11:10:50 +08:00
|
|
|
|
if (7200 == time_check) { // 2h //校时暂时不测
|
|
|
|
|
|
time_check = 0;
|
2024-10-31 19:30:10 +08:00
|
|
|
|
// char buf[256] = {0};
|
|
|
|
|
|
// char buf2[256] = {0};
|
|
|
|
|
|
// sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}", GlobalConfig::MacAddr_G.c_str());
|
|
|
|
|
|
// sprintf(buf2, "{\"dataWatchNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}", GlobalConfig::MacAddr_G.c_str());
|
|
|
|
|
|
// std::string str = std::string(buf);
|
|
|
|
|
|
// std::string str2 = std::string(buf2);
|
2024-11-05 11:10:50 +08:00
|
|
|
|
//
|
2024-10-31 19:30:10 +08:00
|
|
|
|
// int iRet = data_publish(str.c_str(), GlobalConfig::Topic_G.mPubTiming.c_str());
|
|
|
|
|
|
// iRet = data_publish(str.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
|
|
|
|
|
// iRet = data_publish(str2.c_str(), GlobalConfig::Topic_G.mPubTiming.c_str());
|
|
|
|
|
|
// iRet = data_publish(str2.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
|
|
|
|
|
// if (iRet != 0) {
|
|
|
|
|
|
// zlog_error(zct, "MQTT connect failed ,time check");
|
|
|
|
|
|
// #ifdef IMX6UL_GATEWAY
|
|
|
|
|
|
// char connect[10] = {0x00};
|
|
|
|
|
|
// readStringValue("config", "connect", connect, (char *)GlobalConfig::Config_G.c_str());
|
|
|
|
|
|
// if (atoi(connect)) {
|
|
|
|
|
|
// zlog_error(zct, "MQTT connect failed,time check ,reboot");
|
|
|
|
|
|
// exit(0);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
// #ifdef NR5G_MODULE
|
|
|
|
|
|
// #ifdef IMX6UL_GATEWAY
|
|
|
|
|
|
// dial.closePort();
|
|
|
|
|
|
// gpio_set(GlobalConfig::GPIO_G.commRest, 0);
|
|
|
|
|
|
// zlog_warn(zct, "GPIO 8 start");
|
|
|
|
|
|
// sleep(2);
|
|
|
|
|
|
// gpio_set(GlobalConfig::GPIO_G.commRest, 1);
|
|
|
|
|
|
// zlog_warn(zct, "GPIO 8 End");
|
|
|
|
|
|
// sleep(20);
|
|
|
|
|
|
// dial.openPort("/dev/ttyUSB2");
|
|
|
|
|
|
// dial.setState();
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
// #ifdef G2UL_GATEWAY
|
|
|
|
|
|
// dial.closePort();
|
|
|
|
|
|
// gpio_set(GlobalConfig::GPIO_G.commPower, 0);
|
|
|
|
|
|
// zlog_warn(zct, "commPower start");
|
|
|
|
|
|
// sleep(2);
|
|
|
|
|
|
// gpio_set(GlobalConfig::GPIO_G.commPower, 1);
|
|
|
|
|
|
// zlog_warn(zct, "commPower End");
|
|
|
|
|
|
// sleep(20);
|
|
|
|
|
|
// connectCount++;
|
|
|
|
|
|
// if (connectCount > 10) {
|
|
|
|
|
|
// zlog_error(zct, "5G reset error ,reboot!");
|
|
|
|
|
|
// system("reboot");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// #ifndef NR5G_MEIGE
|
|
|
|
|
|
// dial.openPort("/dev/ttyUSB2");
|
|
|
|
|
|
// dial.setState();
|
|
|
|
|
|
// #else
|
|
|
|
|
|
// char szquectel[100] = {0x00};
|
|
|
|
|
|
// std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
|
|
|
|
|
// sprintf(szquectel, "/opt/quectel-CM/Meig-CM -s %s &", strAPN.c_str());
|
|
|
|
|
|
// system(szquectel);
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
// #ifdef WIFI_MODULE
|
|
|
|
|
|
// zlog_warn(zct, "WiFi reset!");
|
|
|
|
|
|
// #ifdef IMX6UL_GATEWAY
|
|
|
|
|
|
// gpio_set(GlobalConfig::GPIO_G.wifiReset, 0);
|
|
|
|
|
|
// sleep(5);
|
|
|
|
|
|
// gpio_set(GlobalConfig::GPIO_G.wifiReset, 1);
|
|
|
|
|
|
// sleep(5);
|
|
|
|
|
|
// wifi::WPAClient wpa;
|
|
|
|
|
|
// wpa.ReconnectWiFi();
|
|
|
|
|
|
// system("/etc/init.d/wpa_restart");
|
|
|
|
|
|
// system("udhcpc -i wlan2 &");
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
// #ifdef G2UL_GATEWAY
|
|
|
|
|
|
// system("/etc/init.d/wpa_restart");
|
|
|
|
|
|
// sleep(5);
|
|
|
|
|
|
// string strip = GetGwIp_("wlan0");
|
|
|
|
|
|
// print_info("strip = %s\n", strip.c_str());
|
|
|
|
|
|
// if (strip.compare("0.0.0.0") != 0) {
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// gpio_set(GlobalConfig::GPIO_G.wifiReset, 1);
|
|
|
|
|
|
// sleep(5);
|
|
|
|
|
|
// gpio_set(GlobalConfig::GPIO_G.wifiReset, 0);
|
|
|
|
|
|
// sleep(30);
|
|
|
|
|
|
// wifi::WPAClient wpa;
|
|
|
|
|
|
// wpa.ReconnectWiFi();
|
|
|
|
|
|
// system("/etc/init.d/wpa_restart");
|
|
|
|
|
|
// sleep(5);
|
|
|
|
|
|
// system("udhcpc -b -i wlan0 &");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
// }
|
2024-11-05 11:10:50 +08:00
|
|
|
|
}
|
2024-10-22 19:04:25 +08:00
|
|
|
|
if (HardStatus == 3600) { // one hour 3600
|
|
|
|
|
|
JsonData jd;
|
|
|
|
|
|
std::string data = jd.JsonCmd_07();
|
|
|
|
|
|
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubStatus.c_str());
|
|
|
|
|
|
HardStatus = 0;
|
|
|
|
|
|
int hour = 0;
|
|
|
|
|
|
struct tm *tm_info = get_current_date();
|
|
|
|
|
|
hour = tm_info->tm_hour;
|
|
|
|
|
|
int statistics = readIntValue("config", "statistics", (char *)GlobalConfig::Config_G.c_str());
|
|
|
|
|
|
if (statistics == 0 && hour > 13) {
|
|
|
|
|
|
writeIntValue("config", "statistics", 1, (char *)GlobalConfig::Config_G.c_str());
|
2024-10-22 20:56:21 +08:00
|
|
|
|
sqlite_db_ctrl::instance().CalculateData();
|
2024-10-22 19:04:25 +08:00
|
|
|
|
} else if (statistics == 1 && hour < 13) {
|
|
|
|
|
|
writeIntValue("config", "statistics", 0, (char *)GlobalConfig::Config_G.c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (mqttresend == 7200) {
|
|
|
|
|
|
mqttresend = 0;
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_info(zct, "mqttresend check");
|
2024-10-22 19:04:25 +08:00
|
|
|
|
Json::Value jsHeart;
|
|
|
|
|
|
Json::FastWriter fw;
|
|
|
|
|
|
jsHeart["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
|
|
|
|
|
jsHeart["status"] = "online_V" + GlobalConfig::Version;
|
|
|
|
|
|
jsHeart["IP"] = GlobalConfig::IpAddr_G;
|
|
|
|
|
|
std::string strJson = fw.write(jsHeart);
|
|
|
|
|
|
int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str());
|
|
|
|
|
|
if (iRet == 0) {
|
2024-10-22 20:56:21 +08:00
|
|
|
|
sqlite_db_ctrl::instance().QueryofflineData();
|
2024-10-22 19:04:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (600 == online_check) {
|
|
|
|
|
|
online_check = 0;
|
2024-10-22 20:56:21 +08:00
|
|
|
|
int Count = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), NULL);
|
2024-10-22 19:04:25 +08:00
|
|
|
|
if (Count > 0) {
|
|
|
|
|
|
JsonData jd;
|
|
|
|
|
|
jd.DataNodeStatusCheck();
|
|
|
|
|
|
Param_29 param;
|
|
|
|
|
|
std::string cmd29 = jd.JsonCmd_29(param);
|
2024-10-24 16:01:21 +08:00
|
|
|
|
data_publish(cmd29.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
2024-10-22 19:04:25 +08:00
|
|
|
|
char localtimestamp[32] = {0};
|
|
|
|
|
|
GetTimeNet(localtimestamp, 1);
|
|
|
|
|
|
std::string nowTimetamp = std::string(localtimestamp);
|
|
|
|
|
|
char selectCon[128] = {0};
|
|
|
|
|
|
sprintf(selectCon, " sendMsg <> '' ORDER BY timeStamp DESC LIMIT 0,1");
|
|
|
|
|
|
sleep(1);
|
2024-10-22 20:56:21 +08:00
|
|
|
|
std::string strTime = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), "timeStamp", selectCon);
|
2024-10-22 19:04:25 +08:00
|
|
|
|
long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str());
|
2024-10-24 16:01:21 +08:00
|
|
|
|
zlog_info(zct, "online check = %ld", lTime);
|
2024-10-22 19:04:25 +08:00
|
|
|
|
if (lTime > 1800) {
|
2024-10-24 16:01:21 +08:00
|
|
|
|
zlog_error(zct, "nowTimetamp = %s,lastTime = %s,lTime = %ld", nowTimetamp.c_str(), strTime.c_str(), lTime);
|
2024-10-22 19:04:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (7200 == Battery) {
|
|
|
|
|
|
Battery = 0;
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_info(zct, "Battery");
|
2024-10-22 20:56:21 +08:00
|
|
|
|
sqlite_db_ctrl::instance().CalculateBattery();
|
2024-10-22 19:04:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (3500 == loose_check) {
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_info(zct, "loosecheck\n");
|
2024-10-22 19:04:25 +08:00
|
|
|
|
loose_check = 0;
|
2024-10-22 20:56:21 +08:00
|
|
|
|
sqlite_db_ctrl::instance().CalculateDip();
|
2024-10-22 19:04:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (ModifyAddr == 3600) {
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_info(zct, "ModifyAddr check");
|
2024-10-22 19:04:25 +08:00
|
|
|
|
ModifyAddr = 0;
|
|
|
|
|
|
if (uart_inst::instance().bModifyAddr) {
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_error(zct, "ModifyAddr failed ");
|
2024-10-22 19:04:25 +08:00
|
|
|
|
exit(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (18000 == commSignal) { // 5h
|
|
|
|
|
|
Json::Value jsBody, jsonVal;
|
|
|
|
|
|
Json::FastWriter showValue;
|
|
|
|
|
|
if (GlobalConfig::NetStatus == "\"NOCONN\"" || GlobalConfig::NetStatus == "\"CONNECT\"") {
|
|
|
|
|
|
if (GlobalConfig::NetSignal == 0) {
|
|
|
|
|
|
jsBody["communicationSignal"] = "未知";
|
|
|
|
|
|
} else if (GlobalConfig::NetSignal > -80) {
|
|
|
|
|
|
jsBody["commSignal"] = "优";
|
|
|
|
|
|
} else if (GlobalConfig::NetSignal > -90 && GlobalConfig::NetSignal < -80) {
|
|
|
|
|
|
jsBody["commSignal"] = "良";
|
|
|
|
|
|
} else if (GlobalConfig::NetSignal > -105 && GlobalConfig::NetSignal < -90) {
|
|
|
|
|
|
jsBody["commSignal"] = "一般";
|
|
|
|
|
|
} else if (GlobalConfig::NetSignal < -105) {
|
|
|
|
|
|
jsBody["commSignal"] = "弱";
|
|
|
|
|
|
} else if (GlobalConfig::NetSignal < -115) {
|
|
|
|
|
|
jsBody["commSignal"] = "不稳定";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else if (GlobalConfig::NetStatus == "\"SEARCH\"") {
|
|
|
|
|
|
jsBody["commSignal"] = "搜索网络";
|
|
|
|
|
|
} else if (GlobalConfig::NetStatus == "\"LIMSRV\"") {
|
|
|
|
|
|
jsBody["commSignal"] = "未插卡";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
jsBody["commSignal"] = "未知";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
jsonVal["cmd"] = "53";
|
|
|
|
|
|
std::string dataBody = showValue.write(jsBody);
|
|
|
|
|
|
jsonVal["cmdBody"] = dataBody;
|
|
|
|
|
|
data_publish(showValue.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (21600 == logClean) {
|
|
|
|
|
|
logClean = 0;
|
|
|
|
|
|
DIR *dp; //创建一个指向root路径下每个文件的指针
|
|
|
|
|
|
struct dirent *dirp;
|
2024-10-23 22:25:03 +08:00
|
|
|
|
std::string root = "/opt/log/";
|
|
|
|
|
|
if ((dp = opendir(root.c_str())) == NULL) zlog_error(zct, "can't open:[%s]", root.c_str());
|
2024-10-22 19:04:25 +08:00
|
|
|
|
while ((dirp = readdir(dp)) != NULL) {
|
|
|
|
|
|
if ((!strcmp(dirp->d_name, ".") || (!strcmp(dirp->d_name, "..")))) continue;
|
|
|
|
|
|
struct timeval curTime;
|
|
|
|
|
|
gettimeofday(&curTime, NULL);
|
|
|
|
|
|
char buffer[80] = {0};
|
|
|
|
|
|
char fileMonth[11] = {0};
|
|
|
|
|
|
char todayMonth[11] = {0};
|
|
|
|
|
|
char fileDay[11] = {0};
|
|
|
|
|
|
char todayDay[11] = {0};
|
|
|
|
|
|
struct tm nowTime;
|
|
|
|
|
|
localtime_r(&curTime.tv_sec, &nowTime); //把得到的值存入临时分配的内存中,线程安全
|
|
|
|
|
|
strftime(buffer, sizeof(buffer), "%Y-%m-%d", &nowTime);
|
|
|
|
|
|
memcpy(fileDay, dirp->d_name + 8, 2);
|
|
|
|
|
|
memcpy(todayDay, buffer + 8, 2);
|
|
|
|
|
|
memcpy(fileMonth, dirp->d_name + 5, 2);
|
|
|
|
|
|
memcpy(todayMonth, buffer + 5, 2);
|
2024-10-23 22:25:03 +08:00
|
|
|
|
std::string filename = root + std::string(dirp->d_name);
|
2024-10-22 19:04:25 +08:00
|
|
|
|
if (atoi(fileMonth) == atoi(todayMonth) ? abs(atoi(todayDay) - atoi(fileDay)) > 15 : abs(abs(30 - (atoi(fileDay)) + atoi(todayDay))) > 15) {
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_info(zct, "filename = %s", filename.c_str());
|
2024-10-22 19:04:25 +08:00
|
|
|
|
remove(filename.c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
char localtimestamp[32] = {0};
|
|
|
|
|
|
GetTimeNet(localtimestamp, 1);
|
|
|
|
|
|
char whereCon[1024] = {0};
|
|
|
|
|
|
#ifdef G2UL_GATEWAY
|
|
|
|
|
|
sprintf(whereCon, " timestamp < '%ld' ", atol(localtimestamp) - 2592000 * 2); //删除2个月前的数据
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef IMX6UL_GATEWAY
|
|
|
|
|
|
sprintf(whereCon, " timestamp < '%ld' ", atol(localtimestamp) - 2592000); //删除1个月前的数据
|
|
|
|
|
|
#endif
|
2024-10-22 20:56:21 +08:00
|
|
|
|
sqlite_db_ctrl::instance().DeleteTableData(" t_battery_history ", whereCon);
|
2024-10-22 19:04:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
#ifdef WIFI_MODULE
|
|
|
|
|
|
if (wifi_reconnect_count == 600) { // 每 10分钟,重连WiFi网络
|
|
|
|
|
|
wifi_reconnect_count = 0;
|
|
|
|
|
|
wifi::WPAClient wpa;
|
|
|
|
|
|
std::string netssid = wpa.GetNetSsid();
|
|
|
|
|
|
std::string currentssid = "";
|
|
|
|
|
|
if (0 == netssid.compare("")) {
|
|
|
|
|
|
netssid = wpa.GetNetSsid();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (netssid.length() > 0) {
|
|
|
|
|
|
currentssid = wpa.GetCurrentSSID();
|
|
|
|
|
|
if (currentssid.length() > 0) {
|
|
|
|
|
|
char buf[64] = {0};
|
|
|
|
|
|
std::string rssiSend = "";
|
|
|
|
|
|
#ifdef G2UL_GATEWAY
|
|
|
|
|
|
rssiSend = "/usr/sbin/wpa_cli signal_poll|grep RSSI | cut -f 2 -d '='";
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef IMX6UL_GATEWAY
|
|
|
|
|
|
rssiSend = "/opt/Cidn/wpa_cli signal_poll|grep RSSI | cut -f 2 -d '='";
|
|
|
|
|
|
#endif
|
|
|
|
|
|
system_custom(rssiSend.c_str(), buf);
|
|
|
|
|
|
std::string Rssi = std::string(buf);
|
|
|
|
|
|
|
|
|
|
|
|
memset(buf, 0, 64);
|
|
|
|
|
|
sprintf(buf, "wifi:true Rssi:%s", Rssi.c_str());
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_info(zct, "%s\n", buf);
|
2024-10-22 19:04:25 +08:00
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
std::string runinfo = "wifi:false\n";
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_info(zct, "%s\n", runinfo.c_str());
|
2024-10-22 19:04:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (wpa.ReconnectWiFi()) {
|
2024-10-23 20:33:05 +08:00
|
|
|
|
zlog_info(zct, "wifi reconnect ok\n");
|
2024-10-22 19:04:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
if (reset_flag > 7200) {
|
|
|
|
|
|
reset_flag = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
Battery++;
|
|
|
|
|
|
reset_flag++;
|
|
|
|
|
|
time_check++;
|
|
|
|
|
|
heart_count++;
|
|
|
|
|
|
online_check++;
|
|
|
|
|
|
HardStatus++;
|
|
|
|
|
|
logClean++;
|
|
|
|
|
|
loose_check++;
|
|
|
|
|
|
ModifyAddr++;
|
|
|
|
|
|
mqttresend++;
|
|
|
|
|
|
#ifdef WIFI_MODULE
|
|
|
|
|
|
wifi_reconnect_count++;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|