Node-RED中建立Websocket客户端连接

发布时间:2022-06-20 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Node-RED中建立Websocket客户端连接脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

场景

Node-red简介与Windows上安装、启动和运行示例:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/121884766

Node-RED怎样导出导入流程为json文件

https://bLOG.csdn.net/BADAO_LIUMANG_QIZHI/article/details/124130985

Node-RED中建立websocket客户端是使用websocket in 和websocket out建立。

@H_304_14@

 

 

注:

博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关子书、教程推送与免费下载。

实现

1、拖拽inject节点,指定传送字符串

Node-RED中建立Websocket客户端连接

 

 

  

2、拖拽websocket out节点并编辑

类型为连接,URL为ws的服务端地址

Node-RED中建立Websocket客户端连接

 

 

3、再编辑一个websocket in节点,在类型选择连接,URL选择之前新增的url

Node-RED中建立Websocket客户端连接

 

 

4、搭建一个ws的服务端,与客户端进行连接测试,ws服务端可以自己网上搜搜。

Node-RED中建立Websocket客户端连接

 

 

 

Node-RED中建立Websocket客户端连接

5、json数据

[
    {
        "id": "f4a4d8eab7935bc8",
        "tyPE": "tab",
        "label": "流程 3",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "c428312d1f6165d1",
        "type": "mqtt-broker",
        "name": "mqtt",
        "broker": "127.0.0.1",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "PRotocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "cloSEMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    },
    {
        "id": "51eee50b4ec9422f",
        "type": "ui_group",
        "name": "@R_406_341@Demo",
        "tab": "29ae4c620f43ee0d",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "classname": ""
    },
    {
        "id": "29ae4c620f43ee0d",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    },
    {
        "id": "a506c767a5c1edbd",
        "type": "ui_base",
        "theme": {
            "name": "theme-light",
            "lightTheme": {
                "default": "#0094CE",
                "baseColor": "#0094CE",
                "baseFont": "-apple-System,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-sans,ubuntu,Cantarell,Helvetica Neue,sans-serif",
                "edITed": true,
                "reset": false
            },
            "darkTheme": {
                "default": "#097479",
                "baseColor": "#097479",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
                "edited": false
            },
            "customTheme": {
                "name": "Untitled Theme 1",
                "default": "#4B7930",
                "baseColor": "#4B7930",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
            },
            "themestate": {
                "base-color": {
                    "default": "#0094CE",
                    "value": "#0094CE",
                    "edited": false
                },
                "page-titlebar-backgroundColor": {
                    "value": "#0094CE",
                    "edited": false
                },
                "page-backgroundColor": {
                    "value": "#fafafa",
                    "edited": false
                },
                "page-sidebar-backgroundColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "group-textColor": {
                    "value": "#1bbfff",
                    "edited": false
                },
                "group-borderColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "group-backgroundColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "widget-textColor": {
                    "value": "#111111",
                    "edited": false
                },
                "widget-backgroundColor": {
                    "value": "#0094ce",
                    "edited": false
                },
                "widget-borderColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "base-font": {
                    "value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
                }
            },
            "AngularTheme": {
                "Primary": "indigo",
                "accents": "blue",
                "warn": "red",
                "background": "grey",
                "palette": "light"
            }
        },
        "site": {
            "name": "Node-RED Dashboard",
            "hideToolbar": "false",
            "allowSwipe": "false",
            "lockMenu": "false",
            "allowTempTheme": "true",
            "dateFormat": "DD/MM/yyYY",
            "sizes": {
                "sx": 48,
                "sy": 48,
                "gx": 6,
                "gy": 6,
                "cx": 6,
                "cy": 6,
                "px": 0,
                "py": 0
            }
        }
    },
    {
        "id": "248cbbb0.18e794",
        "type": "ui_group",
        "name": "MyGroup",
        "tab": "3f79c420.cfc1bc",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "3f79c420.CFc1bc",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    },
    {
        "id": "a0954be5.a7f7e8",
        "type": "ui_group",
        "name": "MyInput",
        "tab": "3f79c420.cfc1bc",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "508bd6f8398ab80f",
        "type": "ui_group",
        "name": "OpenWeatherMap",
        "tab": "3f79c420.cfc1bc",
        "order": 3,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "8824dea1.83e31",
        "type": "websocket-client",
        "path": "ws://localhost:9898/",
        "tls": "",
        "wholemsg": "false"
    },
    {
        "id": "b40b0437.522ab8",
        "type": "websocket in",
        "z": "f4a4d8eab7935bc8",
        "name": "",
        "server": "",
        "client": "8824dea1.83e31",
        "x": 290,
        "y": 240,
        "wires": [
            [
                "24d481b8.2f71ae"
            ]
        ]
    },
    {
        "id": "ad931922.6eF1b8",
        "type": "websocket out",
        "z": "f4a4d8eab7935bc8",
        "name": "",
        "server": "",
        "client": "8824dea1.83e31",
        "x": 520,
        "y": 160,
        "wires": []
    },
    {
        "id": "c9dd9e39.c618f",
        "type": "inject",
        "z": "f4a4d8eab7935bc8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "Hello There",
        "payloadType": "str",
        "x": 280,
        "y": 160,
        "wires": [
            [
                "ad931922.6ef1b8"
            ]
        ]
    },
    {
        "id": "24d481b8.2f71ae",
        "type": "debug",
        "z": "f4a4d8eab7935bc8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 610,
        "y": 240,
        "wires": []
    }
] 

 

脚本宝典总结

以上是脚本宝典为你收集整理的Node-RED中建立Websocket客户端连接全部内容,希望文章能够帮你解决Node-RED中建立Websocket客户端连接所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。