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

 找回密码
 立即注册
楼主: adxr

[经验分享] 让爱快路由器对接HASS 版本2.0 全用Node-RED+MQTT实现

  [复制链接]

2

主题

28

帖子

118

积分

注册会员

Rank: 2

积分
118
金钱
90
HASS币
0
发表于 5 天前 | 显示全部楼层
本帖最后由 xiaomumu0303 于 2024-6-13 14:37 编辑

先说下,大佬的NR代码不能直接导入,但是11楼有好心人发了整理过格式的代码,那个可以直接用,用完另外以后还发现有点问题,我处理了以后记录如下:

大佬的代码一直执行不成功,我研究后总结下我的排障过程:

1、抓包要找post地址后面是/Action/login的那条请求,抓包不会的百度,我直接用iphone手机下了个steam来抓
2、看请求的主体内容如下:
{
  "username" : "ho******ant",
  "remember_password" : null,
  "pass" : "c2Fsd********bnQx",
  "passwd" : "822aa6b*******6ac0358f"
}
而大佬第一个funtion的代码是:
var username ="ho*****nt" ; //用户名
var pass = "822aa*****358f"; //密码MD5加密值
var ip ="192.168.*.*:80";//爱快IP加端口

global.set("ip", ip);
msg.headers = {};
msg.headers['Content-Type'] = 'application/json';
msg.payload = `{"username": "${username}","passwd":"${pass}","pass":"c2FsdF8xMUhvbWVhc3Npc3RhbnQx","remember_password":""}`;
msg.url = 'http://' + ip + '/Action/login';

return msg;

所以我的觉得除了usernames、passwd以外还要修改pass的值
为了方便阅读和后期修改,我把第一个funtion的代码部分改成了

var username ="ho*****ant" ; //用户名
var passwd = "822******58f"; //密码MD5加密值(抓包的)
var pass = "c2Fs******hbnQx"; //pass加密值(抓包的)
var ip ="192.168.*.*:80";//爱快IP加端口


global.set("ip", ip);
msg.headers = {};
msg.headers['Content-Type'] = 'application/json';
msg.payload = `{"username": "${username}","passwd":"${passwd}","pass":"${pass}","remember_password":""}`;
msg.url = 'http://' + ip + '/Action/login';

return msg;

最后成功获取到cookie
回复

使用道具 举报

16

主题

231

帖子

1610

积分

金牌会员

Rank: 6Rank: 6

积分
1610
金钱
1379
HASS币
0
发表于 5 天前 | 显示全部楼层
能不能实现在AC控制器下实现人员精准定位
回复

使用道具 举报

0

主题

13

帖子

50

积分

注册会员

Rank: 2

积分
50
金钱
37
HASS币
0
发表于 5 天前 | 显示全部楼层
我看看
回复

使用道具 举报

1

主题

13

帖子

93

积分

注册会员

Rank: 2

积分
93
金钱
80
HASS币
0
发表于 5 天前 | 显示全部楼层
学习学习一下
回复

使用道具 举报

1

主题

85

帖子

422

积分

中级会员

Rank: 3Rank: 3

积分
422
金钱
337
HASS币
0
发表于 5 天前 | 显示全部楼层
感谢分享,马上试一下
回复

使用道具 举报

1

主题

85

帖子

422

积分

中级会员

Rank: 3Rank: 3

积分
422
金钱
337
HASS币
0
发表于 5 天前 | 显示全部楼层
xiaomumu0303 发表于 2024-6-13 14:34
先说下,大佬的NR代码不能直接导入,但是11楼有好心人发了整理过格式的代码,那个可以直接用,用完另外以后 ...

试了你这个可以了,
回复

使用道具 举报

0

主题

22

帖子

161

积分

注册会员

Rank: 2

积分
161
金钱
139
HASS币
0
发表于 5 天前 | 显示全部楼层
学习一下
回复

使用道具 举报

0

主题

40

帖子

178

积分

注册会员

Rank: 2

积分
178
金钱
138
HASS币
0
发表于 4 天前 | 显示全部楼层
学习一下!
回复

使用道具 举报

0

主题

12

帖子

135

积分

注册会员

Rank: 2

积分
135
金钱
123
HASS币
0
发表于 4 天前 | 显示全部楼层
正需要一个可以通知新设备ip的插件,刚好网关是ikuai系统的。
回复

使用道具 举报

2

主题

28

帖子

118

积分

注册会员

Rank: 2

积分
118
金钱
90
HASS币
0
发表于 4 天前 | 显示全部楼层
限制mac那段不知道是代码被我动过了还是啥原因的,反正也是调不起来,现在改好了,贴出来以防万一

