部署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
相关产品推荐
相关产品推荐

