add mqtt status info

This commit is contained in:
zhangsheng 2024-11-20 16:45:04 +08:00
parent 7e2faf2ead
commit 1e8dee5764
5 changed files with 221 additions and 33 deletions

View File

@ -18,7 +18,10 @@ public:
std::string JsonCmd_25(Param_25 &param); std::string JsonCmd_25(Param_25 &param);
std::string JsonCmd_26(Param_26 &param); std::string JsonCmd_26(Param_26 &param);
std::string JsonCmd_27(Json::Value &recvBody); std::string JsonCmd_27(Json::Value &recvBody);
std::string JsonCmd_29(Param_29 &param); //系统配置信息 int JsonCmd_29(); //系统配置信息
int JsonCmd_30(); //传感器信息
int JsonCmd_31(); //传感器任务调度信息
int JsonCmd_32(std::string MeasurementID,int status,int type,std::string Data,std::string Msg);
std::string JsonCmd_50(Json::Value &recvBody); // download update file std::string JsonCmd_50(Json::Value &recvBody); // download update file
std::string JsonCmd_51(Json::Value &recvBody); std::string JsonCmd_51(Json::Value &recvBody);
std::string JsonCmd_52(); // upload static data std::string JsonCmd_52(); // upload static data

View File

@ -1,11 +1,13 @@
#include "communication_cmd.hpp" #include "communication_cmd.hpp"
#include <zlog.h> #include <zlog.h>
#include <boost/algorithm/string.hpp>
#include "common/global.hpp" #include "common/global.hpp"
#include "dbaccess/sql_db.hpp" #include "dbaccess/sql_db.hpp"
#include "mqttclient/mqtt_client.h" #include "mqttclient/mqtt_client.h"
#include "datatransfer/data_trans.hpp" #include "datatransfer/data_trans.hpp"
#include "platform/platform_init.hpp" #include "platform/platform_init.hpp"
#include "utility/md5.h" #include "utility/md5.h"
#include "scheduler/schedule.hpp"
extern zlog_category_t *zct; extern zlog_category_t *zct;
@ -483,30 +485,193 @@ std::string JsonData::JsonCmd_53(Json::Value &recvBody) {
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }
std::string JsonData::JsonCmd_29(Param_29 &param) { int JsonData::JsonCmd_29() {
Json::Value jsonVal; Json::Value jsonVal;
Json::Value jsBody; Json::Value jsBody;
Json::Value SystemSetting; Json::Value jsSystemSetting;
jsonVal.clear(); jsonVal.clear();
jsonVal["cmd"] = "29"; jsonVal["cmd"] = "29";
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G; jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
jsSystemSetting["WebVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
jsSystemSetting["SystemVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
jsSystemSetting["GateWayVersion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion");
jsBody["localIP"] = GlobalConfig::IpAddr_G;
jsBody["dataNodeGatewayType"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayProduct");
jsBody["CommMode"] = "有线";
#ifdef NR5G_MODULE
jsBody["CommMode"] = "5G";
#endif
#ifdef Q4G_MODULE
jsBody["CommMode"] = "4G";
#endif
#ifdef WIFI_MODULE
jsBody["CommMode"] = "WiFi";
#endif
jsBody["GateWayHwVesion"] = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayHwVesion");
std::string dataBody = show_value_.write(jsBody);
jsonVal["cmdBody"] = dataBody;
char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp;
int res = data_publish(show_value_.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubStatus.c_str());
if(res !=0 ){
zlog_warn(zct, "data_publish res = %d", res);
}
return 0;
}
int JsonData::JsonCmd_30(){
Json::Value jsonVal;
Json::Value jsBody;
Json::Value jsSystemSetting;
Json::Value jsArray;
jsonVal.clear();
jsonVal["cmd"] = "30";
array_t arrRes; array_t arrRes;
arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL); arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), "*", NULL);
int iResult = arrRes.size(); int iResult = arrRes.size();
if (iResult > 0) { if (iResult > 0) {
for (int i = 0; i < iResult; i++) { for (int j = 0; j < iResult; j++) {
Json::Value jsDataNode; Json::Value jsSensorData;
jsDataNode["dataNodeNo"] = arrRes[i][0]; jsSensorData["dataNodeNo"] = arrRes[j][44];
jsDataNode["status"] = atoi(arrRes[i][37].c_str()); jsSensorData["dataNodeName"] = arrRes[j][1];
jsBody["dataNodeArray"].append(jsDataNode); jsSensorData["acc"] = atoi(arrRes[j][3].c_str());
jsSensorData["zigbee"] = atoi(arrRes[j][4].c_str());
jsSensorData["temTop"] = atoi(arrRes[j][5].c_str());
jsSensorData["temBot"] = atoi(arrRes[j][6].c_str());
jsSensorData["hwVersion"] = arrRes[j][8];
jsSensorData["softVersion"] = arrRes[j][9];
jsSensorData["bpNo"] = arrRes[j][10];
jsSensorData["serialNo"] = arrRes[j][11];
jsSensorData["firstPowerTime"] = arrRes[j][12];
jsSensorData["WakeupTime"] = atoi(arrRes[j][13].c_str());
jsSensorData["StaticTime"] = atoi(arrRes[j][14].c_str());
jsSensorData["WaveTime"] = atoi(arrRes[j][15].c_str());
jsSensorData["BateryV"] = arrRes[j][16];
jsSensorData["ProductNo"] = arrRes[j][17];
jsSensorData["configFlag"] = atoi(arrRes[j][18].c_str());
jsSensorData["startBrands"] = arrRes[j][19];
jsSensorData["stopBrands"] = arrRes[j][20];
jsSensorData["featureInterVal"] = atoi(arrRes[j][21].c_str());
jsSensorData["waveInterVal"] = atoi(arrRes[j][22].c_str());
jsSensorData["samplingRate"] = atoi(arrRes[j][23].c_str());
jsSensorData["range"] = atoi(arrRes[j][25].c_str());
jsSensorData["envelopeBandPass"] = arrRes[j][26];
jsSensorData["faultFrequency"] = arrRes[j][27];
jsSensorData["zigbeePanId"] = arrRes[j][28];
jsSensorData["zigbeeChannel"] = (arrRes[j][29]);
jsSensorData["zigbeeAddr"] = arrRes[j][30];
jsSensorData["zigbeeLongAddr"] = arrRes[j][31];
jsSensorData["zigbeeDesAddr"] = arrRes[j][32];
jsSensorData["ZigbeePower"] = atoi(arrRes[j][33].c_str());
jsSensorData["ZigbeeRetry"] = atoi(arrRes[j][34].c_str());
jsSensorData["ZigbeeRetryGap"] = atoi(arrRes[j][35].c_str());
jsSensorData["ACCSampleTime"] = atoi(arrRes[j][36].c_str());
jsSensorData["status"] = atoi(arrRes[j][37].c_str());
jsSensorData["timeStamp"] = arrRes[j][38];
jsSensorData["viff"] = atoi(arrRes[j][39].c_str());
std::vector<std::string> vParam;
boost::split(vParam, arrRes[j][42], boost::is_any_of(","), boost::token_compress_on);
if (vParam.size() > 1){
if (vParam[1] != "0"){
jsSensorData["looseStatus"] = 1;
}else{
jsSensorData["looseStatus"] = 0;
}
}
std::vector<std::string> vParamRSSI;
boost::split(vParamRSSI, arrRes[j][40], boost::is_any_of(","), boost::token_compress_on);
if (vParamRSSI.size() > 1) {
jsSensorData["gatewayRSSI"] = atoi(vParamRSSI[0].c_str());
jsSensorData["sensorRSSI"] = atoi(vParamRSSI[1].c_str());
} else {
jsSensorData["gatewayRSSI"] = 0;
jsSensorData["sensorRSSI"] = atoi(arrRes[j][40].c_str());
}
jsSensorData["update"] = atoi(arrRes[j][41].c_str());
jsSensorData["MeasurementID"] = arrRes[j][44];
std::vector<std::string> vParambattery;
boost::split(vParambattery, arrRes[j][43], boost::is_any_of(","), boost::token_compress_on);
if (vParambattery.size() > 1) {
jsSensorData["battery"] = atoi(vParambattery[1].c_str())/atoi(vParambattery[0].c_str());
} else {
jsSensorData["battery"] = 0.99;
}
jsArray.append(jsSensorData);
} }
} else {
jsArray.resize(0);
jsonVal["success"] = true;
} }
jsBody["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
std::string strBody = show_value_.write(jsBody); jsBody["dataNodeArray"] = jsArray;
jsonVal["cmdBody"] = strBody; std::string dataBody = show_value_.write(jsBody);
return show_value_.write(jsonVal); jsonVal["cmdBody"] = dataBody;
char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp;
int res = data_publish(show_value_.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubStatus.c_str());
if(res !=0 ){
zlog_warn(zct, "data_publish res = %d", res);
}
return 0;
} }
int JsonData::JsonCmd_31(){
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "31";
jsonVal["success"] = true;
jsonVal["message"] = "";
int sensorCount = 0;
int featureInterVal = 0;
int featureInterTime = 0;
int waveInterVal = 0;
int waveInterTime = 0;
int maxSensorNum = 0;
sensorCount = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), NULL);
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,featureInterTime,waveInterTime,maxSensorNum);
jsBody["featureInterVal"] = featureInterVal;
jsBody["featureInterTime"] = featureInterTime;
jsBody["waveInterVal"] = waveInterVal;
jsBody["waveInterTime"] = waveInterTime;
jsBody["maxSensorNum"] = maxSensorNum;
jsBody["sensorCount"] = sensorCount;
std::string dataBody = show_value_.write(jsBody);
jsonVal["cmdBody"] = dataBody;
char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp;
int res = data_publish(show_value_.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubStatus.c_str());
if(res !=0 ){
zlog_warn(zct, "data_publish res = %d", res);
}
return 0;
}
int JsonData::JsonCmd_32(std::string MeasurementID,int status,int type,std::string Data,std::string Msg){
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
Json::FastWriter show_value_;
jsonVal["CMD"] = "32";
jsonVal["success"] = true;
jsonVal["message"] = "";
jsBody["dataNodeNo"] = MeasurementID;
jsBody["errorStatus"] = status;
jsBody["errorType"] = type;
jsBody["errorData"] = Data;
jsBody["errorMsg"] = Msg;
std::string dataBody = show_value_.write(jsBody);
jsonVal["cmdBody"] = dataBody;
char timestamp[32] = {0};
GetTimeNet(timestamp, 1);
jsonVal["timestamp"] = timestamp;
int res = data_publish(show_value_.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubStatus.c_str());
if(res !=0 ){
zlog_warn(zct, "data_publish res = %d", res);
}
return 0;
}
void JsonData::DataNodeStatusCheck() { void JsonData::DataNodeStatusCheck() {
array_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL); array_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL);
int nSize = vetRes.size(); int nSize = vetRes.size();
@ -567,6 +732,9 @@ std::string JsonData::JsonCmd_07() {
jsonVal[JSON_FIELD_CMD] = "07"; jsonVal[JSON_FIELD_CMD] = "07";
jsonVal["success"] = true; jsonVal["success"] = true;
jsonVal["message"] = " "; jsonVal["message"] = " ";
char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1);
jsonVal["timestamp"] = localtimestamp;
if (recvReader.parse(sysStatus, recvSys)) { if (recvReader.parse(sysStatus, recvSys)) {
jsonVal["cmdBody"] = sysStatus; jsonVal["cmdBody"] = sysStatus;
} else { } else {

View File

@ -119,12 +119,9 @@ void CheckThread() {
if (600 == online_check) { if (600 == online_check) {
online_check = 0; online_check = 0;
int Count = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), NULL); int Count = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), NULL);
JsonData jd;
if (Count > 0) { if (Count > 0) {
JsonData jd;
jd.DataNodeStatusCheck(); jd.DataNodeStatusCheck();
Param_29 param;
std::string cmd29 = jd.JsonCmd_29(param);
data_publish(cmd29.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
char localtimestamp[32] = {0}; char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
std::string nowTimetamp = std::string(localtimestamp); std::string nowTimetamp = std::string(localtimestamp);
@ -135,6 +132,10 @@ void CheckThread() {
long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str()); long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str());
zlog_info(zct, "online check = %ld", lTime); zlog_info(zct, "online check = %ld", lTime);
} }
jd.JsonCmd_07();
jd.JsonCmd_29();
jd.JsonCmd_30();
jd.JsonCmd_31();
} }
if (7200 == Battery) { if (7200 == Battery) {
Battery = 0; Battery = 0;

View File

@ -17,6 +17,7 @@
#include "mqttclient/mqtt_client.h" #include "mqttclient/mqtt_client.h"
#include "utility/serial.h" #include "utility/serial.h"
#include "scheduler/schedule.hpp" #include "scheduler/schedule.hpp"
#include "jsonparse/communication_cmd.hpp"
extern zlog_category_t *zct; extern zlog_category_t *zct;
extern zlog_category_t *zbt; extern zlog_category_t *zbt;
@ -1041,20 +1042,26 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
char insertSql[100] = {0x00}; char insertSql[100] = {0x00};
char whereCon[50] = {0x00}; char whereCon[50] = {0x00};
char error_msg[50] = {0x00}; std::string error_msg = "";
std::string strChannelID = "";
sprintf(whereCon, "zigbeeShortAddr='%s'",strShortAddr.c_str()); sprintf(whereCon, "zigbeeShortAddr='%s'",strShortAddr.c_str());
std::string strDataNodeNo = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " dataNodeNo ", whereCon); std::string strMeasurementID = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " MeasurementID ", whereCon);
memset(whereCon, 0x00, sizeof(whereCon)); memset(whereCon, 0x00, sizeof(whereCon));
if (command == WAVE_X){ if (command == WAVE_X){
sprintf(error_msg,"Index error,wave X"); error_msg = "Index error,wave X";
strChannelID = strMeasurementID + "-X";
}else if (command == WAVE_Y){ }else if (command == WAVE_Y){
sprintf(error_msg,"Index error,wave Y"); error_msg = "Index error,wave Y";
strChannelID = strMeasurementID + "-Y";
}else if (command == WAVE_Z){ }else if (command == WAVE_Z){
sprintf(error_msg,"Index error,wave Z"); error_msg = "Index error,wave Z";
strChannelID = strMeasurementID + "-Z";
} }
sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strDataNodeNo.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg); sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strMeasurementID.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg.c_str());
sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql);
JsonData jd;
jd.JsonCmd_32(strMeasurementID,1,1,strChannelID,error_msg);
break; break;
} }
@ -1079,20 +1086,22 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
g_VecWaveDataZ.clear(); g_VecWaveDataZ.clear();
char insertSql[100] = {0x00}; char insertSql[100] = {0x00};
char whereCon[50] = {0x00}; char whereCon[50] = {0x00};
char error_msg[50] = {0x00}; std::string error_msg = "";
std::string strChannelID = "";
sprintf(whereCon, "zigbeeShortAddr='%s'",strShortAddr.c_str()); sprintf(whereCon, "zigbeeShortAddr='%s'",strShortAddr.c_str());
std::string strDataNodeNo = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " dataNodeNo ", whereCon); std::string strMeasurementID = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " MeasurementID ", whereCon);
memset(whereCon, 0x00, sizeof(whereCon)); memset(whereCon, 0x00, sizeof(whereCon));
if (command == WAVE_X){ if (command == WAVE_X){
sprintf(error_msg,"Crc error,wave X"); error_msg = "Crc error,wave X";
}else if (command == WAVE_Y){ }else if (command == WAVE_Y){
sprintf(error_msg,"Crc error,wave Y"); error_msg = "Crc error,wave Y";
}else if (command == WAVE_Z){ }else if (command == WAVE_Z){
sprintf(error_msg,"Crc error,wave Z"); error_msg = "Crc error,wave Z";
} }
sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strDataNodeNo.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg); sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strMeasurementID.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg.c_str());
sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql);
JsonData jd;
jd.JsonCmd_32(strMeasurementID,1,1,strChannelID,error_msg);
break; break;
} }
mlastSize = 0; mlastSize = 0;

