暂存 使用4G接收处理可设置参数
This commit is contained in:
parent
e9f1bead29
commit
8af86dd502
|
@ -75,6 +75,7 @@ typedef struct
|
|||
uint16_t over_press;
|
||||
uint16_t low_press;
|
||||
uint8_t over_temp;
|
||||
uint8_t delay_close_count;
|
||||
int over_flow_press_diff_1kpa;
|
||||
int over_flow_press_diff_2kpa;
|
||||
int over_flow_press_diff_3kpa;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
// #define MQTT_HOST "120.25.151.173" // MQTT服务器地址
|
||||
#define MQTT_HOST "8.135.10.183" // MQTT服务器地址
|
||||
// #define MQTT_PORT 1883 // MQTT服务器端口
|
||||
#define MQTT_PORT 24539 // MQTT服务器端口
|
||||
#define MQTT_PORT 20609 // MQTT服务器端口
|
||||
#define MQTT_USER "guest" // MQTT用户名
|
||||
#define MQTT_PASS "guest" // MQTT密码
|
||||
#define CLIENT_ID "ZBF" // 客户端ID前缀
|
||||
|
|
|
@ -122,10 +122,13 @@ typedef struct __attribute__((packed))
|
|||
uint8_t humi; // 1B 阀门湿度 %RH
|
||||
int8_t rssi;
|
||||
uint8_t Lock; // 1B 阀门锁状态 0=解锁 1=锁定
|
||||
uint16_t over_pressure; // 2B 超压阈值 Pa
|
||||
uint16_t under_pressure; // 2B 欠压阈值 Pa
|
||||
uint8_t over_temp; // 1B 超温阈值 ℃
|
||||
uint16_t delay_close_time; // 2B 延时关阀时间 分钟
|
||||
} TsValveData;
|
||||
extern TsValveData gValveData;
|
||||
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
uint32_t timer_minutes; // 设置的定时分钟数,0表示未激活
|
||||
|
|
|
@ -699,6 +699,7 @@ void VALVE_SetInfo()
|
|||
ValveInfo.over_press = 6200;
|
||||
ValveInfo.low_press = 680;
|
||||
ValveInfo.over_temp = 65;
|
||||
ValveInfo.delay_close_count = 6;
|
||||
|
||||
ValveInfo.over_flow_press_diff_1kpa = 650;
|
||||
ValveInfo.over_flow_press_diff_2kpa = 650;
|
||||
|
@ -1023,9 +1024,9 @@ uint16_t Check_ProcessEvent(uint8_t task_id, uint16_t events)
|
|||
uint8_t over_temp_count = 0;
|
||||
|
||||
// 检查三个传感器的温度是否超过阈值
|
||||
if (T[0] > SAFETY_OVER_TEMP_THRESHOLD) over_temp_count++;
|
||||
if (T[1] > SAFETY_OVER_TEMP_THRESHOLD) over_temp_count++;
|
||||
if (T[2] > SAFETY_OVER_TEMP_THRESHOLD) over_temp_count++;
|
||||
if (T[0] > ValveInfo.over_temp) over_temp_count++;
|
||||
if (T[1] > ValveInfo.over_temp) over_temp_count++;
|
||||
if (T[2] > ValveInfo.over_temp) over_temp_count++;
|
||||
|
||||
// 如果至少有两个传感器超过阈值,触发关阀
|
||||
if (over_temp_count >= 2)
|
||||
|
@ -1100,7 +1101,7 @@ uint16_t Check_ProcessEvent(uint8_t task_id, uint16_t events)
|
|||
valve_safety.auto_close_check_count, ValveRawData.in_out_press_diff);
|
||||
|
||||
// 如果已经检测了6次(30分钟),执行关阀
|
||||
if (valve_safety.auto_close_check_count >= AUTO_CLOSE_CHECK_COUNT)
|
||||
if (valve_safety.auto_close_check_count >= ValveInfo.delay_close_count)
|
||||
{
|
||||
logError("******************************");
|
||||
logError("延时关阀:30分钟无流量,自动关闭阀门");
|
||||
|
|
|
@ -170,7 +170,7 @@ void StopTask_CallBack(MultiTimer* timer, void* userData)
|
|||
static int parse_server_json_data(const char* json_str)
|
||||
{
|
||||
lwjson_t lwjson;
|
||||
lwjson_token_t tokens[64]; // 增加token数量以处理复杂的JSON结构
|
||||
lwjson_token_t tokens[64];
|
||||
const lwjson_token_t* token;
|
||||
|
||||
// 初始化lwjson
|
||||
|
@ -289,11 +289,49 @@ static int parse_server_json_data(const char* json_str)
|
|||
logDebug("Signal: %d\r\n", signal);
|
||||
}
|
||||
|
||||
// 超压阈值
|
||||
token = lwjson_find(&lwjson, "data.over_press");
|
||||
if (token != NULL && token->type == LWJSON_TYPE_NUM_INT) {
|
||||
uint16_t over_press = (uint16_t)token->u.num_int;
|
||||
logDebug("Over pressure threshold: %d Pa\r\n", over_press);
|
||||
// 更新阀门超压阈值
|
||||
ValveInfo.over_press = over_press;
|
||||
}
|
||||
|
||||
// 欠压阈值
|
||||
token = lwjson_find(&lwjson, "data.low_press");
|
||||
if (token != NULL && token->type == LWJSON_TYPE_NUM_INT) {
|
||||
uint16_t low_press = (uint16_t)token->u.num_int;
|
||||
logDebug("Low pressure threshold: %d Pa\r\n", low_press);
|
||||
// 更新阀门欠压阈值
|
||||
ValveInfo.low_press = low_press;
|
||||
}
|
||||
|
||||
// 延时关阀时间
|
||||
token = lwjson_find(&lwjson, "data.delay_close_time");
|
||||
if (token != NULL && token->type == LWJSON_TYPE_NUM_INT) {
|
||||
uint32_t delay_close_time = (uint32_t)token->u.num_int;
|
||||
logDebug("Delay close time: %d minutes\r\n", delay_close_time);
|
||||
// 更新阀门延时次数
|
||||
ValveInfo.delay_close_count = delay_close_time/5;
|
||||
logDebug("delay_close_count: %d \r\n", ValveInfo.delay_close_count);
|
||||
}
|
||||
|
||||
// 超温阈值
|
||||
token = lwjson_find(&lwjson, "data.over_temp");
|
||||
if (token != NULL && token->type == LWJSON_TYPE_NUM_INT) {
|
||||
uint8_t over_temp = (uint8_t)token->u.num_int;
|
||||
logDebug("Over temperature threshold: %d°C\r\n", over_temp);
|
||||
// 更新阀门超温阈值
|
||||
ValveInfo.over_temp = over_temp;
|
||||
}
|
||||
|
||||
// 释放资源
|
||||
lwjson_free(&lwjson);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//模块准备就绪
|
||||
static int URC_Module_Ready_Cb(at_urc_info_t *info)
|
||||
{
|
||||
|
@ -910,6 +948,7 @@ uint8_t BSP_4G_Generate_JsonData(Ts4GJsonData *p4GData, TeFrameCmd cmd)
|
|||
ValveData.bat = BSP_ReadVbat();
|
||||
ValveData.humi = 50;
|
||||
ValveData.rssi = gValveData.rssi;
|
||||
ValveData.delay_close_time = ValveInfo.delay_close_count * 5;
|
||||
|
||||
// 解析信号强度,这里简单处理为0-5的整数值
|
||||
int signal_strength = 0;
|
||||
|
@ -937,7 +976,7 @@ uint8_t BSP_4G_Generate_JsonData(Ts4GJsonData *p4GData, TeFrameCmd cmd)
|
|||
p4GData->length = snprintf(p4GData->json_buffer, JSON_BUFFER_SIZE,
|
||||
"{"
|
||||
"\"sn\":\"%s\","
|
||||
"\"t\":%u,"
|
||||
"\"time\":%u,"
|
||||
"\"type\":%d,"
|
||||
"\"data\":{"
|
||||
"\"switch_status\":%d,"
|
||||
|
@ -949,7 +988,11 @@ uint8_t BSP_4G_Generate_JsonData(Ts4GJsonData *p4GData, TeFrameCmd cmd)
|
|||
"\"bat\":%d,"
|
||||
"\"humi\":%d,"
|
||||
"\"rssi\":%d,"
|
||||
"\"signal\":%d"
|
||||
"\"signal\":%d,"
|
||||
"\"over_press\":%d,"
|
||||
"\"low_press\":%d,"
|
||||
"\"delay_close_time\":%d,"
|
||||
"\"over_temp\":%d"
|
||||
"}"
|
||||
"}",
|
||||
device_sn,
|
||||
|
@ -964,7 +1007,11 @@ uint8_t BSP_4G_Generate_JsonData(Ts4GJsonData *p4GData, TeFrameCmd cmd)
|
|||
ValveData.bat,
|
||||
ValveData.humi,
|
||||
ValveData.rssi,
|
||||
signal_strength
|
||||
signal_strength,
|
||||
ValveInfo.over_press,
|
||||
ValveInfo.low_press,
|
||||
ValveData.delay_close_time,
|
||||
ValveInfo.over_temp
|
||||
);
|
||||
|
||||
// 打印JSON数据信息
|
||||
|
|
Loading…
Reference in New Issue