智能家居填坑003 Modbus设备接入篇

Modbus设备

格控TCP系列507E、508M、508D
1、IO端口多:508D有32个DI口、508M有24个DO口、507E有8个DI和8个DO口。
2、原生支持有线Modbus-TCP协议。
3、价格便宜,差评少。
4、支持二次开发:后期计划将普通设备逻辑写入里面,就可以脱离服务器。
5、产品相关资料 :

格控资料

准备

格控设备在说明书里详细的说明了设备的设置方式,
在此就不多加叙述(不同品牌的设置方式存在差异,均需详细参考说明书)。
1、给设备分配与你所在网段匹配的ip地址。
eg. 我的网段是192.168.0.X,我设置的508M:192.168.0.203、508D:192.168.0.202
2、使用附赠的测试软件,测试设备是否已正常连接。


3、node-red安装节点node-red-contrib-modbus。

node-red相关设置

1、在整个过程中主要使用modbus-flex-write、modbus-flex-getter两个节点。
2、modbus-flex-getter轮询:获取线圈或寄存器信息
3、配置服务端

4、 写入操作指令

5、串成流以后就如下所示

[
{
    "id": "13aff178.470a47",
    "type": "inject",
    "z": "f570f583.ba8418",
    "name": "",
    "topic": "",
    "payload": "",
    "payloadType": "date",
    "repeat": "0.2",
    "crontab": "",
    "once": true,
    "onceDelay": "0",
    "x": 180,
    "y": 3160,
    "wires": [
        [
            "ff699d5b.46a718"
        ]
    ]
},
{
    "id": "ff699d5b.46a718",
    "type": "function",
    "z": "f570f583.ba8418",
    "name": "Read 0-31 on Unit 1 FC2",
    "func": "msg.payload = { value: msg.payload, 'fc': 2, 'unitid': 1, 'address': 0 , 'quantity': 32 };\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "x": 390,
    "y": 3160,
    "wires": [
        [
            "25928808.805ab"
        ]
    ]
},
{
    "id": "25928808.805ab",
    "type": "modbus-flex-getter",
    "z": "f570f583.ba8418",
    "name": "获取按键状态",
    "showStatusActivities": false,
    "showErrors": false,
    "logIOActivities": false,
    "server": "bc23592e.d784c8",
    "useIOFile": false,
    "ioFile": "",
    "useIOForPayload": false,
    "x": 620,
    "y": 3160,
    "wires": [
        [
            "aebee8cf.f142a8"
        ],
        []
    ]
},
{
    "id": "efe7fdc6.38e45",
    "type": "comment",
    "z": "f570f583.ba8418",
    "name": "定时轮询",
    "info": "",
    "x": 160,
    "y": 3120,
    "wires": []
},
{
    "id": "e74381c4.affad8",
    "type": "inject",
    "z": "f570f583.ba8418",
    "name": "start",
    "topic": "",
    "payload": "",
    "payloadType": "date",
    "repeat": "",
    "crontab": "",
    "once": true,
    "onceDelay": "0",
    "x": 170,
    "y": 3280,
    "wires": [
        [
            "25cb2616.ce8292"
        ]
    ]
},
{
    "id": "25cb2616.ce8292",
    "type": "function",
    "z": "f570f583.ba8418",
    "name": "Read 0-31 on Unit 1 FC2",
    "func": "msg.payload = { value: msg.payload, 'fc': 2, 'unitid': 1, 'address': 0 , 'quantity': 32 };\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "x": 390,
    "y": 3280,
    "wires": [
        [
            "f3f8587.497f2a8"
        ]
    ]
},
{
    "id": "f3f8587.497f2a8",
    "type": "modbus-flex-getter",
    "z": "f570f583.ba8418",
    "name": "获取按键状态",
    "showStatusActivities": false,
    "showErrors": false,
    "logIOActivities": false,
    "server": "bc23592e.d784c8",
    "useIOFile": false,
    "ioFile": "",
    "useIOForPayload": false,
    "x": 620,
    "y": 3280,
    "wires": [
        [
            "4aba02be.620b74",
            "a1768992.a4da3"
        ],
        []
    ]
},
{
    "id": "beb6a924.cb22c",
    "type": "comment",
    "z": "f570f583.ba8418",
    "name": "完整轮询",
    "info": "",
    "x": 160,
    "y": 3240,
    "wires": []
},
{
    "id": "4aba02be.620b74",
    "type": "delay",
    "z": "f570f583.ba8418",
    "name": "",
    "pauseType": "delay",
    "timeout": "5",
    "timeoutUnits": "seconds",
    "rate": "1",
    "nbRateUnits": "1",
    "rateUnits": "second",
    "randomFirst": "1",
    "randomLast": "5",
    "randomUnits": "seconds",
    "drop": false,
    "x": 460,
    "y": 3380,
    "wires": [
        [
            "25cb2616.ce8292"
        ]
    ]
},
{
    "id": "aebee8cf.f142a8",
    "type": "debug",
    "z": "f570f583.ba8418",
    "name": "",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "false",
    "x": 830,
    "y": 3160,
    "wires": []
},
{
    "id": "a1768992.a4da3",
    "type": "debug",
    "z": "f570f583.ba8418",
    "name": "",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "false",
    "x": 830,
    "y": 3280,
    "wires": []
},
{
    "id": "bc23592e.d784c8",
    "type": "modbus-client",
    "z": "",
    "name": "",
    "clienttype": "tcp",
    "bufferCommands": true,
    "stateLogEnabled": false,
    "tcpHost": "192.168.0.203",
    "tcpPort": "502",
    "tcpType": "DEFAULT",
    "serialPort": "/dev/ttyUSB",
    "serialType": "RTU-BUFFERD",
    "serialBaudrate": "9600",
    "serialDatabits": "8",
    "serialStopbits": "1",
    "serialParity": "none",
    "serialConnectionDelay": "100",
    "unit_id": "1",
    "commandDelay": "1",
    "clientTimeout": "1000",
    "reconnectOnTimeout": true,
    "reconnectTimeout": "2000",
    "parallelUnitIdsAllowed": true
}]

6、改变设备状态就更简单了


上一篇 https://bbs.iobroker.cn/t/topic/1689/4

下一篇

太高深了 mark 慢慢学习

:see_no_evil:你这个依赖了nodered吧,nodered挂了就瞎灯黑火了吧

这些都是软件层面的,物理开关还是可惜控制的

是的 当nodered 挂了会自动切换到备用机

大佬,备用主机该怎么搞