[
    {
        "id": "c8e808abf4f80545",
        "type": "debug",
        "z": "0380ab821e0383ce",
        "name": "ACL-MAC",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 380,
        "wires": []
    },
    {
        "id": "a1ea73e0c7966881",
        "type": "mqtt in",
        "z": "0380ab821e0383ce",
        "name": "MAC限网开关接收",
        "topic": "cmnd/ikuai/acl",
        "qos": "2",
        "datatype": "auto",
        "broker": "854a61c87270b850",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 210,
        "y": 300,
        "wires": [
            [
                "7747972f81806646",
                "9322ad2d9688c2ec"
            ]
        ]
    },
    {
        "id": "7747972f81806646",
        "type": "function",
        "z": "0380ab821e0383ce",
        "name": "开关限网cmnd",
        "func": "const rmsg = {};\nconst cmnd = msg.payload;\n\nswitch (cmnd) {\n    case \"10\":\n        rmsg.id = \"1\"; // mac限网ID\n        rmsg.action = \"down\"; // 限网开up/关down\n        break;\n    case \"11\":\n        rmsg.id = \"1\"; // mac限网ID\n        rmsg.action = \"up\"; // 限网开up/关down\n        break;\n    case \"20\":\n        rmsg.id = \"2\"; // mac限网ID\n        rmsg.action = \"down\"; // 限网开up/关down\n        break;\n    case \"21\":\n        rmsg.id = \"2\"; // mac限网ID\n        rmsg.action = \"up\"; // 限网开up/关down\n        break;\n    default:\n        node.warn(\"Unknown command: \" + cmnd);\n        return null;\n}\n\nreturn rmsg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 460,
        "y": 300,
        "wires": [
            [
                "0964acc01adccbbd"
            ]
        ]
    },
    {
        "id": "0964acc01adccbbd",
        "type": "function",
        "z": "0380ab821e0383ce",
        "name": "MAC_ALC限网",
        "func": "var cookie = flow.get(\"cookie\");\nvar ip = flow.get(\"ip\");\n\nmsg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['cookie'] = cookie;\nmsg.payload = `{\"func_name\":\"acl_mac\",\"action\":\"${msg.action}\",\"param\":{\"id\":\"${msg.id}\"}}`;\nmsg.url = 'http://' + ip +'/Action/call';\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 660,
        "y": 300,
        "wires": [
            [
                "e3c0eedca3929c6e",
                "810937fe64701f1a"
            ]
        ]
    },
    {
        "id": "d85996e020c63e58",
        "type": "function",
        "z": "0380ab821e0383ce",
        "name": "整理结果",
        "func": "var data = msg.payload.Data.data;\nvar id;\nvar enabled;\nmsg = {};\nmsg.payload = {};\nvar dalen = data.length;\n\nfor (var i = 0; i < dalen; i++) {\n    id = data[i].id;\n    if (data[i].enabled === \"yes\") {\n        enabled = \"ON\";\n    } else {\n        enabled = \"OFF\";\n    }\n    msg.payload[id] = enabled;\n}\n\n// 添加调试信息\nnode.warn(`Parsed Data: ${JSON.stringify(msg.payload)}`);\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 960,
        "y": 460,
        "wires": [
            [
                "c8e808abf4f80545",
                "289c13a9895f9ed6"
            ]
        ]
    },
    {
        "id": "8c70993fcd533113",
        "type": "function",
        "z": "0380ab821e0383ce",
        "name": "请求更新限网状态",
        "func": "msg.action=\"show\";//限网开up/关down\nmsg.id=\"\";//mac限网ID\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 330,
        "y": 460,
        "wires": [
            [
                "6ae93e1b4659ae12",
                "69765f8b22e1b19a"
            ]
        ]
    },
    {
        "id": "6ae93e1b4659ae12",
        "type": "function",
        "z": "0380ab821e0383ce",
        "name": "MAC_ALC限网",
        "func": "var cookie = flow.get(\"cookie\");\nvar ip = flow.get(\"ip\");\n\nmsg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['cookie'] = cookie;\nmsg.payload = `{\"func_name\":\"acl_mac\",\"action\":\"${msg.action}\",\"param\":{\"id\":\"${msg.id}\"}}`;\nmsg.url = 'http://' + ip +'/Action/call';\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 460,
        "wires": [
            [
                "44e8ff13fdb4714d",
                "952fc8c0daea76a6"
            ]
        ]
    },
    {
        "id": "44e8ff13fdb4714d",
        "type": "http request",
        "z": "0380ab821e0383ce",
        "name": "发送请求",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 780,
        "y": 460,
        "wires": [
            [
                "d85996e020c63e58"
            ]
        ]
    },
    {
        "id": "289c13a9895f9ed6",
        "type": "mqtt out",
        "z": "0380ab821e0383ce",
        "name": "ikuai/acl",
        "topic": "stat/ikuai/acl",
        "qos": "0",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "854a61c87270b850",
        "x": 920,
        "y": 560,
        "wires": []
    },
    {
        "id": "e3c0eedca3929c6e",
        "type": "http request",
        "z": "0380ab821e0383ce",
        "name": "发送请求",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 840,
        "y": 300,
        "wires": [
            [
                "24466d6b5e210fcc",
                "8c70993fcd533113"
            ]
        ]
    },
    {
        "id": "810937fe64701f1a",
        "type": "debug",
        "z": "0380ab821e0383ce",
        "name": "发送请求",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 220,
        "wires": []
    },
    {
        "id": "9322ad2d9688c2ec",
        "type": "debug",
        "z": "0380ab821e0383ce",
        "name": "收到",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 390,
        "y": 240,
        "wires": []
    },
    {
        "id": "952fc8c0daea76a6",
        "type": "debug",
        "z": "0380ab821e0383ce",
        "name": "发送请求2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 690,
        "y": 560,
        "wires": []
    },
    {
        "id": "24466d6b5e210fcc",
        "type": "debug",
        "z": "0380ab821e0383ce",
        "name": "debug 11",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1040,
        "y": 300,
        "wires": []
    },
    {
        "id": "69765f8b22e1b19a",
        "type": "debug",
        "z": "0380ab821e0383ce",
        "name": "请求更新限网状态",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 390,
        "y": 620,
        "wires": []
    },
    {
        "id": "854a61c87270b850",
        "type": "mqtt-broker",
        "name": "",
        "broker": "core-mosquitto",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-6-18 20:34 , Processed in 0.087196 second(s), 30 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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