fix bugs
This commit is contained in:
parent
4064335a21
commit
fab386fabc
@ -18,10 +18,10 @@ enum enumZigBeeTransmitStatus {
|
|||||||
|
|
||||||
|
|
||||||
//#define NR5G_MODULE
|
//#define NR5G_MODULE
|
||||||
#define Q4G_MODULE
|
//#define Q4G_MODULE
|
||||||
//#define WIFI_MODULE
|
//#define WIFI_MODULE
|
||||||
//#define NR5G_MEIGE
|
//#define NR5G_MEIGE
|
||||||
//#define BLUETEETH_MODULE
|
#define BLUETEETH_MODULE
|
||||||
|
|
||||||
|
|
||||||
class GlobalConfig
|
class GlobalConfig
|
||||||
|
|||||||
@ -373,19 +373,20 @@ struct Param_65 {
|
|||||||
struct Param_100{
|
struct Param_100{
|
||||||
int mPackageFlag;
|
int mPackageFlag;
|
||||||
Param_100() : mPackageFlag(0){};
|
Param_100() : mPackageFlag(0){};
|
||||||
}
|
};
|
||||||
|
|
||||||
struct Param_101{
|
struct Param_101{
|
||||||
std::string mac;
|
std::string mac;
|
||||||
std::string timeStart;
|
std::string timeStart;
|
||||||
std::string timeEnd;
|
std::string timeEnd;
|
||||||
int mPackageFlag;
|
int mPackageFlag;
|
||||||
Param_61() : mac(""),straxis(""),timeStart(""),timeEnd(""),mPackageFlag(0){};
|
Param_101() : mac(""),timeStart(""),timeEnd(""),mPackageFlag(0){};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Param_103{
|
struct Param_103{
|
||||||
std::string mac;
|
std::string mac;
|
||||||
int operate; // 0:添加 1:删除
|
std::string name;
|
||||||
Param_103() : mac(""),operate(0){};
|
std::string operate;
|
||||||
|
Param_103() : mac(""),name(""),operate(""){};
|
||||||
};
|
};
|
||||||
#endif // PARAMETER_DEFINATION_HPP_
|
#endif // PARAMETER_DEFINATION_HPP_
|
||||||
|
|||||||
@ -26,6 +26,8 @@ const char *T_GATEWAY_INFO1[] = {"t_gateway_info", "gatewayMAC", "sensorVers
|
|||||||
"systemVersion", "programVersion", "webVersion", "serverIP", "serverPort", "status", "gateWayUpdate", "MAC2"};
|
"systemVersion", "programVersion", "webVersion", "serverIP", "serverPort", "status", "gateWayUpdate", "MAC2"};
|
||||||
|
|
||||||
const char *T_BATTERY_INFO1[] = {"t_battery_info", "dataNodeNo", "Dip", "temBot", "nodeWorkTime", "nodeSendTime", "batteryVoltage", "batteryUsage", "batteryRemain", "timeStamp"};
|
const char *T_BATTERY_INFO1[] = {"t_battery_info", "dataNodeNo", "Dip", "temBot", "nodeWorkTime", "nodeSendTime", "batteryVoltage", "batteryUsage", "batteryRemain", "timeStamp"};
|
||||||
|
|
||||||
|
const char *T_SENSOR_BT_INFO1[] = {"t_sensor_bt_info", "mac", "name","type", "status", "timeStamp"};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
SqliteDB::SqliteDB() {}
|
SqliteDB::SqliteDB() {}
|
||||||
@ -265,6 +267,8 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
|||||||
execute_sql_file("/opt/configenv/reboot_record.sql");
|
execute_sql_file("/opt/configenv/reboot_record.sql");
|
||||||
|
|
||||||
execute_sql_file("/opt/configenv/blueteeth_info.sql");
|
execute_sql_file("/opt/configenv/blueteeth_info.sql");
|
||||||
|
|
||||||
|
execute_sql_file("/opt/configenv/t_sensor_bt_info.sql");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqliteDB::Createtable(const char *ptableName) {
|
void SqliteDB::Createtable(const char *ptableName) {
|
||||||
|
|||||||
@ -16,6 +16,7 @@ extern const char *T_DATASTATIC_INFO1[];
|
|||||||
extern const char *T_DATANODE_TIME1[];
|
extern const char *T_DATANODE_TIME1[];
|
||||||
extern const char *T_GATEWAY_INFO1[];
|
extern const char *T_GATEWAY_INFO1[];
|
||||||
extern const char *T_BATTERY_INFO1[];
|
extern const char *T_BATTERY_INFO1[];
|
||||||
|
extern const char *T_SENSOR_BT_INFO1[];
|
||||||
|
|
||||||
#define T_SENSOR_INFO(x) T_SENSOR_INFO1[T_SENSOR_INFO_##x]
|
#define T_SENSOR_INFO(x) T_SENSOR_INFO1[T_SENSOR_INFO_##x]
|
||||||
#define T_DATA_INFO(x) T_DATA_INFO1[T_DATA_INFO_##x]
|
#define T_DATA_INFO(x) T_DATA_INFO1[T_DATA_INFO_##x]
|
||||||
@ -24,7 +25,7 @@ extern const char *T_BATTERY_INFO1[];
|
|||||||
#define T_DATANODE_TIME(x) T_DATANODE_TIME1[T_DATANODE_TIME_##x]
|
#define T_DATANODE_TIME(x) T_DATANODE_TIME1[T_DATANODE_TIME_##x]
|
||||||
#define T_BATTERY_INFO(x) T_BATTERY_INFO1[T_BATTERY_INFO_##x]
|
#define T_BATTERY_INFO(x) T_BATTERY_INFO1[T_BATTERY_INFO_##x]
|
||||||
|
|
||||||
#define T_SENSOR_BT_INFO(x) T_SENSOR_INFO1[T_SENSOR_BT_INFO_##x]
|
#define T_SENSOR_BT_INFO(x) T_SENSOR_BT_INFO1[T_SENSOR_BT_INFO_##x]
|
||||||
|
|
||||||
typedef std::map<std::string, std::string> map_t;
|
typedef std::map<std::string, std::string> map_t;
|
||||||
typedef std::vector<std::string> vec_t;
|
typedef std::vector<std::string> vec_t;
|
||||||
@ -203,4 +204,14 @@ typedef enum {
|
|||||||
|
|
||||||
} T_BATTERY_INFO_Index;
|
} T_BATTERY_INFO_Index;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
T_SENSOR_BT_INFO_TNAME = 0,
|
||||||
|
T_SENSOR_BT_INFO_MAC,
|
||||||
|
T_SENSOR_BT_INFO_NAME,
|
||||||
|
T_SENSOR_BT_INFO_TYPE,
|
||||||
|
T_SENSOR_BT_INFO_STATUS,
|
||||||
|
T_SENSOR_BT_INFO_CONFIG_DATE,
|
||||||
|
|
||||||
|
} T_SENSOR_BT_INFO_Index;
|
||||||
|
|
||||||
#endif // SQL_DB_HPP_
|
#endif // SQL_DB_HPP_
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
extern zlog_category_t *zct;
|
extern zlog_category_t *zct;
|
||||||
extern const char *JSON_FIELD_CMD;
|
extern const char *JSON_FIELD_CMD;
|
||||||
extern std::map<std::string, std::string> device_map;
|
extern std::map<std::string, int8_t> device_map;
|
||||||
std::string JsonData::JsonCmd_Cgi_100(Param_100 ¶m){
|
std::string JsonData::JsonCmd_Cgi_100(Param_100 ¶m){
|
||||||
Json::Value jsonVal;
|
Json::Value jsonVal;
|
||||||
jsonVal.clear();
|
jsonVal.clear();
|
||||||
@ -18,7 +18,7 @@ std::string JsonData::JsonCmd_Cgi_100(Param_100 ¶m){
|
|||||||
|
|
||||||
Json::Value jsBody;
|
Json::Value jsBody;
|
||||||
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_BT_INFO(TNAME), "*", NULL);
|
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_BT_INFO(TNAME), "*", NULL);
|
||||||
|
int iResult = arrRes.size();
|
||||||
if (arrRes.size() > 0) {
|
if (arrRes.size() > 0) {
|
||||||
int packgeNo = param.mPackageFlag;
|
int packgeNo = param.mPackageFlag;
|
||||||
int packgeMax = 0;
|
int packgeMax = 0;
|
||||||
@ -44,7 +44,7 @@ std::string JsonData::JsonCmd_Cgi_100(Param_100 ¶m){
|
|||||||
packgeMax = index + 1;
|
packgeMax = index + 1;
|
||||||
jsonVal["packageMax"] = index;
|
jsonVal["packageMax"] = index;
|
||||||
}
|
}
|
||||||
for (size_t packgeNo * 10; j < packgeNum; i++) {
|
for (size_t i = packgeNo * 10; i < packgeNum; i++) {
|
||||||
Json::Value jsSensorData;
|
Json::Value jsSensorData;
|
||||||
jsSensorData["mac"] = arrRes[i][0];
|
jsSensorData["mac"] = arrRes[i][0];
|
||||||
jsSensorData["name"] = arrRes[i][1];
|
jsSensorData["name"] = arrRes[i][1];
|
||||||
@ -52,12 +52,14 @@ std::string JsonData::JsonCmd_Cgi_100(Param_100 ¶m){
|
|||||||
jsSensorData["status"] = atoi(arrRes[i][3].c_str());
|
jsSensorData["status"] = atoi(arrRes[i][3].c_str());
|
||||||
jsSensorData["config_date"] = atoi(arrRes[i][4].c_str());
|
jsSensorData["config_date"] = atoi(arrRes[i][4].c_str());
|
||||||
std::string strMac = arrRes[i][0];
|
std::string strMac = arrRes[i][0];
|
||||||
vec_t vec_ret = sqlite_db_ctrl::instance().GetDataMultiLine(" blueteeth_info ", "*", " oder by timestamp desc limit 1 ");
|
char whereCon[256] = {0x00};
|
||||||
|
sprintf(whereCon, "mac = '%s' order by timestamp desc limit 1 ", strMac.c_str());
|
||||||
|
vec_t vec_ret = sqlite_db_ctrl::instance().GetDataSingleLine(" blueteeth_info ", "*", whereCon);
|
||||||
jsSensorData["env_temp"] = atof(vec_ret[7].c_str());
|
jsSensorData["env_temp"] = atof(vec_ret[7].c_str());
|
||||||
jsSensorData["dev_temp"] = atof(vec_ret[6].c_str());
|
jsSensorData["dev_temp"] = atof(vec_ret[6].c_str());
|
||||||
jsSensorData["battery_v"] = atof(vec_ret[4].c_str());
|
jsSensorData["battery_v"] = atof(vec_ret[4].c_str());
|
||||||
jsSensorData["rssi"] = atoi(vec_ret[2].c_str());
|
jsSensorData["rssi"] = atoi(vec_ret[2].c_str());
|
||||||
jsSensorData["feature_date"] = vec_ret[i][8];
|
jsSensorData["feature_date"] = vec_ret[8];
|
||||||
jsBody.append(jsSensorData);
|
jsBody.append(jsSensorData);
|
||||||
}
|
}
|
||||||
jsonVal["content"] = jsBody;
|
jsonVal["content"] = jsBody;
|
||||||
@ -108,18 +110,16 @@ std::string JsonData::JsonCmd_Cgi_101(Param_101 ¶m){
|
|||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, "mac = '%s' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.mac.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
|
sprintf(whereCon, "mac = '%s' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.mac.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
|
||||||
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(" blueteeth_info ", "env_temp,chip_temp,volt,timestamp", whereCon);
|
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(" blueteeth_info ", "env_temp,chip_temp,volt,timestamp", whereCon);
|
||||||
zlog_info(zct, "vecRes = %d", vecRes.size());
|
if (arrRes.size() > 0) {
|
||||||
if (vecRes.size() > 0) {
|
|
||||||
Json::Value jsSensorData;
|
Json::Value jsSensorData;
|
||||||
for (size_t i = 0; i < vecRes.size(); i++) {
|
Json::Value iTem1, iTem2, iTem3;
|
||||||
|
for (size_t i = 0; i < arrRes.size(); i++) {
|
||||||
Json::Value iTem1, iTem2, iTem3;
|
iTem1.append(arrRes[i][0]);
|
||||||
iTem1.append(vecRes[i][0]);
|
iTem1.append(arrRes[i][3]);
|
||||||
iTem1.append(vecRes[i][3]);
|
iTem2.append(arrRes[i][1]);
|
||||||
iTem2.append(vecRes[i][1]);
|
iTem2.append(arrRes[i][3]);
|
||||||
iTem2.append(vecRes[i][3]);
|
iTem3.append(arrRes[i][2]);
|
||||||
iTem3.append(vecRes[i][2]);
|
iTem3.append(arrRes[i][3]);
|
||||||
iTem3.append(vecRes[i][3]);
|
|
||||||
}
|
}
|
||||||
jsSensorData["env_temp"] = iTem1;
|
jsSensorData["env_temp"] = iTem1;
|
||||||
jsSensorData["chip_temp"] = iTem2;
|
jsSensorData["chip_temp"] = iTem2;
|
||||||
@ -131,9 +131,10 @@ std::string JsonData::JsonCmd_Cgi_101(Param_101 ¶m){
|
|||||||
jsonVal["message"] = "没有传感器信息";
|
jsonVal["message"] = "没有传感器信息";
|
||||||
jsonVal["content"].resize(0);
|
jsonVal["content"].resize(0);
|
||||||
}
|
}
|
||||||
|
return show_value_.write(jsonVal);
|
||||||
}
|
}
|
||||||
std::string JsonData::JsonCmd_Cgi_102(){
|
std::string JsonData::JsonCmd_Cgi_102(){
|
||||||
for (size_t i = 0; i < device_map.size; i++)
|
for (auto it = device_map.begin(); it != device_map.end(); ++it)
|
||||||
{
|
{
|
||||||
Json::Value jsonVal;
|
Json::Value jsonVal;
|
||||||
jsonVal.clear();
|
jsonVal.clear();
|
||||||
@ -142,12 +143,16 @@ std::string JsonData::JsonCmd_Cgi_102(){
|
|||||||
jsonVal["message"] = "获取传感器信息成功";
|
jsonVal["message"] = "获取传感器信息成功";
|
||||||
|
|
||||||
Json::Value jsBody;
|
Json::Value jsBody;
|
||||||
jsBody["mac"] = device_map[i].first;
|
jsBody["mac"] = it->first;
|
||||||
sqlite_db_ctrl::instance().GetRowCount(T_SENSOR_BT_INFO(TNAME), "count(*)", "mac = '" + device_map[i].first + "'");
|
char whereCon[256] = {0x00};
|
||||||
|
sprintf(whereCon, "mac = '%s'", it->first.c_str());
|
||||||
|
int rows = sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_BT_INFO(TNAME), whereCon);
|
||||||
if (rows > 1) {
|
if (rows > 1) {
|
||||||
jsBody["added"] = true;
|
jsBody["added"] = true;
|
||||||
|
}else {
|
||||||
|
jsBody["added"] = false;
|
||||||
}
|
}
|
||||||
jsBody["rssi"] = device_map[i].second;
|
jsBody["rssi"] = it->second;
|
||||||
jsonVal["content"] = jsBody;
|
jsonVal["content"] = jsBody;
|
||||||
|
|
||||||
return show_value_.write(jsonVal);
|
return show_value_.write(jsonVal);
|
||||||
@ -160,14 +165,19 @@ std::string JsonData::JsonCmd_Cgi_103(Param_103 ¶m){
|
|||||||
jsonVal[JSON_FIELD_CMD] = "103";
|
jsonVal[JSON_FIELD_CMD] = "103";
|
||||||
jsonVal["success"] = true;
|
jsonVal["success"] = true;
|
||||||
jsonVal["message"] = "获取传感器信息成功";
|
jsonVal["message"] = "获取传感器信息成功";
|
||||||
|
char insertSql[256] = {0x00},updateSql[256] = {0x00},
|
||||||
|
whereCon[256] = {0x00};
|
||||||
|
char localtimestamp[32] = {0};
|
||||||
|
sprintf(whereCon, "mac = '%s'", param.mac.c_str());
|
||||||
|
GetTimeNet(localtimestamp, 1);
|
||||||
if (param.operate == "add") {
|
if (param.operate == "add") {
|
||||||
sqlite_db_ctrl::instance().InsertData(T_SENSOR_BT_INFO(TNAME), "mac,name,type,status,config_date",
|
sprintf(insertSql, "'%s','','DN-801','0','%s'", param.mac.c_str(),localtimestamp);
|
||||||
"'" + param.mac + "','" + param.name + "'," + std::to_string(param.type) + "," + std::to_string(param.status) + "," + std::to_string(param.config_date));
|
sqlite_db_ctrl::instance().InsertData(T_SENSOR_BT_INFO(TNAME), insertSql);
|
||||||
} else if (param.operate == "update") {
|
} else if (param.operate == "update") {
|
||||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_BT_INFO(TNAME), "name = '" + param.name ,"mac = '" + param.mac + "'");
|
sprintf(updateSql, "name = '%s'", param.name.c_str());
|
||||||
|
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_BT_INFO(TNAME), updateSql,whereCon);
|
||||||
} else if (param.operate == "delete") {
|
} else if (param.operate == "delete") {
|
||||||
sqlite_db_ctrl::instance().DeleteData(T_SENSOR_BT_INFO(TNAME), "mac = '" + param.mac + "'");
|
sqlite_db_ctrl::instance().DeleteTableData(T_SENSOR_BT_INFO(TNAME), whereCon);
|
||||||
}
|
}
|
||||||
|
|
||||||
return show_value_.write(jsonVal);
|
return show_value_.write(jsonVal);
|
||||||
|
|||||||
@ -548,7 +548,7 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
|||||||
JsonData jd;
|
JsonData jd;
|
||||||
Param_103 param;
|
Param_103 param;
|
||||||
param.mac = recvBody["mac"].asString();
|
param.mac = recvBody["mac"].asString();
|
||||||
param.operate = recvBody["operate"].asInt();
|
param.operate = recvBody["operate"].asString();
|
||||||
std::string data = jd.JsonCmd_Cgi_103(param);
|
std::string data = jd.JsonCmd_Cgi_103(param);
|
||||||
return data;
|
return data;
|
||||||
}break;
|
}break;
|
||||||
|
|||||||
@ -13,11 +13,13 @@
|
|||||||
#include <bluetooth/hci_lib.h>
|
#include <bluetooth/hci_lib.h>
|
||||||
#include <zlog.h>
|
#include <zlog.h>
|
||||||
#include "common/common_func.hpp"
|
#include "common/common_func.hpp"
|
||||||
|
#include "common/global.hpp"
|
||||||
#include "dbaccess/sql_db.hpp"
|
#include "dbaccess/sql_db.hpp"
|
||||||
|
#include "mqttclient/mqtt_client.h"
|
||||||
|
|
||||||
extern zlog_category_t *zct;
|
extern zlog_category_t *zct;
|
||||||
|
|
||||||
std::map<std::string, std::string> ScanBlueteeth::device_map;
|
std::map<std::string, int8_t> device_map;
|
||||||
|
|
||||||
ScanBlueteeth::ScanBlueteeth() : device_id(-1), sock(-1) {
|
ScanBlueteeth::ScanBlueteeth() : device_id(-1), sock(-1) {
|
||||||
retry_count = 0;
|
retry_count = 0;
|
||||||
@ -189,7 +191,21 @@ void ScanBlueteeth::ParseData(unsigned char *data, int len,int8_t rssi){
|
|||||||
sprintf(insertSql,"'%s','%s','%d',%d,'%.1f','%.1f','%.1f','%.1f','%s'",device_id,mac,rssi,count,volt_,blueteeth_temp,chip_temp,env_temp,localtimestamp);
|
sprintf(insertSql,"'%s','%s','%d',%d,'%.1f','%.1f','%.1f','%.1f','%s'",device_id,mac,rssi,count,volt_,blueteeth_temp,chip_temp,env_temp,localtimestamp);
|
||||||
sqlite_db_ctrl::instance().InsertData(" blueteeth_info ", insertSql);
|
sqlite_db_ctrl::instance().InsertData(" blueteeth_info ", insertSql);
|
||||||
}
|
}
|
||||||
device_map.insert({mac, rssi});
|
Json::Value root;
|
||||||
|
Json::Value valdatastatic;
|
||||||
|
valdatastatic["TemperatureTop"] = env_temp;
|
||||||
|
valdatastatic["TemperatureBot"] = chip_temp;
|
||||||
|
valdatastatic["Voltage"] = volt_;
|
||||||
|
valdatastatic["ChannelId"] = mac;
|
||||||
|
valdatastatic["TimeStamp"] = localtimestamp;
|
||||||
|
valdatastatic["dataNodeNo"] = mac;
|
||||||
|
root["data"] = valdatastatic;
|
||||||
|
root["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||||
|
Json::FastWriter featureValue;
|
||||||
|
std::string strstatisticData = featureValue.write(root);
|
||||||
|
|
||||||
|
int iRet = data_publish(strstatisticData.c_str(), GlobalConfig::Topic_G.mPubData.c_str());
|
||||||
|
device_map.insert(std::make_pair(std::string(mac), rssi));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user