View File

@ -10,6 +10,7 @@
#include <json/json.h> #include <json/json.h>
#include "mqttclient/mqtt_client.h" #include "mqttclient/mqtt_client.h"
#include "minilzo/minilzo.h" #include "minilzo/minilzo.h"
#include "jsonparse/communication_cmd.hpp"
extern zlog_category_t *zct; extern zlog_category_t *zct;
extern zlog_category_t *zbt; extern zlog_category_t *zbt;
@ -576,7 +577,8 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
//综上代码把静态数据x y z轴的特征值存放到sql数据库中如果数据原来不存在则插入新数据如果存在则更新数据 //综上代码把静态数据x y z轴的特征值存放到sql数据库中如果数据原来不存在则插入新数据如果存在则更新数据
zlog_info(zct, "Dip : %d TemBot : %f TemBot : %f Voltage : %d", dataStatic.Dip, dataStatic.TemBot, dataStatic.TemTop, dataStatic.Voltage); zlog_info(zct, "Dip : %d TemBot : %f TemBot : %f Voltage : %d", dataStatic.Dip, dataStatic.TemBot, dataStatic.TemTop, dataStatic.Voltage);
JsonData jd;
jd.JsonCmd_32(strMeasurementID,0,0,"","");
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);
@ -995,11 +997,16 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
system(tmpCmd); system(tmpCmd);
zlog_info(zct, "rm dat file %s \n", tmpCmd); zlog_info(zct, "rm dat file %s \n", tmpCmd);
} }
JsonData jd;
jd.JsonCmd_32(strMeasurementID,1,1,strChannelID,"send failed");
} else { } else {
zlog_warn(zct, "send data , filename %s,size = %d\n", strFileName.c_str(), vecData.size()); zlog_warn(zct, "send data , filename %s,size = %d\n", strFileName.c_str(), vecData.size());
} }
JsonData jd;
jd.JsonCmd_32(strMeasurementID,0,1,strChannelID,"");
zlog_info(zct, "write data to filename %s", strFileName.c_str()); zlog_info(zct, "write data to filename %s", strFileName.c_str());
std::vector<float>().swap(vecData); std::vector<float>().swap(vecData);
sleep(1); sleep(1);
} }