【node-red】利用乐橙云实现推送报警或门铃触发图片到邮箱。
这个是自己编辑的一套流程,我用时间触发使用了几个月很稳定,可恨的是乐橙直播连接视频要收费了,拍照没有影响但是有次数限制,应该自用也够了。这个也可以用其他条件触发。所有要填的信息都可以通过乐橙云找到,不懂的网上多查一下。[
{
"id": "971cc31c1202573a",
"type": "tab",
"label": "乐橙监控拍照邮件推送",
"disabled": false,
"info": "",
"env": []
},
{
"id": "2985e10b471de67c",
"type": "inject",
"z": "971cc31c1202573a",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 70,
"y": 120,
"wires": [
[
"379e2c6c4376c7b0"
]
]
},
{
"id": "2727c7c40c568e4a",
"type": "function",
"z": "971cc31c1202573a",
"name": "function 2",
"func": "\nvar ver = msg.payload.ver\nvar appId = msg.payload.appId\nvar sign = msg.payload\nvar time = msg.payload.timestamp\nvar nonce = msg.payload.nonce\nvar id = msg.payload.id\nmsg.payload =\n{\n \"system\": {\n \"ver\": ver,\n \"appId\": appId,\n \"sign\": sign,\n \"time\": time,\n \"nonce\": nonce,\n },\n \"id\": id,\n \"params\": {\n\n }\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 680,
"y": 140,
"wires": [
[
"e9c4e8b255ef3a90"
]
]
},
{
"id": "379e2c6c4376c7b0",
"type": "function",
"z": "971cc31c1202573a",
"name": "function 3",
"func": "function getTime() {\n var timestamp = Math.round(new Date().getTime() / 1000);\n return timestamp;\n}\n\nvar ver = \"1.0\";\nvar appId = \"\"; //填入自己的appid\nvar appSecret = \"\"; //填入自己的appSecret\nvar timestamp = getTime();\nvar nonce = Math.random().toString(36).substr(2);\nvar id = Math.floor(Math.random() * (50 - 1 + 1) + 1);\nvar sign = \"time:\" + timestamp + \",nonce:\" + nonce + \",appSecret:\" + appSecret;\n\nvar data = {\n \"ver\": ver,\n \"appId\": appId,\n \"appSecret\" : appSecret,\n \"timestamp\": timestamp,\n \"nonce\": nonce,\n \"sign\": sign,\n \"id\": id\n}\nmsg.payload = data;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 200,
"y": 120,
"wires": [
[
"9c859158d2eb588b",
"3468b523ea59fd0e"
]
]
},
{
"id": "e9c4e8b255ef3a90",
"type": "http request",
"z": "971cc31c1202573a",
"name": "",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://openapi.lechange.cn/openapi/accessToken",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 840,
"y": 100,
"wires": [
[
"f198403f17c5a9c5",
"6c03e2d7156c3183"
]
]
},
{
"id": "f198403f17c5a9c5",
"type": "debug",
"z": "971cc31c1202573a",
"name": "debug 53",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 860,
"y": 140,
"wires": []
},
{
"id": "3468b523ea59fd0e",
"type": "function",
"z": "971cc31c1202573a",
"name": "function 4",
"func": "\nmsg.parts = {};\nmsg.parts.id = \"old\";\nmsg.parts.index = 1;\nmsg.parts.count = 2;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 140,
"wires": [
[
"8a96dc091762942b"
]
]
},
{
"id": "eca5ec53e6d11922",
"type": "digest",
"z": "971cc31c1202573a",
"name": "",
"algorithm": "MD5",
"x": 510,
"y": 100,
"wires": [
[
"109337a9eb645c4a"
]
]
},
{
"id": "109337a9eb645c4a",
"type": "function",
"z": "971cc31c1202573a",
"name": "function 6",
"func": "\nmsg.parts = {};\nmsg.parts.id = \"newsign\";\nmsg.parts.index = 0;\nmsg.parts.count = 2;\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 660,
"y": 100,
"wires": [
[
"8a96dc091762942b"
]
]
},
{
"id": "9c859158d2eb588b",
"type": "function",
"z": "971cc31c1202573a",
"name": "function 9",
"func": "msg.payload = (msg.payload.sign)\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 100,
"wires": [
[
"eca5ec53e6d11922"
]
]
},
{
"id": "8a96dc091762942b",
"type": "join",
"z": "971cc31c1202573a",
"name": "",
"mode": "custom",
"build": "array",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "num",
"reduceFixup": "",
"x": 510,
"y": 140,
"wires": [
[
"2727c7c40c568e4a"
]
]
},
{
"id": "0c3b9e9fa55324fa",
"type": "file",
"z": "971cc31c1202573a",
"name": "存储token",
"filename": "C:\\node-red\\imoutoken.txt",
"filenameType": "str",
"appendNewline": false,
"createDir": false,
"overwriteFile": "true",
"encoding": "none",
"x": 1180,
"y": 100,
"wires": [
[
"e91ec5104c1e58d2"
]
]
},
{
"id": "d0546fbf169b4471",
"type": "file in",
"z": "971cc31c1202573a",
"name": "读取token",
"filename": "C:\\node-red\\imoutoken.txt",
"filenameType": "str",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "utf8",
"allProps": false,
"x": 140,
"y": 260,
"wires": [
[
"335854bc75adbd16"
]
]
},
{
"id": "e91ec5104c1e58d2",
"type": "debug",
"z": "971cc31c1202573a",
"name": "debug 105",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1150,
"y": 140,
"wires": []
},
{
"id": "9ed174d20f415461",
"type": "inject",
"z": "971cc31c1202573a",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 110,
"y": 360,
"wires": [
[
"d0546fbf169b4471",
"bd15dcec7d97e568"
]
]
},
{
"id": "6c03e2d7156c3183",
"type": "function",
"z": "971cc31c1202573a",
"name": "取accessToken值",
"func": "msg.payload = msg.payload.result.data.accessToken\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1010,
"y": 100,
"wires": [
[
"0c3b9e9fa55324fa"
]
]
},
{
"id": "bd15dcec7d97e568",
"type": "function",
"z": "971cc31c1202573a",
"name": "设置主参数",
"func": "function getTime() {\n var timestamp = Math.round(new Date().getTime() / 1000);\n return timestamp;\n}\n\nvar ver = \"1.0\";\nvar appId = \"\"; //填入自己的appid\nvar appSecret = \"\"; //填入自己的appSecret\nvar deviceId = \"\" //填入自己摄像头ID\nvar channelId = \"0\" //填入自己摄像头通道号\nvar timestamp = getTime();\nvar nonce = Math.random().toString(36).substr(2);\nvar id = Math.floor(Math.random() * (50 - 1 + 1) + 1);\nvar sign = \"time:\" + timestamp + \",nonce:\" + nonce + \",appSecret:\" + appSecret;\n\nvar data = {\n \"ver\": ver,\n \"appId\": appId,\n \"appSecret\" : appSecret,\n \"deviceId\": deviceId,\n \"channelId\": channelId,\n \"timestamp\": timestamp,\n \"nonce\": nonce,\n \"sign\": sign,\n \"id\": id\n}\nmsg.payload = data;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 130,
"y": 300,
"wires": [
[
"719d5f9e38e2566c",
"f48e79c601b8ba15"
]
]
},
{
"id": "be4caf6939db5455",
"type": "function",
"z": "971cc31c1202573a",
"name": "格式化",
"func": "\nvar ver = msg.payload.ver\nvar appId = msg.payload.appId\nvar token = msg.payload\nvar sign = msg.payload\nvar time = msg.payload.timestamp\nvar nonce = msg.payload.nonce\nvar id = msg.payload.id\nvar deviceId = msg.payload.deviceId\nvar channelId = msg.payload.channelId\nmsg.payload =\n{\n \"system\": {\n \"ver\": ver,\n \"appId\": appId,\n \"sign\": sign,\n \"time\": time,\n \"nonce\": nonce\n },\n \"id\": id,\n \"params\": {\n \"deviceId\": deviceId,\n \"channelId\": channelId,\n \"token\": token,\n }\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 630,
"y": 280,
"wires": [
[
"2ea562e4021c5e83"
]
]
},
{
"id": "6cb81053a3cf8927",
"type": "join",
"z": "971cc31c1202573a",
"name": "合并",
"mode": "custom",
"build": "array",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "num",
"reduceFixup": "",
"x": 510,
"y": 280,
"wires": [
[
"be4caf6939db5455"
]
]
},
{
"id": "335854bc75adbd16",
"type": "function",
"z": "971cc31c1202573a",
"name": "提取token值",
"func": "\nmsg.parts = {};\nmsg.parts.id = \"token\";\nmsg.parts.index = 2;\nmsg.parts.count = 3;\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 310,
"y": 260,
"wires": [
[
"6cb81053a3cf8927"
]
]
},
{
"id": "3d38b6158e9e8e60",
"type": "function",
"z": "971cc31c1202573a",
"name": "合并前赋值",
"func": "\nmsg.parts = {};\nmsg.parts.id = \"newsign\";\nmsg.parts.index = 0;\nmsg.parts.count = 3;\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 610,
"y": 340,
"wires": [
[
"6cb81053a3cf8927"
]
]
},
{
"id": "fb1b80d5eaae5ee7",
"type": "digest",
"z": "971cc31c1202573a",
"name": "MD5",
"algorithm": "MD5",
"x": 470,
"y": 340,
"wires": [
[
"3d38b6158e9e8e60"
]
]
},
{
"id": "719d5f9e38e2566c",
"type": "function",
"z": "971cc31c1202573a",
"name": "提取sign值",
"func": "msg.payload = (msg.payload.sign)\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 310,
"y": 340,
"wires": [
[
"fb1b80d5eaae5ee7"
]
]
},
{
"id": "f48e79c601b8ba15",
"type": "function",
"z": "971cc31c1202573a",
"name": "其他值继续",
"func": "\nmsg.parts = {};\nmsg.parts.id = \"old\";\nmsg.parts.index = 1;\nmsg.parts.count = 3;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 310,
"y": 300,
"wires": [
[
"6cb81053a3cf8927"
]
]
},
{
"id": "2ea562e4021c5e83",
"type": "http request",
"z": "971cc31c1202573a",
"name": "",
"method": "POST",
"ret": "txt",
"paytoqs": "ignore",
"url": "https://openapi.lechange.cn/openapi/setDeviceSnap",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 760,
"y": 280,
"wires": [
[
"8d8f7cf1c0c3c042"
]
]
},
{
"id": "e49d29a0a075082d",
"type": "function",
"z": "971cc31c1202573a",
"name": "取url值",
"func": "msg.payload = (msg.payload.result.data.url)\nreturn msg;\n\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 820,
"y": 340,
"wires": [
[
"70c1818e3578286b"
]
]
},
{
"id": "8d8f7cf1c0c3c042",
"type": "json",
"z": "971cc31c1202573a",
"name": "",
"property": "payload",
"action": "obj",
"pretty": false,
"x": 890,
"y": 280,
"wires": [
[
"b3a739995ecc9515"
]
]
},
{
"id": "b3a739995ecc9515",
"type": "switch",
"z": "971cc31c1202573a",
"name": "token值判断",
"property": "payload.result.msg",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "token已过期或不存在,请重新获取token。",
"vt": "str"
},
{
"t": "eq",
"v": "操作成功。",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1030,
"y": 280,
"wires": [
[
"379e2c6c4376c7b0",
"e00281e05c61b6f5"
],
[
"e49d29a0a075082d"
]
]
},
{
"id": "e00281e05c61b6f5",
"type": "delay",
"z": "971cc31c1202573a",
"name": "",
"pauseType": "delay",
"timeout": "2",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 80,
"y": 180,
"wires": [
[
"bd15dcec7d97e568",
"d0546fbf169b4471"
]
]
},
{
"id": "f44e0459ce3bd957",
"type": "jsontohtml",
"z": "971cc31c1202573a",
"transform": "{\"<>\":\"head\",\"html\":[{\"<>\":\"title\",\"html\":\"显示图片\"},{\"<>\":\"img\",\"src\":\"${url}\",\"style\":\"${imag}\"},{\"<>\":\"a\",\"href\":\"${live}\",\"style\":\"${font}\",\"text\":\"直播\"}]}",
"name": "",
"x": 1130,
"y": 340,
"wires": [
[
"1b5dbdc8eb9c4a64"
]
]
},
{
"id": "70c1818e3578286b",
"type": "function",
"z": "971cc31c1202573a",
"name": "html赋值",
"func": "var url = msg.payload;\nvar live = \"填入自己的摄像头直播地址\"\n//修改直播链接地址\nvar font = \"font-size: 80px\"//修改直播文字链接字体大小\nvar imag = \"width: 900px; height: 500px;\" //修改推送图片显示分辨率\nvar roomMap = \"门口\"\nvar topic = \"报警信息\"\n\nmsg.payload =\n[\n {\n \"url\": url,\n \"live\": live,\n \"font\": font,\n \"imag\": imag,\n \"roomMap\": roomMap,\n \"topic\": topic,\n }\n]\n//msg.payload = [(url), (roomMap), (topic)]\n//msg.url = url;\n//msg.roomMap = roomMap;\n//msg.topic = topic;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 960,
"y": 340,
"wires": [
[
"f44e0459ce3bd957"
]
]
},
{
"id": "588c24524f67c296",
"type": "comment",
"z": "971cc31c1202573a",
"name": "乐橙token获取流程",
"info": "",
"x": 110,
"y": 80,
"wires": []
},
{
"id": "7368319d929e71a4",
"type": "comment",
"z": "971cc31c1202573a",
"name": "乐橙设备抓图发邮件流程",
"info": "",
"x": 150,
"y": 400,
"wires": []
},
{
"id": "1b5dbdc8eb9c4a64",
"type": "function",
"z": "971cc31c1202573a",
"name": "格式化邮件",
"func": "\nvar topic = \"报警信息\"\nvar theme = msg.payload\n//msg.to = \"@qq.com\";\n//msg.cc = \"@163.com\";//抄送邮件\n//msg.bcc = \"@qq.com\";\nmsg.payload = theme;\nmsg.topic = topic;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1290,
"y": 340,
"wires": [
[
"89a5152219038d8f",
"6a0ce86fc09d3219"
]
]
},
{
"id": "89a5152219038d8f",
"type": "e-mail",
"z": "971cc31c1202573a",
"server": "smtp.qq.com",
"port": "465",
"authtype": "BASIC",
"saslformat": true,
"token": "oauth2Response.access_token",
"secure": true,
"tls": true,
"name": "自己的QQ邮箱@qq.com",
"dname": "",
"credentials": {},
"x": 1290,
"y": 280,
"wires": []
},
{
"id": "6a0ce86fc09d3219",
"type": "e-mail",
"z": "971cc31c1202573a",
"server": "smtp.qq.com",
"port": "465",
"authtype": "BASIC",
"saslformat": true,
"token": "oauth2Response.access_token",
"secure": true,
"tls": true,
"name": "备用邮箱@163.com",
"dname": "",
"x": 1280,
"y": 240,
"wires": []
}
]
谢谢大佬,刚好用乐橙云 大佬,你的flows文件是不是没导出全呀
页:
[1]