『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: chaoself

[流程系列] nodered提取ID

[复制链接]

3

主题

321

帖子

2889

积分

论坛积极会员

积分
2889
金钱
2568
HASS币
10
发表于 2021-7-9 10:32:51 | 显示全部楼层
本帖最后由 tcwj2008 于 2021-7-9 10:36 编辑
chaoself 发表于 2021-7-8 23:28
这个代码试了,输出的180个数组,并不是ID为94的两个值

channel那个我c小写了,你的数据里应该是大写的,灵活运用吧。其实几个人已经写的很详细了,自己多练习下,这个其实挺基础的。给你一个导出来的,你自己试试看吧
[{"id":"f21f1297.c6921","type":"inject","z":"6f6ce46.ce6b51c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{"Device_ID":"94","Channel":"Hum","Qty":1},{"Device_ID":"94","Channel":"Temp","Qty":2},{"Device_ID":"93","Channel":"Hum","Qty":3},{"Device_ID":"93","Channel":"Temp","Qty":4}]","payloadType":"json","x":130,"y":980,"wires":[["c84648c.e7806b8"]]},{"id":"c84648c.e7806b8","type":"function","z":"6f6ce46.ce6b51c","name":"","func":"for(let i of msg.payload){\n    if(i.Device_ID == "94") msg[i.Channel] = i.Qty;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":980,"wires":[["a69927cb.9149e8","a690dded.facb6","c684a068.38a13"]]},{"id":"a69927cb.9149e8","type":"debug","z":"6f6ce46.ce6b51c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":920,"wires":[]},{"id":"a690dded.facb6","type":"change","z":"6f6ce46.ce6b51c","name":"湿度","rules":[{"t":"set","p":"payload","pt":"msg","to":"Hum","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":960,"wires":[["df2654fd.1fe7c8"]]},{"id":"c684a068.38a13","type":"change","z":"6f6ce46.ce6b51c","name":"温度","rules":[{"t":"set","p":"payload","pt":"msg","to":"Temp","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":1000,"wires":[["d27a5035.fa11f"]]},{"id":"df2654fd.1fe7c8","type":"debug","z":"6f6ce46.ce6b51c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":960,"wires":[]},{"id":"d27a5035.fa11f","type":"debug","z":"6f6ce46.ce6b51c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":1000,"wires":[]}]


回复

使用道具 举报

32

主题

146

帖子

1257

积分

金牌会员

Rank: 6Rank: 6

积分
1257
金钱
1111
HASS币
0
 楼主| 发表于 2021-7-10 16:22:30 | 显示全部楼层
本帖最后由 chaoself 于 2021-7-10 16:24 编辑
tcwj2008 发表于 2021-7-9 10:32
channel那个我c小写了,你的数据里应该是大写的,灵活运用吧。其实几个人已经写的很详细了,自己多练习下 ...

感谢大神帮助,现在可以输出了。现在我想把数组重整。对Device_ID排序后重整输出。
Device_ID:
0:
Temp:xx
Humi:xx
1:
Temp:xx
Humi:xx
......

不知道如何实现呢?多多指教
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-21 21:37 , Processed in 0.389278 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表