”实现了bluesun/bms/control/sn的主题配置“
This commit is contained in:
parent
5aff48e4b0
commit
1dc6f097e0
File diff suppressed because it is too large
Load Diff
|
@ -984,7 +984,7 @@ void protocol_build_json(uint16_t groupId, uint32_t time)
|
|||
if (json_str)
|
||||
{
|
||||
drv_mqtt_publish_no_respose(json_str, strlen(json_str));
|
||||
bsp_task_delay_ms(50);
|
||||
bsp_task_delay_ms(100);
|
||||
cJSON_free(json_str);
|
||||
}
|
||||
|
||||
|
@ -1042,7 +1042,7 @@ void protocol_build_volt_json(uint8_t i, uint32_t time)
|
|||
if (json_str)
|
||||
{
|
||||
drv_mqtt_publish_no_respose(json_str, strlen(json_str));
|
||||
bsp_task_delay_ms(50);
|
||||
bsp_task_delay_ms(100);
|
||||
cJSON_free(json_str);
|
||||
}
|
||||
|
||||
|
@ -1100,7 +1100,7 @@ void protocol_build_temp_json(uint8_t i, uint32_t time)
|
|||
if (json_str)
|
||||
{
|
||||
drv_mqtt_publish_no_respose(json_str, strlen(json_str));
|
||||
bsp_task_delay_ms(50);
|
||||
bsp_task_delay_ms(10.0);
|
||||
cJSON_free(json_str);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -126,7 +126,7 @@ uint8_t drv_mqtt_connect()
|
|||
//2、建立 MQTT 客户端与服务器之间的会话连接
|
||||
char cmd[100] = {0};
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "AT+QMTOPEN=0,\"%s\",%d",MQTT_BROKER,MQTT_PORT);
|
||||
snprintf(cmd, sizeof(cmd), "AT+QMTOPEN=1,\"%s\",%d",MQTT_BROKER,MQTT_PORT);
|
||||
if (!drv_at_send_cmd(cmd, "OK", WIFI_TIMEOUT))
|
||||
{
|
||||
// KIT_PRINTF("Failed to set MQTT server!\r\n");
|
||||
|
@ -136,10 +136,14 @@ uint8_t drv_mqtt_connect()
|
|||
|
||||
//2、MQTT 客户端与服务器之间建立 MQTT 连接 AT+QMTCONN=<clientID>,<client_identity>,<username>,<password>
|
||||
//snprintf(cmd, sizeof(cmd), "AT+QMTCONN=0,%s,%s,%s",MQTT_CLIENT_ID,MQTT_USER, MQTT_PASSWORD);
|
||||
if (!drv_at_send_cmd("AT+QMTCONN=0,\"clientBCUwifi11223344\"", "OK", WIFI_TIMEOUT))
|
||||
if (!drv_at_send_cmd("AT+QMTCONN=1,\"clientBCUwifi11223344\"", "OK", WIFI_TIMEOUT))
|
||||
{
|
||||
// KIT_PRINTF("Failed to set MQTT client credentials!\r\n");
|
||||
}
|
||||
|
||||
if (!drv_at_send_cmd("AT+QMTSUB=1,1,\"bluesun/bms/control/11223344\",0", "OK", WIFI_TIMEOUT))
|
||||
{
|
||||
// KIT_PRINTF("Failed to set MQTT client credentials!\r\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// KIT_PRINTF("MQTT Connection Successful!\r\n");
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
uint8_t rev_buff[QFC41D_MAX_RECV_SIZE] = {0};
|
||||
uint8_t send_buff[QFC41D_MAX_SEND_SIZE] = {0};
|
||||
char wifiName[40] = "BLUESUNESS", wifiPassWord[40] = "bluesun009", bleName[40] = "bsm1";
|
||||
|
||||
#define MAX_PAYLOAD_LEN 128
|
||||
char cmd[1000] = {0}; //降低栈空间使用
|
||||
|
||||
#define TX_DMA_BUFFER_SIZE 1000
|
||||
#define TX_DMA_BUFFER_SIZE 2000
|
||||
|
||||
uint8_t dma_tx_buffer[TX_DMA_BUFFER_SIZE];
|
||||
volatile uint8_t dma_tx_busy = 0;
|
||||
|
@ -28,6 +28,83 @@ WifiBleItem qfc41dItem = {
|
|||
.sendCall = NULL,
|
||||
};
|
||||
|
||||
void parse_mqtt_message(char* message)
|
||||
{
|
||||
// 示例消息: +QMTRECV: 0,31,"bluesun/bms/control/123",11,"MQ3156+1MQ"
|
||||
uint16_t first = 0;
|
||||
uint16_t second = 0;
|
||||
|
||||
char* quotes[4] = {0};
|
||||
int quote_count = 0;
|
||||
for(char* p = message; *p && quote_count < 4; p++)
|
||||
{
|
||||
if(*p == '\"')
|
||||
{
|
||||
quotes[quote_count++] = p;
|
||||
}
|
||||
}
|
||||
|
||||
// 匹配四个引号
|
||||
if(quote_count < 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 提取payload内容
|
||||
char* payload_start = quotes[2] + 1;
|
||||
char* payload_end = quotes[3];
|
||||
size_t payload_len = payload_end - payload_start;
|
||||
|
||||
if(payload_len >= MAX_PAYLOAD_LEN)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char payload[MAX_PAYLOAD_LEN];
|
||||
strncpy(payload, payload_start, payload_len);
|
||||
payload[payload_len] = '\0';
|
||||
|
||||
char* processed = payload;
|
||||
size_t len = strlen(processed);
|
||||
|
||||
// 去除开头"MQ"
|
||||
if(len >= 2 && strncmp(processed, "MQ", 2) == 0)
|
||||
{
|
||||
processed += 2;
|
||||
len -= 2;
|
||||
}
|
||||
|
||||
// 去除结尾"MQ"
|
||||
if(len >= 2 && strcmp(processed + len - 2, "MQ") == 0)
|
||||
{
|
||||
processed[len - 2] = '\0';
|
||||
len -= 2;
|
||||
}
|
||||
|
||||
// 分离参数
|
||||
char* plus_pos = strchr(processed, '+');
|
||||
if(!plus_pos)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 后续增加对主题部分的解析,读取是全部读取,配置下发,是一条一条下发
|
||||
// 解析主题
|
||||
|
||||
*plus_pos = '\0'; // 分割字符串
|
||||
first = atoi(processed);
|
||||
second = atoi(plus_pos + 1);
|
||||
|
||||
if((first >= 3000) && (first <= 3168))
|
||||
{
|
||||
bcu_data_set_0x06_msg(first, second);
|
||||
}
|
||||
else if ((first >= 4000) && (first <= 4999))
|
||||
{
|
||||
hmi_write_modbus_cfg(first - 4000, second);
|
||||
}
|
||||
}
|
||||
|
||||
static void drv_qfc41d_push_data(WifiBleItem* item, uint8_t *buf, uint16_t len)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
|
@ -39,6 +116,10 @@ static void drv_qfc41d_push_data(WifiBleItem* item, uint8_t *buf, uint16_t len)
|
|||
if (buf[i] == '\n')
|
||||
{
|
||||
item->buf[item->buf_pos] = '\0'; // 添加结束符
|
||||
if (item->buf_pos < 100)
|
||||
{
|
||||
parse_mqtt_message(item->buf); // 解析消息
|
||||
}
|
||||
item->buf_pos = 0; // 重置索引,准备下一条数据
|
||||
}
|
||||
}
|
||||
|
@ -342,7 +423,7 @@ static uint8_t drv_mqtt_subscribe()
|
|||
*/
|
||||
uint8_t drv_mqtt_publish(char* str,uint16_t length)
|
||||
{
|
||||
snprintf(cmd, sizeof(cmd), "AT+QMTPUB=0,1,2,0,%s,%d,%s",MQTT_TOPIC, length, str);
|
||||
snprintf(cmd, sizeof(cmd), "AT+QMTPUB=1,1,2,0,%s,%d,%s",MQTT_TOPIC, length, str);
|
||||
if (!drv_at_send_cmd(cmd, "OK\0", WIFI_TIMEOUT))
|
||||
{
|
||||
// KIT_PRINTF("Failed to publish message!\r\n");
|
||||
|
@ -356,7 +437,7 @@ uint8_t drv_mqtt_publish(char* str,uint16_t length)
|
|||
uint8_t drv_mqtt_publish_no_respose(char* str,uint16_t length)
|
||||
{
|
||||
// snprintf(cmd, sizeof(cmd), "AT+QMTPUB=0,1,2,0,%s,%d,%s",MQTT_TOPIC, length, str);
|
||||
snprintf(cmd, sizeof(cmd), "AT+QMTPUB=0,1,2,0,\"%s\",%d,\"%s\"", MQTT_TOPIC, length, str);
|
||||
snprintf(cmd, sizeof(cmd), "AT+QMTPUB=1,1,2,0,\"%s\",%d,\"%s\"", MQTT_TOPIC, length, str);
|
||||
// drv_wireless_send_string(cmd); // 未使用DMA
|
||||
drv_wireless_send_string_dma(cmd); // 使用DMA
|
||||
// kit_time_dly_ms(100);
|
||||
|
|
Loading…
Reference in New Issue