window安装EMQX和node.js

  1. 进入网站
    https://www.emqx.io/zh/downloads?os=Windows
  2. 可能会报错MSVRC120.dll
    https://learn.microsoft.com/zh-CN/cpp/windows/latest-supported-vc-redist?view=msvc-170
    下载64位的即可启动emqx
  3. 进入nodejs官网
    https://nodejs.cn/download/
    下载

新建group

考试node-red配置

点击查看代码
[
    {
        "id": "4480a22badcc80b5",
        "type": "tab",
        "label": "时间戳生成数据",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "a43d7c5856dc2fea",
        "type": "function",
        "z": "4480a22badcc80b5",
        "name": "function 2-zwl2007331220",
        "func": "var msg1 = {payload:msg.payload};\nvar mysql = \"INSERT INTO zwlled VALUES ('%s')\";\nvar tem2007331220 = msg1.payload;\nvar msg3 = {\n\n    \"topic\": util.format(mysql,tem2007331220)\n}\n\nreturn  [[msg1],[msg3]];\n",
        "outputs": 2,
        "noerr": 1,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 860,
        "wires": [
            [
                "a27e6a3f73ac9865",
                "e210add1d2c28b25"
            ],
            [
                "0b66d280d274ed81"
            ]
        ]
    },
    {
        "id": "e210add1d2c28b25",
        "type": "ui_gauge",
        "z": "4480a22badcc80b5",
        "name": "",
        "group": "86d9dae2c7d6e7e6",
        "order": 3,
        "width": "0",
        "height": "0",
        "gtype": "gage",
        "title": "温度",
        "label": "units",
        "format": "{{value}}",
        "min": 0,
        "max": "100",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "diff": false,
        "className": "",
        "x": 830,
        "y": 760,
        "wires": []
    },
    {
        "id": "2af280ae9cb6d059",
        "type": "mqtt in",
        "z": "4480a22badcc80b5",
        "name": "",
        "topic": "zwl2007331220",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "f7ad174f.17a3c",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 240,
        "y": 860,
        "wires": [
            [
                "a43d7c5856dc2fea"
            ]
        ]
    },
    {
        "id": "0b66d280d274ed81",
        "type": "mysql",
        "z": "4480a22badcc80b5",
        "mydb": "c3ed5a2b931be081",
        "name": "",
        "x": 830,
        "y": 900,
        "wires": [
            []
        ]
    },
    {
        "id": "a27e6a3f73ac9865",
        "type": "ui_chart",
        "z": "4480a22badcc80b5",
        "name": "",
        "group": "194aa3cb24375fc7",
        "order": 1,
        "width": "0",
        "height": "0",
        "label": "温度折线图",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "0",
        "ymax": "101",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 850,
        "y": 840,
        "wires": [
            []
        ]
    },
    {
        "id": "edc7ed0408f90779",
        "type": "inject",
        "z": "4480a22badcc80b5",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 220,
        "y": 160,
        "wires": [
            [
                "7eea001d4cf904e6"
            ]
        ]
    },
    {
        "id": "2d621c5113bccb2d",
        "type": "mqtt out",
        "z": "4480a22badcc80b5",
        "name": "",
        "topic": "zwl2007331220",
        "qos": "2",
        "retain": "true",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "f7ad174f.17a3c",
        "x": 860,
        "y": 160,
        "wires": []
    },
    {
        "id": "1b5e58fdeae07547",
        "type": "debug",
        "z": "4480a22badcc80b5",
        "name": "debug 22",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 100,
        "wires": []
    },
    {
        "id": "7eea001d4cf904e6",
        "type": "random",
        "z": "4480a22badcc80b5",
        "name": "",
        "low": 1,
        "high": "111",
        "inte": "true",
        "property": "payload",
        "x": 480,
        "y": 160,
        "wires": [
            [
                "1b5e58fdeae07547",
                "2d621c5113bccb2d"
            ]
        ]
    },
    {
        "id": "345eb7e648e3d8b7",
        "type": "serial out",
        "z": "4480a22badcc80b5",
        "name": "LED灯串口",
        "serial": "8fd3b110b3c6dcee",
        "x": 850,
        "y": 360,
        "wires": []
    },
    {
        "id": "5c15c59c62795e9c",
        "type": "function",
        "z": "4480a22badcc80b5",
        "name": "function 1-zwl2007331220",
        "func": "var temp0 = new Buffer([0x00]);\nvar temp1 = new Buffer([0x01]);\nvar temp2 = new Buffer([0x02]);\nvar temp3 = new Buffer([0x03]);\nvar msg1 = { payload: msg.payload };\nif(msg.topic === \"zwl2007331220\"){\nif (msg1.payload >100) {\n    msg.payload = temp0;\n} else if (msg1.payload >= 70 && msg1.payload <= 100) {\n    msg.payload = temp1;\n} else if (msg1.payload >= 40 && msg1.payload < 70) {\n    msg.payload = temp2;\n}else{\n    msg.payload = temp3;\n}\nreturn msg;\n}else if (msg.topic === \"topic\"){\n    msg.payload = temp0;\n    return msg;}\nelse if (msg.topic === \"topic2\") {\n        msg.payload = temp1;\n        return msg;\n}else{\n    if (msg1.payload > 100) {\n        msg.payload = temp0;\n    } else if (msg1.payload >= 70 && msg1.payload <= 100) {\n        msg.payload = temp1;\n    } else if (msg1.payload >= 40 && msg1.payload < 70) {\n        msg.payload = temp2;\n    } else {\n        msg.payload = temp3;\n    }\n    return msg;\n}\n\n\n\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 320,
        "wires": [
            [
                "345eb7e648e3d8b7",
                "bb94797d502b77c0"
            ]
        ]
    },
    {
        "id": "004918129e3a3871",
        "type": "mqtt in",
        "z": "4480a22badcc80b5",
        "name": "",
        "topic": "zwl2007331220",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "f7ad174f.17a3c",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 240,
        "y": 340,
        "wires": [
            [
                "5c15c59c62795e9c"
            ]
        ]
    },
    {
        "id": "aabbee4a48ead696",
        "type": "ui_button",
        "z": "4480a22badcc80b5",
        "name": "",
        "group": "338b06a7370dade5",
        "order": 3,
        "width": "0",
        "height": "0",
        "passthru": false,
        "label": "断开",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "true",
        "payloadType": "bool",
        "topic": "topic",
        "topicType": "str",
        "x": 210,
        "y": 420,
        "wires": [
            [
                "5c15c59c62795e9c",
                "9a5a2572d0e79fa4"
            ]
        ]
    },
    {
        "id": "bb94797d502b77c0",
        "type": "debug",
        "z": "4480a22badcc80b5",
        "name": "debug 24",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 300,
        "wires": []
    },
    {
        "id": "7c8dec03ee16b37c",
        "type": "ui_button",
        "z": "4480a22badcc80b5",
        "name": "",
        "group": "338b06a7370dade5",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "换灯",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "true",
        "payloadType": "bool",
        "topic": "topic2",
        "topicType": "str",
        "x": 210,
        "y": 260,
        "wires": [
            [
                "5c15c59c62795e9c",
                "9a5a2572d0e79fa4"
            ]
        ]
    },
    {
        "id": "9a5a2572d0e79fa4",
        "type": "function",
        "z": "4480a22badcc80b5",
        "name": "function3-zwl2007331220",
        "func": "var msg2 = { payload: msg.payload};\n\n\n\n\nif (msg.topic === \"zwl2007331220\") {\n    if (msg2.payload > 100) {\n        msg.payload = '00';\n        var mysql = \"INSERT INTO LED2zwl VALUES ('%s')\";\n        var msg3 = {\n\n            \"topic\": util.format(mysql, '灰色')\n        }\n    } else if (msg2.payload >= 70 && msg2.payload <= 100) {\n        msg.payload = '01';\n        var mysql = \"INSERT INTO LED2zwl VALUES ('%s')\";\n        var msg3 = {\n\n            \"topic\": util.format(mysql, '红色')\n        }\n    } else if (msg2.payload >= 40 && msg2.payload < 70) {\n        msg.payload = '02';\n        var mysql = \"INSERT INTO LED2zwl VALUES ('%s')\";\n        var msg3 = {\n\n            \"topic\": util.format(mysql, '绿色')\n        }\n    } else {\n        msg.payload = '03';\n        var mysql = \"INSERT INTO LED2zwl VALUES ('%s')\";\n        var msg3 = {\n\n            \"topic\": util.format(mysql, '蓝色')\n        }\n    }\n    return [[msg], [msg3]];\n   \n} else if (msg.topic === \"topic\") {\n    msg.payload = '00';\n    return msg;\n} else {\n    if (msg2.payload > 100) {\n        msg.payload = '00';\n        var mysql = \"INSERT INTO LED2zwl VALUES ('%s')\";\n        var msg3 = {\n\n            \"topic\": util.format(mysql, '灰色')\n        }\n    } else if (msg2.payload >= 70 && msg2.payload <= 100) {\n        msg.payload = '01';\n        var mysql = \"INSERT INTO LED2zwl VALUES ('%s')\";\n        var msg3 = {\n\n            \"topic\": util.format(mysql, '红色')\n        }\n    } else if (msg2.payload >= 40 && msg2.payload < 70) {\n        msg.payload = '02';\n        var mysql = \"INSERT INTO LED2zwl VALUES ('%s')\";\n        var msg3 = {\n\n            \"topic\": util.format(mysql, '绿色')\n        }\n    } else {\n        msg.payload = '03';\n        var mysql = \"INSERT INTO LED2zwl VALUES ('%s')\";\n        var msg3 = {\n\n            \"topic\": util.format(mysql, '蓝色')\n        }\n    }\n    return [[msg], [msg3]];\n    \n}",
        "outputs": 2,
        "noerr": 8,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 560,
        "wires": [
            [
                "f77a74cfabb08859",
                "e48172629f8912c2"
            ],
            [
                "100482b02e6f35b3",
                "445bc122a3d75bf1"
            ]
        ]
    },
    {
        "id": "9c17c2b665b8d758",
        "type": "mqtt in",
        "z": "4480a22badcc80b5",
        "name": "",
        "topic": "zwl2007331220",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "f7ad174f.17a3c",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 240,
        "y": 560,
        "wires": [
            [
                "9a5a2572d0e79fa4"
            ]
        ]
    },
    {
        "id": "f77a74cfabb08859",
        "type": "ui_led",
        "z": "4480a22badcc80b5",
        "order": 1,
        "group": "86d9dae2c7d6e7e6",
        "width": 0,
        "height": 0,
        "label": "",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "colorForValue": [
            {
                "color": "#808080",
                "value": "00",
                "valueType": "str"
            },
            {
                "color": "#ff0000",
                "value": "01",
                "valueType": "str"
            },
            {
                "color": "#008000",
                "value": "02",
                "valueType": "str"
            },
            {
                "color": "#0000ff",
                "value": "03",
                "valueType": "str"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showGlow": true,
        "name": "",
        "x": 830,
        "y": 560,
        "wires": []
    },
    {
        "id": "100482b02e6f35b3",
        "type": "debug",
        "z": "4480a22badcc80b5",
        "name": "debug 32",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 620,
        "wires": []
    },
    {
        "id": "e48172629f8912c2",
        "type": "debug",
        "z": "4480a22badcc80b5",
        "name": "debug 33",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 500,
        "wires": []
    },
    {
        "id": "445bc122a3d75bf1",
        "type": "mysql",
        "z": "4480a22badcc80b5",
        "mydb": "c3ed5a2b931be081",
        "name": "",
        "x": 830,
        "y": 680,
        "wires": [
            []
        ]
    },
    {
        "id": "86d9dae2c7d6e7e6",
        "type": "ui_group",
        "name": "温度显示界面",
        "tab": "91403e6c2ad42c28",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "f7ad174f.17a3c",
        "type": "mqtt-broker",
        "name": "",
        "broker": "localhost:18083",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "compatmode": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "c3ed5a2b931be081",
        "type": "MySQLdatabase",
        "name": "",
        "host": "127.0.0.1",
        "port": "3306",
        "db": "test",
        "tz": "",
        "charset": "UTF8"
    },
    {
        "id": "194aa3cb24375fc7",
        "type": "ui_group",
        "name": "数据分析界面",
        "tab": "91403e6c2ad42c28",
        "order": 3,
        "disp": true,
        "width": "13",
        "collapse": false,
        "className": ""
    },
    {
        "id": "8fd3b110b3c6dcee",
        "type": "serial-port",
        "z": "4480a22badcc80b5",
        "serialport": "COM3",
        "serialbaud": "115200",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "waitfor": "",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "\\n",
        "bin": "false",
        "out": "char",
        "addchar": "",
        "responsetimeout": "10000"
    },
    {
        "id": "338b06a7370dade5",
        "type": "ui_group",
        "name": "控制LED亮灭界面",
        "tab": "91403e6c2ad42c28",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "91403e6c2ad42c28",
        "type": "ui_tab",
        "name": "Tab 1",
        "icon": "dashboard",
        "order": 1
    }
]
posted @ 2023-06-07 18:21  Mr_LL  阅读(242)  评论(0)    收藏  举报