【类 型】:feat 添加读取参数 向前端发送功能
【原 因】: 【过 程】: 【影 响】:
This commit is contained in:
parent
f867ec17a2
commit
1f06676b1e
@ -14,12 +14,12 @@ extern void Hook_recovery();
|
||||
static const char *MOUDLENAME = "COMMSER";
|
||||
|
||||
/*项目对象*/
|
||||
char *ssid = "szMate40pro"; // wifi帐号
|
||||
char *password = "63587839ab"; // wifi密码
|
||||
// char* ssid = "szdot"; //wifi帐号
|
||||
// char* password = "63587839ab"; //wifi密码
|
||||
// char *ssid = "flicube"; // wifi帐号
|
||||
// char *password = "fxmf0622"; // wifi密码
|
||||
// char *ssid = "szMate40pro"; // wifi帐号
|
||||
// char *password = "63587839ab"; // wifi密码
|
||||
// char* ssid = "szdot"; //wifi帐号
|
||||
// char* password = "63587839ab"; //wifi密码
|
||||
char *ssid = "flicube"; // wifi帐号
|
||||
char *password = "fxmf0622"; // wifi密码
|
||||
// char *ssid = "fxmf_sc01"; // 4g wifi帐号
|
||||
// char *password = "12345678"; // 4g wifi密码
|
||||
char *mqttServer = "szdot.top"; // mqtt地址
|
||||
@ -35,8 +35,8 @@ FoodCube fc(ssid, password, mqttServer, mqttPort, mqttName, mqttPassword, mavlin
|
||||
/* 发布 主题 ps:以下是登记发布json内容的组成元素 */
|
||||
// 登记 json成员名字
|
||||
|
||||
// 0:心跳信息 1:电压信息 2:电流信息 3:电池电量 4:海拔高度 5:对地速度 6:卫星数量 7:定位状态 8:磁罗盘校准进度 9:磁罗盘校准结果 10:任务状态 11:加速度计状态 12:飞机模式 13:重量 14:钩子状态 15:{经,维,高} 16:电池总容量 17:返航点 18:文本信息 19:返航速度
|
||||
const String topicPub[] = {"heartBeat", "voltagBattery", "currentBattery", "batteryRemaining", "positionAlt", "groundSpeed", "satCount", "fixType", "completionPct", "reportCal", "questState", "acceState", "getPlaneMode", "loadweight", "hookstatus", "position", "battCapacity", "homePosition", "statusText", "wpnavSpeed"};
|
||||
// 0:心跳信息 1:电压信息 2:电流信息 3:电池电量 4:海拔高度 5:对地速度 6:卫星数量 7:定位状态 8:磁罗盘校准进度 9:磁罗盘校准结果 10:任务状态 11:加速度计状态 12:飞机模式 13:重量 14:钩子状态 15:{经,维,高} 16:电池总容量 17:返航点 18:文本信息 19:返航速度 20:{参数名:值}
|
||||
const String topicPub[] = {"heartBeat", "voltagBattery", "currentBattery", "batteryRemaining", "positionAlt", "groundSpeed", "satCount", "fixType", "completionPct", "reportCal", "questState", "acceState", "getPlaneMode", "loadweight", "hookstatus", "position", "battCapacity", "homePosition", "statusText", "wpnavSpeed", "parameterValue"};
|
||||
/*
|
||||
*其中topicPubMsg[10]既飞机任务状态的值
|
||||
*二进制00 0000
|
||||
@ -221,6 +221,11 @@ void mqtt_receiveCallback(char *topic, byte *payload, unsigned int length)
|
||||
// 调用 setParam 函数
|
||||
fc.setParam(item, paramValue);
|
||||
}
|
||||
else if (key == "getParam")
|
||||
{
|
||||
String todo = value; // 转换值
|
||||
fc.mav_parameter_data(todo.c_str()); // 获取指定参数 值
|
||||
}
|
||||
else if (key == "refreshRequest")
|
||||
{
|
||||
refreshRequest(); // 刷新各种请求
|
||||
@ -844,7 +849,7 @@ void mavlink_receiveCallback(uint8_t c)
|
||||
}
|
||||
}
|
||||
// "WPNAV_SPEED" 参数 返航速度
|
||||
if (strcmp(param_value.param_id, "WPNAV_SPEED") == 0)
|
||||
else if (strcmp(param_value.param_id, "WPNAV_SPEED") == 0)
|
||||
{
|
||||
// 将参数值转换为字符串
|
||||
dtostrf(param_value.param_value / 1000, 0, 2, buf); // 使用 dtostrf 将浮点数转换为字符串
|
||||
@ -853,6 +858,18 @@ void mavlink_receiveCallback(uint8_t c)
|
||||
topicPubMsg[19] = buf;
|
||||
}
|
||||
}
|
||||
// 其余参数
|
||||
char jsonStr[100]; // 用于存储 JSON 格式的字符串
|
||||
dtostrf(param_value.param_value, 0, 2, buf); // 将浮点数转换为字符串
|
||||
|
||||
// 构造 JSON 格式的字符串 {"param_name": value}
|
||||
snprintf(jsonStr, sizeof(jsonStr), "{\"%s\":%.2f}", param_value.param_id, atof(buf));
|
||||
|
||||
// 检查生成的 JSON 字符串是否与 topicPubMsg[20] 不相同,若不同则更新
|
||||
if (String(jsonStr) != topicPubMsg[20])
|
||||
{
|
||||
topicPubMsg[20] = jsonStr;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user