You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Node-RED流时触发‘Function tried to send a message of type number’错误求助

解决Node-RED「Function tried to send a message of type number」错误

错误原因

Node-RED的Function节点仅接受消息对象作为返回值(消息对象一般包含payload属性承载数据),你直接返回了数字类型的motor_speed和current,不符合节点的消息格式规范,因此触发该错误。

修复后的代码

// 补充你省略的if判断逻辑
if (/* 你的判断条件 */) {
    flow.set('previous_motor_speed', motor_speed);
    // 将数字包装成消息对象,通过payload传递数据
    return [{payload: motor_speed}, {payload: current}];
}
// Return nothing if not required
else { 
    flow.set('previous_motor_speed', motor_speed);
    return null;
}

关键修改点

  • 把直接返回的数字值motor_speed、current,包装成带payload属性的消息对象,比如{payload: motor_speed}
  • 补全代码的大括号结构(原代码缺失if语句的起始大括号,需补充保证逻辑完整)

内容的提问来源于stack exchange,提问作者Rush

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 14:15:33