mqtt change string to json
This commit is contained in:
parent
ef4dd93863
commit
08cb041e29
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -78,7 +78,8 @@
|
||||
"complex": "cpp",
|
||||
"any": "cpp",
|
||||
"future": "cpp",
|
||||
"typeindex": "cpp"
|
||||
"typeindex": "cpp",
|
||||
"variant": "cpp"
|
||||
},
|
||||
"C_Cpp.errorSquiggles": "disabled"
|
||||
}
|
||||
@ -42,7 +42,6 @@
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/xpressive/xpressive_dynamic.hpp>
|
||||
#include <json/json.h>
|
||||
#include <zlog.h>
|
||||
#include "global.hpp"
|
||||
#include "dbaccess/sql_db.hpp"
|
||||
@ -953,7 +952,7 @@ int getSysIntValue(char *key) {
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string GetSysStatus() {
|
||||
std::string GetSysStatus(Json::Value &jsData) {
|
||||
long mem_used = -1;
|
||||
long mem_free = -1;
|
||||
long mem_total = -1;
|
||||
@ -1009,7 +1008,6 @@ std::string GetSysStatus() {
|
||||
sprintf(key, "/sys/class/thermal/thermal_zone0/temp");
|
||||
int temp = getSysIntValue(key);
|
||||
|
||||
Json::Value jsData;
|
||||
Json::FastWriter fw;
|
||||
jsData["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
jsData["cpuUserUse"] = rateUser;
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <json/json.h>
|
||||
|
||||
typedef struct statfs DISK, *pDISK;
|
||||
|
||||
@ -378,7 +379,7 @@ void ZoneConfig(std::string zoneid);
|
||||
* @brief 获取系统基本信息
|
||||
* @return std::string CPU MEM DISK info
|
||||
*/
|
||||
std::string GetSysStatus();
|
||||
std::string GetSysStatus(Json::Value &jsData);
|
||||
|
||||
bool CheckIP(const char* ip);
|
||||
|
||||
|
||||
@ -508,8 +508,7 @@ int JsonData::JsonCmd_29() {
|
||||
jsBody["CommMode"] = "WiFi";
|
||||
#endif
|
||||
jsBody["GateWayHwVesion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayHwVesion");
|
||||
std::string dataBody = show_value_.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
jsonVal["cmdBody"] = jsBody;
|
||||
char localtimestamp[32] = {0};
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
jsonVal["timestamp"] = localtimestamp;
|
||||
@ -604,8 +603,7 @@ int JsonData::JsonCmd_30(){
|
||||
}
|
||||
jsBody["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
jsBody["dataNodeArray"] = jsArray;
|
||||
std::string dataBody = show_value_.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
jsonVal["cmdBody"] = jsBody;
|
||||
char localtimestamp[32] = {0};
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
jsonVal["timestamp"] = localtimestamp;
|
||||
@ -637,8 +635,7 @@ int JsonData::JsonCmd_31(){
|
||||
jsBody["waveInterTime"] = waveInterTime;
|
||||
jsBody["maxSensorNum"] = maxSensorNum;
|
||||
jsBody["sensorCount"] = sensorCount;
|
||||
std::string dataBody = show_value_.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
jsonVal["cmdBody"] = jsBody;
|
||||
char localtimestamp[32] = {0};
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
jsonVal["timestamp"] = localtimestamp;
|
||||
@ -661,8 +658,7 @@ int JsonData::JsonCmd_32(std::string MeasurementID,int status,int type,std::str
|
||||
jsBody["errorType"] = type;
|
||||
jsBody["errorData"] = Data;
|
||||
jsBody["errorMsg"] = Msg;
|
||||
std::string dataBody = show_value_.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
jsonVal["cmdBody"] = jsBody;
|
||||
char timestamp[32] = {0};
|
||||
GetTimeNet(timestamp, 1);
|
||||
jsonVal["timestamp"] = timestamp;
|
||||
@ -723,7 +719,8 @@ void JsonData::DataNodeStatusCheck() {
|
||||
std::string JsonData::JsonCmd_07() {
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
std::string sysStatus = GetSysStatus();
|
||||
Json::Value jsData;
|
||||
std::string sysStatus = GetSysStatus(jsData);
|
||||
|
||||
zlog_info(zct, "sysStatus : %s", sysStatus.c_str());
|
||||
Json::Features f = Json::Features::strictMode();
|
||||
@ -736,7 +733,7 @@ std::string JsonData::JsonCmd_07() {
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
jsonVal["timestamp"] = localtimestamp;
|
||||
if (recvReader.parse(sysStatus, recvSys)) {
|
||||
jsonVal["cmdBody"] = sysStatus;
|
||||
jsonVal["cmdBody"] = jsData;
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "状态获取失败";
|
||||
|
||||
@ -112,7 +112,8 @@ std::string JsonData::JsonCmd_Cgi_02(Param_02 ¶m) {
|
||||
std::string JsonData::JsonCmd_Cgi_07() {
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
std::string sysStatus = GetSysStatus();
|
||||
Json::Value jsData;
|
||||
std::string sysStatus = GetSysStatus(jsData);
|
||||
|
||||
zlog_info(zct, "sysStatus : %s", sysStatus.c_str());
|
||||
Json::Features f = Json::Features::strictMode();
|
||||
@ -133,7 +134,8 @@ std::string JsonData::JsonCmd_Cgi_07() {
|
||||
std::string JsonData::JsonCmd_Cgi_08() {
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
std::string sysStatus = GetSysStatus();
|
||||
Json::Value jsData;
|
||||
std::string sysStatus = GetSysStatus(jsData);
|
||||
|
||||
Json::Features f = Json::Features::strictMode();
|
||||
Json::Reader recvReader(f);
|
||||
|
||||
@ -203,7 +203,8 @@ int data_publish(const char *str, const char *topic) {
|
||||
int ret = -1;
|
||||
if (mosq != NULL) {
|
||||
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;
|
||||
char *base64_aes = new char[pData.length() * 2];
|
||||
memset(base64_aes, 0, pData.length() * 2);
|
||||
|
||||
@ -361,9 +361,7 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
||||
}
|
||||
else if (taskID == kScheduleUpgrade) //3.升级
|
||||
{
|
||||
zlog_info(zct, " UpdateWirelessNode 2222" );
|
||||
UpdateWirelessNode(ushortAdd);
|
||||
zlog_info(zct, " UpdateWirelessNode end1111" );
|
||||
}else if (taskID == kScheduleConfigSensor) //4.更新配置
|
||||
{
|
||||
scheduleTask.cmd = CONFIG;
|
||||
@ -523,7 +521,6 @@ void Uart::DealRecvData(const char *pData) {
|
||||
break;
|
||||
case ASK_TASK:
|
||||
DealAskTask(ushortAdd);
|
||||
zlog_info(zct, " DealAskTask end11111" );
|
||||
break;
|
||||
case DEVICE_EXCEPTION:
|
||||
DealException(pData);
|
||||
|
||||
@ -581,7 +581,8 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
||||
memset(selectCon, 0x00, sizeof(selectCon));
|
||||
sprintf(selectCon, "zigbeeSignal <> '' ORDER BY timeStamp desc LIMIT 0,1");
|
||||
strTime = sqlite_db_ctrl::instance().GetData(szTableNameStatic, "timeStamp", selectCon);
|
||||
|
||||
JsonData jd;
|
||||
jd.JsonCmd_32(strMeasurementID,0,0,strMeasurementID,"");
|
||||
if (flag == 1) {
|
||||
zlog_info(zct, "DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
|
||||
}
|
||||
@ -811,6 +812,8 @@ void Uart::DealWave() {
|
||||
g_VecWaveDataZ.clear();
|
||||
VecWaveDataZ.clear();
|
||||
}
|
||||
if (m_waveCountX > 0 || m_waveCountY > 0 || m_waveCountZ > 0)
|
||||
{
|
||||
char localtimestamp[32] = {0};
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
char insertSql[100] = {0x00};
|
||||
@ -819,6 +822,7 @@ void Uart::DealWave() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,11 +168,8 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
|
||||
}
|
||||
Data[99] = tmp;
|
||||
sleep(1);
|
||||
zlog_info(zct, "111111111");
|
||||
WriteToUart((const char*)Data, 100);
|
||||
zlog_info(zct, "22222222222");
|
||||
int iRet = CheckZigbeeACK();
|
||||
zlog_info(zct, "333333333333");
|
||||
if (iRet == 0) {
|
||||
zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user