系统拓扑图:

操作视频截图:

      

      

视频链接:

https://v.douyin.com/Q_dvSDBgS7k

node-red流Json数据:

[
    {
        "id": "7e28882f52da98e6",
        "type": "tab",
        "label": "测试CH348的GPIO,是否正常",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "94624e546ee46fd8",
        "type": "exec",
        "z": "7e28882f52da98e6",
        "command": "/home/zdm/ch348_gpio",
        "addpay": "payload",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 550,
        "y": 200,
        "wires": [
            [
                "56ac6e96b35afe48"
            ],
            [],
            []
        ]
    },
    {
        "id": "f8c7d0a86f9cc77b",
        "type": "inject",
        "z": "7e28882f52da98e6",
        "name": "绿LED",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 110,
        "y": 260,
        "wires": [
            [
                "ca32b3683f6ce472"
            ]
        ]
    },
    {
        "id": "ca32b3683f6ce472",
        "type": "function",
        "z": "7e28882f52da98e6",
        "name": "输出,控制指令",
        "func": "// ledStatus状态,为关false时,调用“输出高电平”指令\nif(!flow.get(\"ledStatus\")) {\n    msg.payload = \"write 1 1\";    // gpio1设置为高电平\n    flow.set(\"ledStatus\", true);  // LED状态,设置为true\n} else {\n// ledStatus状态,为关true时,调用“输出低电平”指令\n    msg.payload = \"write 1 0\";    // gpio1设置为低电平\n    flow.set(\"ledStatus\", false);  // LED状态,设置false\n}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 280,
        "y": 260,
        "wires": [
            [
                "94624e546ee46fd8"
            ]
        ]
    },
    {
        "id": "68edba75d00a2ed1",
        "type": "inject",
        "z": "7e28882f52da98e6",
        "name": "红LED",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 110,
        "y": 320,
        "wires": [
            [
                "6850a226540bd048"
            ]
        ]
    },
    {
        "id": "6850a226540bd048",
        "type": "function",
        "z": "7e28882f52da98e6",
        "name": "输出,控制指令",
        "func": "// ledStatus状态,为关false时,调用“输出高电平”指令\nif(!flow.get(\"redLedStatus\")) {\n    msg.payload = \"write 10 1\";    // gpio10设置为高电平\n    flow.set(\"redLedStatus\", true);  // LED状态,设置为true\n} else {\n// ledStatus状态,为关true时,调用“输出低电平”指令\n    msg.payload = \"write 10 0\";    // gpio10设置为低电平\n    flow.set(\"redLedStatus\", false);  // LED状态,设置false\n}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 280,
        "y": 320,
        "wires": [
            [
                "94624e546ee46fd8"
            ]
        ]
    },
    {
        "id": "56499c26a79513e9",
        "type": "inject",
        "z": "7e28882f52da98e6",
        "name": "检测,按钮B",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "0.3",
        "crontab": "",
        "once": true,
        "onceDelay": "0.6",
        "topic": "",
        "payload": "read 6",
        "payloadType": "str",
        "x": 240,
        "y": 160,
        "wires": [
            [
                "94624e546ee46fd8"
            ]
        ]
    },
    {
        "id": "55d1f3c90bf88f74",
        "type": "inject",
        "z": "7e28882f52da98e6",
        "name": "检测,按钮A",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "0.3",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "read 5",
        "payloadType": "str",
        "x": 240,
        "y": 100,
        "wires": [
            [
                "94624e546ee46fd8"
            ]
        ]
    },
    {
        "id": "65dbfc6dbc89a7a8",
        "type": "ui-notification",
        "z": "7e28882f52da98e6",
        "ui": "24effe465125a07b",
        "position": "top center",
        "colorDefault": true,
        "color": "#08f604",
        "displayTime": "1",
        "showCountdown": false,
        "outputs": 1,
        "allowDismiss": false,
        "dismissText": "Close",
        "allowConfirm": false,
        "confirmText": "Confirm",
        "raw": false,
        "className": "",
        "name": "弹窗提示",
        "x": 600,
        "y": 340,
        "wires": [
            []
        ]
    },
    {
        "id": "56ac6e96b35afe48",
        "type": "function",
        "z": "7e28882f52da98e6",
        "name": "解析exec节点输出",
        "func": "// 解析exec节点输出\nlet text = msg.payload.toString().trim();\n\nif (text.includes(\"GPIO 5\") && text.includes(\"高电平\")) {\n    msg.payload = \"✅ 按钮 A,被按下!\";\n    return msg;\n} \nelse if (text.includes(\"GPIO 6\") && text.includes(\"高电平\")) {\n    msg.payload = \"🔴 按钮 B,被按下!\";\n    return msg;\n}\n\nreturn null;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 550,
        "y": 280,
        "wires": [
            [
                "65dbfc6dbc89a7a8"
            ]
        ]
    },
    {
        "id": "24effe465125a07b",
        "type": "ui-base",
        "name": "My Dashboard",
        "path": "/dashboard",
        "appIcon": "",
        "includeClientData": true,
        "acceptsClientConfig": [
            "ui-notification",
            "ui-control"
        ],
        "showPathInSidebar": false,
        "headerContent": "page",
        "navigationStyle": "default",
        "titleBarStyle": "default",
        "showReconnectNotification": false,
        "notificationDisplayTime": "1",
        "showDisconnectNotification": true,
        "allowInstall": false
    },
    {
        "id": "bf2bfe9e1345fb03",
        "type": "global-config",
        "env": [],
        "modules": {
            "@flowfuse/node-red-dashboard": "1.30.2"
        }
    }
]

更多推荐