mqtt change string to json

This commit is contained in:
zhangsheng 2024-11-22 15:20:22 +08:00
parent ef4dd93863
commit 08cb041e29
9 changed files with 31 additions and 33 deletions

View File

@ -78,7 +78,8 @@
"complex": "cpp", "complex": "cpp",
"any": "cpp", "any": "cpp",
"future": "cpp", "future": "cpp",
"typeindex": "cpp" "typeindex": "cpp",
"variant": "cpp"
}, },
"C_Cpp.errorSquiggles": "disabled" "C_Cpp.errorSquiggles": "disabled"
} }

View File

@ -42,7 +42,6 @@
#include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/classification.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/xpressive/xpressive_dynamic.hpp> #include <boost/xpressive/xpressive_dynamic.hpp>
#include <json/json.h>
#include <zlog.h> #include <zlog.h>
#include "global.hpp" #include "global.hpp"
#include "dbaccess/sql_db.hpp" #include "dbaccess/sql_db.hpp"
@ -953,7 +952,7 @@ int getSysIntValue(char *key) {
return value; return value;
} }
std::string GetSysStatus() { std::string GetSysStatus(Json::Value &jsData) {
long mem_used = -1; long mem_used = -1;
long mem_free = -1; long mem_free = -1;
long mem_total = -1; long mem_total = -1;
@ -1009,7 +1008,6 @@ std::string GetSysStatus() {
sprintf(key, "/sys/class/thermal/thermal_zone0/temp"); sprintf(key, "/sys/class/thermal/thermal_zone0/temp");
int temp = getSysIntValue(key); int temp = getSysIntValue(key);
Json::Value jsData;
Json::FastWriter fw; Json::FastWriter fw;
jsData["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G; jsData["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsData["cpuUserUse"] = rateUser; jsData["cpuUserUse"] = rateUser;

View File

@ -5,6 +5,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include <json/json.h>
typedef struct statfs DISK, *pDISK; typedef struct statfs DISK, *pDISK;
@ -378,7 +379,7 @@ void ZoneConfig(std::string zoneid);
* @brief * @brief
* @return std::string CPU MEM DISK info * @return std::string CPU MEM DISK info
*/ */
std::string GetSysStatus(); std::string GetSysStatus(Json::Value &jsData);
bool CheckIP(const char* ip); bool CheckIP(const char* ip);

View File

@ -508,8 +508,7 @@ int JsonData::JsonCmd_29() {
jsBody["CommMode"] = "WiFi"; jsBody["CommMode"] = "WiFi";
#endif #endif
jsBody["GateWayHwVesion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayHwVesion"); jsBody["GateWayHwVesion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayHwVesion");
std::string dataBody = show_value_.write(jsBody); jsonVal["cmdBody"] = jsBody;
jsonVal["cmdBody"] = dataBody;
char localtimestamp[32] = {0}; char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp; jsonVal["timestamp"] = localtimestamp;
@ -604,8 +603,7 @@ int JsonData::JsonCmd_30(){
} }
jsBody["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G; jsBody["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsBody["dataNodeArray"] = jsArray; jsBody["dataNodeArray"] = jsArray;
std::string dataBody = show_value_.write(jsBody); jsonVal["cmdBody"] = jsBody;
jsonVal["cmdBody"] = dataBody;
char localtimestamp[32] = {0}; char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp; jsonVal["timestamp"] = localtimestamp;
@ -637,8 +635,7 @@ int JsonData::JsonCmd_31(){
jsBody["waveInterTime"] = waveInterTime; jsBody["waveInterTime"] = waveInterTime;
jsBody["maxSensorNum"] = maxSensorNum; jsBody["maxSensorNum"] = maxSensorNum;
jsBody["sensorCount"] = sensorCount; jsBody["sensorCount"] = sensorCount;
std::string dataBody = show_value_.write(jsBody); jsonVal["cmdBody"] = jsBody;
jsonVal["cmdBody"] = dataBody;
char localtimestamp[32] = {0}; char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp; jsonVal["timestamp"] = localtimestamp;
@ -661,8 +658,7 @@ int JsonData::JsonCmd_32(std::string MeasurementID,int status,int type,std::str
jsBody["errorType"] = type; jsBody["errorType"] = type;
jsBody["errorData"] = Data; jsBody["errorData"] = Data;
jsBody["errorMsg"] = Msg; jsBody["errorMsg"] = Msg;
std::string dataBody = show_value_.write(jsBody); jsonVal["cmdBody"] = jsBody;
jsonVal["cmdBody"] = dataBody;
char timestamp[32] = {0}; char timestamp[32] = {0};
GetTimeNet(timestamp, 1); GetTimeNet(timestamp, 1);
jsonVal["timestamp"] = timestamp; jsonVal["timestamp"] = timestamp;
@ -723,7 +719,8 @@ void JsonData::DataNodeStatusCheck() {
std::string JsonData::JsonCmd_07() { std::string JsonData::JsonCmd_07() {
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear(); jsonVal.clear();
std::string sysStatus = GetSysStatus(); Json::Value jsData;
std::string sysStatus = GetSysStatus(jsData);
zlog_info(zct, "sysStatus : %s", sysStatus.c_str()); zlog_info(zct, "sysStatus : %s", sysStatus.c_str());
Json::Features f = Json::Features::strictMode(); Json::Features f = Json::Features::strictMode();
@ -736,7 +733,7 @@ std::string JsonData::JsonCmd_07() {
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp; jsonVal["timestamp"] = localtimestamp;
if (recvReader.parse(sysStatus, recvSys)) { if (recvReader.parse(sysStatus, recvSys)) {
jsonVal["cmdBody"] = sysStatus; jsonVal["cmdBody"] = jsData;
} else { } else {
jsonVal["success"] = false; jsonVal["success"] = false;
jsonVal["message"] = "状态获取失败"; jsonVal["message"] = "状态获取失败";

View File

@ -112,7 +112,8 @@ std::string JsonData::JsonCmd_Cgi_02(Param_02 &param) {
std::string JsonData::JsonCmd_Cgi_07() { std::string JsonData::JsonCmd_Cgi_07() {
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear(); jsonVal.clear();
std::string sysStatus = GetSysStatus(); Json::Value jsData;
std::string sysStatus = GetSysStatus(jsData);
zlog_info(zct, "sysStatus : %s", sysStatus.c_str()); zlog_info(zct, "sysStatus : %s", sysStatus.c_str());
Json::Features f = Json::Features::strictMode(); Json::Features f = Json::Features::strictMode();
@ -133,7 +134,8 @@ std::string JsonData::JsonCmd_Cgi_07() {
std::string JsonData::JsonCmd_Cgi_08() { std::string JsonData::JsonCmd_Cgi_08() {
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear(); jsonVal.clear();
std::string sysStatus = GetSysStatus(); Json::Value jsData;
std::string sysStatus = GetSysStatus(jsData);
Json::Features f = Json::Features::strictMode(); Json::Features f = Json::Features::strictMode();
Json::Reader recvReader(f); Json::Reader recvReader(f);

View File

@ -203,7 +203,8 @@ int data_publish(const char *str, const char *topic) {
int ret = -1; int ret = -1;
if (mosq != NULL) { if (mosq != NULL) {
std::string strTopic = std::string(topic); std::string strTopic = std::string(topic);
if (strTopic.find("cmd") != std::string::npos || strTopic.find("configureInfo") != std::string::npos) { if (strTopic.find("cmd") != std::string::npos || strTopic.find("configureInfo") != std::string::npos || strTopic.find("status") != std::string::npos) {
zlog_info(zct,"strTopic = %s,pData = %s",strTopic.c_str(),str);
std::string pData = (std::string)str; std::string pData = (std::string)str;
char *base64_aes = new char[pData.length() * 2]; char *base64_aes = new char[pData.length() * 2];
memset(base64_aes, 0, pData.length() * 2); memset(base64_aes, 0, pData.length() * 2);

View File

@ -361,9 +361,7 @@ int Uart::DealAskTask(uint16_t ushortAdd){
} }
else if (taskID == kScheduleUpgrade) //3.升级 else if (taskID == kScheduleUpgrade) //3.升级
{ {
zlog_info(zct, " UpdateWirelessNode 2222" );
UpdateWirelessNode(ushortAdd); UpdateWirelessNode(ushortAdd);
zlog_info(zct, " UpdateWirelessNode end1111" );
}else if (taskID == kScheduleConfigSensor) //4.更新配置 }else if (taskID == kScheduleConfigSensor) //4.更新配置
{ {
scheduleTask.cmd = CONFIG; scheduleTask.cmd = CONFIG;
@ -523,7 +521,6 @@ void Uart::DealRecvData(const char *pData) {
break; break;
case ASK_TASK: case ASK_TASK:
DealAskTask(ushortAdd); DealAskTask(ushortAdd);
zlog_info(zct, " DealAskTask end11111" );
break; break;
case DEVICE_EXCEPTION: case DEVICE_EXCEPTION:
DealException(pData); DealException(pData);

View File

@ -581,7 +581,8 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
memset(selectCon, 0x00, sizeof(selectCon)); memset(selectCon, 0x00, sizeof(selectCon));
sprintf(selectCon, "zigbeeSignal <> '' ORDER BY timeStamp desc LIMIT 0,1"); sprintf(selectCon, "zigbeeSignal <> '' ORDER BY timeStamp desc LIMIT 0,1");
strTime = sqlite_db_ctrl::instance().GetData(szTableNameStatic, "timeStamp", selectCon); strTime = sqlite_db_ctrl::instance().GetData(szTableNameStatic, "timeStamp", selectCon);
JsonData jd;
jd.JsonCmd_32(strMeasurementID,0,0,strMeasurementID,"");
if (flag == 1) { if (flag == 1) {
zlog_info(zct, "DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); zlog_info(zct, "DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
} }
@ -811,14 +812,17 @@ void Uart::DealWave() {
g_VecWaveDataZ.clear(); g_VecWaveDataZ.clear();
VecWaveDataZ.clear(); VecWaveDataZ.clear();
} }
char localtimestamp[32] = {0}; if (m_waveCountX > 0 || m_waveCountY > 0 || m_waveCountZ > 0)
GetTimeNet(localtimestamp, 1); {
char insertSql[100] = {0x00}; char localtimestamp[32] = {0};
char whereCon[50] = {0x00}; GetTimeNet(localtimestamp, 1);
sprintf(whereCon, "MeasurementID='%s'",strMeasurementID.c_str()); char insertSql[100] = {0x00};
memset(whereCon, 0x00, sizeof(whereCon)); char whereCon[50] = {0x00};
sprintf(insertSql, "'%s','%02x%02x','%s',0,'1','%s' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,""); sprintf(whereCon, "MeasurementID='%s'",strMeasurementID.c_str());
sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); memset(whereCon, 0x00, sizeof(whereCon));
sprintf(insertSql, "'%s','%02x%02x','%s',0,'1','%s' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,"");
sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql);
}
wave_trans_ = false; wave_trans_ = false;
} }
} }

View File

@ -168,11 +168,8 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
} }
Data[99] = tmp; Data[99] = tmp;
sleep(1); sleep(1);
zlog_info(zct, "111111111");
WriteToUart((const char*)Data, 100); WriteToUart((const char*)Data, 100);
zlog_info(zct, "22222222222");
int iRet = CheckZigbeeACK(); int iRet = CheckZigbeeACK();
zlog_info(zct, "333333333333");
if (iRet == 0) { if (iRet == 0) {
zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
} else { } else {