modify mqtt
This commit is contained in:
parent
862b992c8c
commit
888bea8fa3
@ -257,6 +257,8 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
execute_sql_file("/opt/configenv/firmware_upgrade.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/receive_wave_status.sql");
|
||||
|
||||
execute_sql_file("/opt/configenv/reboot_record.sql");
|
||||
}
|
||||
|
||||
void SqliteDB::Createtable(const char *ptableName) {
|
||||
|
||||
@ -227,6 +227,9 @@ std::string JsonData::JsonCmd_26(Param_26 ¶m) {
|
||||
for (int j = 0; j < iResult; j++) {
|
||||
Json::Value jsSensorData;
|
||||
jsSensorData["dataNodeNo"] = arrRes[j][44];
|
||||
char NodeName[100]={0};
|
||||
stringToHex(arrRes[j][1].c_str(),NodeName);
|
||||
jsSensorData["dataNodeNameHex"] = NodeName;
|
||||
jsSensorData["dataNodeName"] = arrRes[j][1];
|
||||
jsSensorData["initFlag"] = atoi(arrRes[j][2].c_str());
|
||||
jsSensorData["accFlag"] = atoi(arrRes[j][3].c_str());
|
||||
@ -523,7 +526,9 @@ int JsonData::JsonCmd_30(){
|
||||
for (int j = 0; j < iResult; j++) {
|
||||
Json::Value jsSensorData;
|
||||
jsSensorData["dataNodeNo"] = arrRes[j][44];
|
||||
jsSensorData["dataNodeName"] = arrRes[j][1];
|
||||
char NodeName[100]={0};
|
||||
stringToHex(arrRes[j][1].c_str(),NodeName);
|
||||
jsSensorData["dataNodeName"] = NodeName;
|
||||
jsSensorData["acc"] = atoi(arrRes[j][3].c_str());
|
||||
jsSensorData["zigbee"] = atoi(arrRes[j][4].c_str());
|
||||
|
||||
@ -581,7 +586,7 @@ int JsonData::JsonCmd_30(){
|
||||
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());
|
||||
jsSensorData["battery"] = float(atof(vParambattery[1].c_str())/atof(vParambattery[0].c_str()));
|
||||
} else {
|
||||
jsSensorData["battery"] = 0.99;
|
||||
}
|
||||
@ -700,16 +705,12 @@ void JsonData::DataNodeStatusCheck() {
|
||||
char whereCon[32] = {0};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", strDataNodeNo.c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), "status='0'", whereCon);
|
||||
count++;
|
||||
} else {
|
||||
char whereCon[32] = {0};
|
||||
sprintf(whereCon, "dataNodeNo='%s'", strDataNodeNo.c_str());
|
||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), "status='1'", whereCon);
|
||||
}
|
||||
if (lTimeTemp > atoi(vetRes[i][21].c_str()) * 5 * 60) //判定传感器是否超过五次未传特征值
|
||||
{
|
||||
zlog_info(zct, "lTimeTemp = %d,featureInterVal = %d", lTimeTemp, atoi(vetRes[i][21].c_str()));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count == nSize && nodeOnline && count != 0) {
|
||||
|
||||
2
main.cpp
2
main.cpp
@ -142,7 +142,7 @@ int main(int argc, char *argv[]) {
|
||||
// gpio_set(GlobalConfig::GPIO_G.hardWatchDog, 1);
|
||||
// usleep(20000);
|
||||
// gpio_set(GlobalConfig::GPIO_G.hardWatchDog, 0);
|
||||
//WriteWatchDog(fd);
|
||||
// WriteWatchDog(fd);
|
||||
sleep(20);
|
||||
if (GlobalConfig::threadStatus == 0) {
|
||||
count++;
|
||||
|
||||
@ -98,9 +98,10 @@ void CheckThread() {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (HardStatus == 3600) { // one hour 3600
|
||||
if (HardStatus == 60) { // one hour 3600
|
||||
JsonData jd;
|
||||
jd.JsonCmd_07();
|
||||
jd.JsonCmd_30();
|
||||
HardStatus = 0;
|
||||
}
|
||||
if (mqttresend == 7200) {
|
||||
@ -137,12 +138,17 @@ void CheckThread() {
|
||||
}
|
||||
if (7200 == Battery) {
|
||||
Battery = 0;
|
||||
zlog_info(zct, "Battery");
|
||||
zlog_warn(zct, "Battery");
|
||||
sqlite_db_ctrl::instance().CalculateBattery();
|
||||
JsonData jd;
|
||||
jd.JsonCmd_30();
|
||||
jd.JsonCmd_07();
|
||||
jd.JsonCmd_29();
|
||||
jd.JsonCmd_31();
|
||||
}
|
||||
|
||||
if (3500 == loose_check) {
|
||||
zlog_info(zct, "loosecheck\n");
|
||||
zlog_warn(zct, "loosecheck\n");
|
||||
loose_check = 0;
|
||||
sqlite_db_ctrl::instance().CalculateDip();
|
||||
}
|
||||
|
||||
@ -209,15 +209,18 @@ void InitModule() {
|
||||
|
||||
#ifdef Q4G_MODULE
|
||||
|
||||
InitGpio(GlobalConfig::GPIO_G.commPower, 1); // 4G,5G模组供电,
|
||||
gpio_set(GlobalConfig::GPIO_G.commPower, 1);
|
||||
InitGpio(GlobalConfig::GPIO_G.commRest, 1);
|
||||
gpio_set(GlobalConfig::GPIO_G.commRest, 0); //高电平复位
|
||||
sleep(10);
|
||||
char szquectel[100] = {0x00};
|
||||
std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
||||
sprintf(szquectel, "/opt/quectel-CM/quectel-CM -s %s &", strAPN.c_str());
|
||||
system(szquectel);
|
||||
system("killall daemon_CM");
|
||||
InitGpio(GlobalConfig::GPIO_G.commPower,1);//4G,5G模组供电,
|
||||
gpio_set(GlobalConfig::GPIO_G.commPower,1);
|
||||
InitGpio(GlobalConfig::GPIO_G.commRest,1);
|
||||
gpio_set(GlobalConfig::GPIO_G.commRest,0);//高电平复位
|
||||
sleep(10);
|
||||
char szquectel[100]={0x00};
|
||||
std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
||||
sprintf(szquectel,"/opt/quectel-CM/quectel-CM -s %s &",strAPN.c_str());
|
||||
system(szquectel);
|
||||
sleep(2);
|
||||
system("/opt/Cidn/daemon_CM &");
|
||||
#endif // Q4G_MODULE
|
||||
#ifdef WIFI_MODULE
|
||||
zlog_info(zbt, "Init WiFi!");
|
||||
|
||||
@ -183,7 +183,7 @@ public:
|
||||
void DealWave();
|
||||
std::vector<float> DealData(int ichannel, float coe, unsigned int sampleRate, int ACCSampleTime, std::string strProduct);
|
||||
float Calcoe(int ran, int iChannel, std::string& product, int range);
|
||||
void WriteDatFile(int sampleRate, std::string& strMeasurementID, int iChannel, std::vector<float>& vecData,std::string &product);
|
||||
void WriteDatFile(int sampleRate, std::string& strMeasurementID, int iChannel, std::vector<float>& vecData,std::string &product,int ACCSampleTime);
|
||||
float ScaleConvert(int highbit);
|
||||
void DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n);
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ std::map<std::string, WaveChannel> g_mapWaveChannel;
|
||||
unsigned char data[96000] = {0x00};
|
||||
unsigned char outdata[96000] = {0x00};
|
||||
unsigned char dealdata[96000] = {0x00};
|
||||
char mqttData[512000] = {0};
|
||||
char mqttData[1024000] = {0};
|
||||
|
||||
void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, std::string &nowTimetamp) {
|
||||
char insertSql[1024] = {0};
|
||||
@ -802,7 +802,7 @@ void Uart::DealWave() {
|
||||
zlog_info(zct, "m_waveCountX = %d,VecWaveData = %d", m_waveCountX, VecWaveDataX.size());
|
||||
coe = Calcoe(n, WAVE_X, strProduct, range);
|
||||
vecData = DealData(WAVE_X, coe, sampleRate, ACCSampleTime, strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_X, vecData,strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_X, vecData,strProduct,ACCSampleTime);
|
||||
m_waveCountX = 0;
|
||||
g_VecWaveDataX.clear();
|
||||
VecWaveDataX.clear();
|
||||
@ -811,7 +811,7 @@ void Uart::DealWave() {
|
||||
zlog_info(zct, "m_waveCountY = %d,VecWaveData = %d", m_waveCountY, VecWaveDataY.size());
|
||||
coe = Calcoe(n, WAVE_Y, strProduct, range);
|
||||
vecData = DealData(WAVE_Y, coe, sampleRate, ACCSampleTime, strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Y, vecData,strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Y, vecData,strProduct,ACCSampleTime);
|
||||
m_waveCountY = 0;
|
||||
g_VecWaveDataY.clear();
|
||||
VecWaveDataY.clear();
|
||||
@ -820,7 +820,7 @@ void Uart::DealWave() {
|
||||
zlog_info(zct, "m_waveCountZ = %d,VecWaveDataZ = %d", m_waveCountZ, VecWaveDataZ.size());
|
||||
coe = Calcoe(n, WAVE_Z, strProduct, range);
|
||||
vecData = DealData(WAVE_Z, coe, sampleRate, ACCSampleTime, strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Z, vecData,strProduct);
|
||||
WriteDatFile(sampleRate, strMeasurementID, WAVE_Z, vecData,strProduct,ACCSampleTime);
|
||||
m_waveCountZ = 0;
|
||||
g_VecWaveDataZ.clear();
|
||||
VecWaveDataZ.clear();
|
||||
@ -845,7 +845,7 @@ float Uart::Calcoe(int ran, int iChannel, std::string &product, int range) {
|
||||
return coe;
|
||||
}
|
||||
|
||||
void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChannel, std::vector<float> &vecData,std::string &product) {
|
||||
void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChannel, std::vector<float> &vecData,std::string &product,int ACCSampleTime) {
|
||||
if (vecData.size() <= 0) return;
|
||||
std::string strFileName = "";
|
||||
char localtimestamp[32] = {0};
|
||||
@ -903,27 +903,31 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
if (product == "02" && sampleRate == 24000 && strMeasurementID == "8eff96feff141a88"){
|
||||
if (product == "02" && sampleRate == 24000 && iChannel == WAVE_Z){
|
||||
sampleRate = 25600;
|
||||
zlog_info(zct, " sampleRate = %d,product = %s ", sampleRate,product.c_str());
|
||||
size_t outSize = 25600;
|
||||
std::vector<float> outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
std::vector<float> outputData,outputData2;
|
||||
if (ACCSampleTime == 1){
|
||||
outputData = Calculation::fftInterpolate(vecData, outSize);
|
||||
}else if(ACCSampleTime == 2){
|
||||
std::vector<float> first_wave = std::vector<float>(vecData.begin(), vecData.begin() + vecData.size()/2);
|
||||
std::vector<float> second_wave = std::vector<float>(vecData.begin() + vecData.size()/2, vecData.end());
|
||||
outputData = Calculation::fftInterpolate(first_wave, outSize);
|
||||
outputData2 = Calculation::fftInterpolate(second_wave, outSize);
|
||||
for (size_t i = 0; i < outputData2.size(); i++)
|
||||
{
|
||||
outputData.push_back(outputData2[i]);
|
||||
}
|
||||
}
|
||||
zlog_info(zct, " outputData_size %d ", outputData.size());
|
||||
float mean = Calculation::mean(outputData);
|
||||
memset(mqttData,0,sizeof(mqttData));
|
||||
id = 0;
|
||||
strFileName = strFileName + std::string(localtimestamp);
|
||||
FILE *fp = fopen(strFileName.c_str(), "w");
|
||||
fwrite(localtimestamp,sizeof(localtimestamp),1,fp);
|
||||
for (size_t i = 0; i < outputData.size(); i++) {
|
||||
frTemp = outputData[i] - mean;
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
sprintf(buf, "%.2f", frTemp);
|
||||
fwrite(&frTemp,sizeof(float),1,fp);
|
||||
if (iChannel == WAVE_X){
|
||||
wave_channel.WaveChannelX[i] = frTemp;
|
||||
}else if (iChannel == WAVE_Y){
|
||||
wave_channel.WaveChannelY[i] = frTemp;
|
||||
}else if (iChannel == WAVE_Z){
|
||||
wave_channel.WaveChannelZ[i] = frTemp;
|
||||
}
|
||||
if(i != outputData.size() -1){
|
||||
strncpy(mqttData + id ,buf,strlen(buf));
|
||||
id = id + strlen(buf);
|
||||
@ -933,7 +937,6 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
strncpy(mqttData + id ,buf,strlen(buf));
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
zlog_info(zct, "fopen FIle vecData.size : %d end ", vecData.size());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user