使用下拉列表中的数据来设置节点红色的SNMP设置中的值

问题描述 投票:0回答:1

在Node-red中,我想使用例如下拉列表中的值以发送到SNMP-set命令。据我了解,snmp-set节点使用msg.varbinds来获取其数据。但是,我如何引用msg.varbinds输入中的下拉列表中的值,因为它对我来说看起来像JSON

这是我在Varbinds窗口中所拥有的。我以为我只需要引用来自dropdown元素的msg.payload,但这似乎太简单了。

[ {
            "oid" : "1.3.6.1.4.1.5835.3.1.3.1.38.1.1",
            "type" : "OctetString",
            "value" : msg.payload
        }
    ]

这是通过调试窗口中我的下拉列表的输出。

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}]
json snmp node-red
1个回答
0
投票

确定,因此SNMP set节点的信息边栏帮助具有您所缺少的位:

msg.varbinds可能包含varbinds作为json对象的数组包含多个oid,类型和值。

这意味着您需要构建varbinds字符串并将其存储在消息对象的msg.varbinds键中,然后将其传递到SNMP set节点。最简单的方法可能是在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" + 
"]";

return msg;

您应在SNMP设置节点配置中将varbinds保留为空。

© www.soinside.com 2019 - 2024. All rights reserved.