不干了!!!收
This commit is contained in:
@@ -20,6 +20,10 @@ extern uint8_t Request_Water(uint8_t cmd);
|
||||
// 系统模式设置函数声明(定义在freertos.c中)
|
||||
extern void Set_System_Mode(uint8_t mode);
|
||||
|
||||
// 定时喂食配置函数声明(定义在freertos.c中)
|
||||
extern void Update_Feed_Config(const char *feed_times_json, uint16_t single_weight);
|
||||
extern uint16_t Get_Single_Feed_Weight(void);
|
||||
|
||||
/* ================= 配置 ================= */
|
||||
|
||||
#define WIFI_TX_BUF_SIZE 512
|
||||
@@ -585,8 +589,15 @@ void wifi_task_mqtt(void *argument) {
|
||||
elog_i(TAG, "处理control主题消息");
|
||||
if (strstr(msg.payload, "feed")) {
|
||||
elog_i(TAG, "执行喂食动作");
|
||||
// 根据配置的单次喂食重量计算份数(每份10克)
|
||||
uint16_t single_weight = Get_Single_Feed_Weight();
|
||||
uint8_t feed_amount = single_weight / 10;
|
||||
if (feed_amount < 1) {
|
||||
feed_amount = 1; // 至少喂食1份
|
||||
}
|
||||
elog_i(TAG, "远程喂食重量: %dg, 计算份数: %d", single_weight, feed_amount);
|
||||
// 调用远程喂食函数
|
||||
if (Request_Feed(FEED_CMD_REMOTE, 90, 1)) {
|
||||
if (Request_Feed(FEED_CMD_REMOTE, 90, feed_amount)) {
|
||||
elog_i(TAG, "远程喂食请求已提交");
|
||||
} else {
|
||||
elog_w(TAG, "喂食进行中,无法接受新命令");
|
||||
@@ -644,10 +655,71 @@ void wifi_task_mqtt(void *argument) {
|
||||
}
|
||||
|
||||
/* ===== config主题 ===== */
|
||||
/**
|
||||
{
|
||||
"feedTimes": [
|
||||
"02:00",
|
||||
"02:04"
|
||||
],
|
||||
"singleFeedWeight": 50
|
||||
}
|
||||
*/
|
||||
else if (strcmp(msg.topic, "petfeeder/config") == 0) {
|
||||
elog_i(TAG, "处理config主题消息");
|
||||
elog_i(TAG, "更新配置参数");
|
||||
// 其他配置参数更新逻辑
|
||||
|
||||
// 解析JSON配置
|
||||
char *feed_times_start = strstr(msg.payload, "\"feedTimes\"");
|
||||
char *single_weight_start = strstr(msg.payload, "\"singleFeedWeight\"");
|
||||
|
||||
if (feed_times_start && single_weight_start) {
|
||||
// 提取feedTimes数组字符串
|
||||
char *bracket_start = strstr(feed_times_start, "[");
|
||||
char *bracket_end = strstr(feed_times_start, "]");
|
||||
|
||||
if (bracket_start && bracket_end && bracket_end > bracket_start) {
|
||||
// 计算数组字符串长度
|
||||
size_t array_len = bracket_end - bracket_start + 1;
|
||||
char feed_times_array[256] = {0};
|
||||
|
||||
if (array_len < sizeof(feed_times_array)) {
|
||||
strncpy(feed_times_array, bracket_start, array_len);
|
||||
feed_times_array[array_len] = '\0';
|
||||
|
||||
// 提取singleFeedWeight值
|
||||
char *colon = strstr(single_weight_start, ":");
|
||||
if (colon) {
|
||||
// 跳过冒号和可能的空格
|
||||
char *value_start = colon + 1;
|
||||
while (*value_start == ' ' || *value_start == '\t') {
|
||||
value_start++;
|
||||
}
|
||||
|
||||
// 解析数字
|
||||
uint16_t single_weight = 0;
|
||||
if (sscanf(value_start, "%hu", &single_weight) == 1) {
|
||||
elog_i(TAG, "解析到配置: feedTimes=%s, singleFeedWeight=%d",
|
||||
feed_times_array, single_weight);
|
||||
|
||||
// 调用更新函数
|
||||
Update_Feed_Config(feed_times_array, single_weight);
|
||||
|
||||
elog_i(TAG, "喂食配置更新完成");
|
||||
} else {
|
||||
elog_w(TAG, "解析singleFeedWeight失败");
|
||||
}
|
||||
} else {
|
||||
elog_w(TAG, "找不到singleFeedWeight的冒号");
|
||||
}
|
||||
} else {
|
||||
elog_w(TAG, "feedTimes数组太长,超出缓冲区");
|
||||
}
|
||||
} else {
|
||||
elog_w(TAG, "找不到feedTimes数组的括号");
|
||||
}
|
||||
} else {
|
||||
elog_w(TAG, "JSON格式错误,缺少feedTimes或singleFeedWeight字段");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
elog_w(TAG, "MQTT消息解析失败");
|
||||
|
||||
Reference in New Issue
Block a user