『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: zxlch

[基础教程] 使用TCP通信方式控制小米电视

[复制链接]

8

主题

90

帖子

567

积分

高级会员

Rank: 4

积分
567
金钱
477
HASS币
0
发表于 2021-12-3 14:45:49 | 显示全部楼层
回复

使用道具 举报

15

主题

304

帖子

2237

积分

金牌会员

Rank: 6Rank: 6

积分
2237
金钱
1933
HASS币
0
发表于 2021-12-3 22:09:32 | 显示全部楼层
本帖最后由 cjnt007 于 2021-12-18 18:02 编辑
zxlch 发表于 2021-11-14 23:15
http resquest不能拼接协议,因为他封装了

可以使用的,我把楼主的flow作了修改,使用http request节点发送控制信息,正常使用没有问题
[
    {
        "id": "514354bccdd417aa",
        "type": "http request",
        "z": "4bc863fe95c091b7",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "query",
        "url": "http://192.168.10.64:6095/controller",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "credentials": {},
        "x": 540,
        "y": 60,
        "wires": [
            []
        ]
    },
    {
        "id": "035a2b1f7f8ba71a",
        "type": "function",
        "z": "4bc863fe95c091b7",
        "name": "",
        "func": "msg.payload={\n    'action':'keyevent',\n    'keycode':`${msg.payload}`\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 60,
        "wires": [
            [
                "514354bccdd417aa",
                "214468d1afd2e14c"
            ]
        ]
    },
    {
        "id": "1c9188a067e04f86",
        "type": "inject",
        "z": "4bc863fe95c091b7",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "enter",
        "payloadType": "str",
        "x": 130,
        "y": 140,
        "wires": [
            [
                "035a2b1f7f8ba71a"
            ]
        ]
    },
    {
        "id": "8779f6c9d176b22d",
        "type": "inject",
        "z": "4bc863fe95c091b7",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "menu",
        "payloadType": "str",
        "x": 130,
        "y": 200,
        "wires": [
            [
                "035a2b1f7f8ba71a"
            ]
        ]
    },
    {
        "id": "e051458bb50104e7",
        "type": "mqtt in",
        "z": "4bc863fe95c091b7",
        "name": "miTV4",
        "topic": "control/mitv4/send",
        "qos": "2",
        "datatype": "auto",
        "broker": "b50ed318f890a537",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 120,
        "y": 60,
        "wires": [
            [
                "035a2b1f7f8ba71a"
            ]
        ]
    },
    {
        "id": "214468d1afd2e14c",
        "type": "debug",
        "z": "4bc863fe95c091b7",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 560,
        "y": 120,
        "wires": []
    },
    {
        "id": "b50ed318f890a537",
        "type": "mqtt-broker",
        "name": "",
        "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": ""
    }
]

大家使用时注意把http request节点里的URL中的IP地址换成自己的
回复

使用道具 举报

44

主题

632

帖子

3560

积分

论坛元老

Rank: 8Rank: 8

积分
3560
金钱
2928
HASS币
0
发表于 2021-12-18 02:15:14 | 显示全部楼层
cjnt007 发表于 2021-12-3 22:09
可以使用的,我把楼主的flow作了修改,使用http request节点发送控制信息,正常使用没有问题

大家使用时 ...

无法导入nr 提示有错误
回复

使用道具 举报

15

主题

304

帖子

2237

积分

金牌会员

Rank: 6Rank: 6

积分
2237
金钱
1933
HASS币
0
发表于 2021-12-18 17:59:51 | 显示全部楼层
wangmucha 发表于 2021-12-18 02:15
无法导入nr 提示有错误
[
    {
        "id": "514354bccdd417aa",
        "type": "http request",
        "z": "4bc863fe95c091b7",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "query",
        "url": "http://192.168.10.64:6095/controller",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "credentials": {},
        "x": 540,
        "y": 60,
        "wires": [
            []
        ]
    },
    {
        "id": "035a2b1f7f8ba71a",
        "type": "function",
        "z": "4bc863fe95c091b7",
        "name": "",
        "func": "msg.payload={\n    'action':'keyevent',\n    'keycode':`${msg.payload}`\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 60,
        "wires": [
            [
                "514354bccdd417aa",
                "214468d1afd2e14c"
            ]
        ]
    },
    {
        "id": "1c9188a067e04f86",
        "type": "inject",
        "z": "4bc863fe95c091b7",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "enter",
        "payloadType": "str",
        "x": 130,
        "y": 140,
        "wires": [
            [
                "035a2b1f7f8ba71a"
            ]
        ]
    },
    {
        "id": "8779f6c9d176b22d",
        "type": "inject",
        "z": "4bc863fe95c091b7",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "menu",
        "payloadType": "str",
        "x": 130,
        "y": 200,
        "wires": [
            [
                "035a2b1f7f8ba71a"
            ]
        ]
    },
    {
        "id": "e051458bb50104e7",
        "type": "mqtt in",
        "z": "4bc863fe95c091b7",
        "name": "miTV4",
        "topic": "control/mitv4/send",
        "qos": "2",
        "datatype": "auto",
        "broker": "b50ed318f890a537",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 120,
        "y": 60,
        "wires": [
            [
                "035a2b1f7f8ba71a"
            ]
        ]
    },
    {
        "id": "214468d1afd2e14c",
        "type": "debug",
        "z": "4bc863fe95c091b7",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 560,
        "y": 120,
        "wires": []
    },
    {
        "id": "b50ed318f890a537",
        "type": "mqtt-broker",
        "name": "",
        "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": ""
    }
]

我检查了下,是双引号的问题,我在function Node里的键值对使用了双引号,node-red导出时在外面又加了双引号
回复

使用道具 举报

5

主题

259

帖子

1590

积分

金牌会员

Rank: 6Rank: 6

积分
1590
金钱
1331
HASS币
0
发表于 2021-12-27 22:10:18 | 显示全部楼层
本帖最后由 damp521 于 2021-12-27 22:11 编辑

好东西,前排留名。导入red流后是不要重启下?没重启直接配置ha文件报错。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-27 11:14 , Processed in 0.053145 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表