使用下拉列表中的数据在 Node-red 上的 SNMP-set 中设置值
Use data from dropdownlist to set value in SNMP-set on Node-red
在 Node-red 中,我想使用例如下拉列表中的值发送到 SNMP-set 命令。
据我了解,snmp-set 节点使用 msg.varbinds 来获取其数据。
但是我如何引用 msg.varbinds 输入中下拉列表的值,因为它在我看来 JSON
这就是我在 Varbinds window 中的内容。
我以为我只需要引用来自下拉元素的 msg.payload,但这似乎太简单了。
[ {
"oid" : "1.3.6.1.4.1.5835.3.1.3.1.38.1.1",
"type" : "OctetString",
"value" : msg.payload
}
]
顺便说一句,这是我在调试 window 中下拉列表的输出。
9/23/2019, 8:13:04 PMnode: b4c9ef70.0f38d
msg : Object
object
payload: "14300000000"
socketid: "Xc-CPsZX-CouQVRAAAAA"
_msgid: "b77a7c3f.8645c"
这是流程
[{"id":"fd51033f.82b34","type":"snmp set","z":"e5486a7.f6cf798","host":"192.168.0.35","community":"public","version":"1","varbinds":"[ {\n \"oid\" : \"1.3.6.1.4.1.5835.3.1.3.1.38.1.1\",\n \"type\" : \"OctetString\",\n \"value\" : msg.payload\n }\n ]","timeout":5,"name":"set freq ","x":620,"y":1940,"wires":[]},{"id":"596c4ff0.67b7b","type":"ui_dropdown","z":"e5486a7.f6cf798","name":"","label":"","tooltip":"","place":"Select option","group":"ca614dce.5eeca","order":11,"width":0,"height":0,"passthru":true,"options":[{"label":"14200","value":"14200000000","type":"str"},{"label":"14300","value":"14300000000","type":"str"},{"label":"14400","value":"14400000000","type":"str"}],"payload":"","topic":"","x":340,"y":1940,"wires":[["fd51033f.82b34","b4c9ef70.0f38d"]]},{"id":"b4c9ef70.0f38d","type":"debug","z":"e5486a7.f6cf798","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":690,"y":2060,"wires":[]},{"id":"ca614dce.5eeca","type":"ui_group","z":"","name":"Modulator 5","tab":"fe640bc5.c66b48","order":4,"disp":true,"width":"6","collapse":false},{"id":"fe640bc5.c66b48","type":"ui_tab","z":"","name":"Modulators","icon":"rss_feed","order":5,"disabled":false,"hidden":false}]
好的,所以 SNMP 设置节点的信息边栏帮助中有您缺少的部分:
msg.varbinds
may contain varbinds as an array of json objects
containing multiple oids, types and values.
这意味着您需要构建 varbinds 字符串并存储在消息对象的 msg.varbinds
键中,然后将其传递给 SNMP 集节点。最简单的方法可能是在 UI 下拉节点和 SNMP 集节点之间使用一个功能节点。
msg.varbinds = "[ {\n" +
"\"oid\" : \"1.3.6.1.4.1.5835.3.1.3.1.38.1.1\",\n" +
"\"type\" : \"OctetString\",\n" +
"\"value\" : \"" + msg.payload + "\"\n"
"}\n" +
"]";
return msg;
您应该在 SNMP 集节点配置中将 varbinds 留空。
在 Node-red 中,我想使用例如下拉列表中的值发送到 SNMP-set 命令。 据我了解,snmp-set 节点使用 msg.varbinds 来获取其数据。 但是我如何引用 msg.varbinds 输入中下拉列表的值,因为它在我看来 JSON
这就是我在 Varbinds window 中的内容。 我以为我只需要引用来自下拉元素的 msg.payload,但这似乎太简单了。
[ {
"oid" : "1.3.6.1.4.1.5835.3.1.3.1.38.1.1",
"type" : "OctetString",
"value" : msg.payload
}
]
顺便说一句,这是我在调试 window 中下拉列表的输出。
9/23/2019, 8:13:04 PMnode: b4c9ef70.0f38d
msg : Object
object
payload: "14300000000"
socketid: "Xc-CPsZX-CouQVRAAAAA"
_msgid: "b77a7c3f.8645c"
这是流程
[{"id":"fd51033f.82b34","type":"snmp set","z":"e5486a7.f6cf798","host":"192.168.0.35","community":"public","version":"1","varbinds":"[ {\n \"oid\" : \"1.3.6.1.4.1.5835.3.1.3.1.38.1.1\",\n \"type\" : \"OctetString\",\n \"value\" : msg.payload\n }\n ]","timeout":5,"name":"set freq ","x":620,"y":1940,"wires":[]},{"id":"596c4ff0.67b7b","type":"ui_dropdown","z":"e5486a7.f6cf798","name":"","label":"","tooltip":"","place":"Select option","group":"ca614dce.5eeca","order":11,"width":0,"height":0,"passthru":true,"options":[{"label":"14200","value":"14200000000","type":"str"},{"label":"14300","value":"14300000000","type":"str"},{"label":"14400","value":"14400000000","type":"str"}],"payload":"","topic":"","x":340,"y":1940,"wires":[["fd51033f.82b34","b4c9ef70.0f38d"]]},{"id":"b4c9ef70.0f38d","type":"debug","z":"e5486a7.f6cf798","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":690,"y":2060,"wires":[]},{"id":"ca614dce.5eeca","type":"ui_group","z":"","name":"Modulator 5","tab":"fe640bc5.c66b48","order":4,"disp":true,"width":"6","collapse":false},{"id":"fe640bc5.c66b48","type":"ui_tab","z":"","name":"Modulators","icon":"rss_feed","order":5,"disabled":false,"hidden":false}]
好的,所以 SNMP 设置节点的信息边栏帮助中有您缺少的部分:
msg.varbinds
may contain varbinds as an array of json objects containing multiple oids, types and values.
这意味着您需要构建 varbinds 字符串并存储在消息对象的 msg.varbinds
键中,然后将其传递给 SNMP 集节点。最简单的方法可能是在 UI 下拉节点和 SNMP 集节点之间使用一个功能节点。
msg.varbinds = "[ {\n" +
"\"oid\" : \"1.3.6.1.4.1.5835.3.1.3.1.38.1.1\",\n" +
"\"type\" : \"OctetString\",\n" +
"\"value\" : \"" + msg.payload + "\"\n"
"}\n" +
"]";
return msg;
您应该在 SNMP 集节点配置中将 varbinds 留空。