node-red


[
{
"id": "7c254e2b.1938c",
"type": "http in",
"z": "d1cc3ace.5b5638",
"name": "POST sample ",
"url": "/webhook",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 87,
"y": 166,
"wires": [
[
"6a8bf7e3.5dd328",
"355ba63a.72d85a"
]
]
},
{
"id": "6a8bf7e3.5dd328",
"type": "function",
"z": "d1cc3ace.5b5638",
"name": "event type text",
"func": "var event = msg.payload[\"events\"][0];\nif(event[\"type\"] == \"message\"){\n \n\n\nvar message = event[\"message\"][\"text\"];\nmsg.message = message;\nmessage = \"เรียบร้อยค่ะ\";\nvar replyToken = event[\"replyToken\"];\nvar replyMessage = {\"type\": \"text\", \"text\": message}\nmsg.payload = {\"messages\": [replyMessage], \"replyToken\": replyToken};\nmsg.headers ={ \"Content-Type\": \"application/json\", \"Authorization\": \"Bearer UAUhWiqKAQE75xUjF5HvkBmctcOHS6cw0R+HnigweWhbH6/dPAqyU+msRtcT4alitYL+xMkQubnqvAHeHWf83HZ1+/jAU3w5KQfvm5zJXgMXlzJUU1ikam92ewBFfOGopNYucVZ+0Bn7K8rpSGxF8AdB04t89/1O/w1cDnyilFU=\"};\nreturn msg;\n}else{\nreturn msg;\n\n}",
"outputs": 1,
"noerr": 0,
"x": 294,
"y": 165,
"wires": [
[
"d98dcac6.74e308",
"db24d40a.b224c8",
"728dc41f.adcdec"
]
]
},
{
"id": "d98dcac6.74e308",
"type": "http request",
"z": "d1cc3ace.5b5638",
"name": "LINE REPLY API",
"method": "POST",
"ret": "txt",
"url": "https://api.line.me/v2/bot/message/reply",
"tls": "",
"x": 538,
"y": 165,
"wires": [
[
"58fa7566.44eb6c"
]
]
},
{
"id": "58fa7566.44eb6c",
"type": "debug",
"z": "d1cc3ace.5b5638",
"name": "API",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 717,
"y": 165,
"wires": []
},
{
"id": "db24d40a.b224c8",
"type": "debug",
"z": "d1cc3ace.5b5638",
"name": "request",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 556,
"y": 87,
"wires": []
},
{
"id": "3f53076e.88a488",
"type": "mqtt out",
"z": "d1cc3ace.5b5638",
"name": "",
"topic": "YMC2018/data",
"qos": "0",
"retain": "",
"broker": "3faed9e7.73bbe6",
"x": 737.5,
"y": 225,
"wires": []
},
{
"id": "728dc41f.adcdec",
"type": "switch",
"z": "d1cc3ace.5b5638",
"name": "เปรียบเทียบคำสั่ง",
"property": "message",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "เปิดไฟหน้าบ้าน",
"vt": "str"
},
{
"t": "eq",
"v": "ปิดไฟหน้าบ้าน",
"vt": "str"
},
{
"t": "eq",
"v": "เปิดไฟ",
"vt": "str"
},
{
"t": "eq",
"v": "ปิดไฟ",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 4,
"x": 297.5,
"y": 237,
"wires": [
[
"1a443ca6.00e173"
],
[
"20ce2e6e.cd9782"
],
[
"1a443ca6.00e173"
],
[
"20ce2e6e.cd9782"
]
]
},
{
"id": "1a443ca6.00e173",
"type": "function",
"z": "d1cc3ace.5b5638",
"name": "เปิด",
"func": "msg.payload = '1'\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 492.5,
"y": 210,
"wires": [
[
"3f53076e.88a488"
]
]
},
{
"id": "20ce2e6e.cd9782",
"type": "function",
"z": "d1cc3ace.5b5638",
"name": "ปิด",
"func": "msg.payload = '0'\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 497,
"y": 261,
"wires": [
[
"3f53076e.88a488"
]
]
},
{
"id": "355ba63a.72d85a",
"type": "function",
"z": "d1cc3ace.5b5638",
"name": "event type beacon",
"func": "var event = msg.payload[\"events\"][0];\nif(event[\"type\"] == \"beacon\"){\n \n\nvar hwid = event[\"beacon\"][\"hwid\"];\nvar btype = event[\"beacon\"][\"type\"];\nvar uid = event[\"source\"][\"userId\"];\n\nconst dm = `${Buffer.from(event[\"beacon\"][\"dm\"] || '', 'hex').toString('utf8')}`;\nmsg.dm = dm;\nmsg.btype = btype;\nmsg.uid = uid;\nmessage = \"คุณค้นพบ [\"+btype+\"]\"+ hwid+\">\"+dm+\"{\"+uid+\"}\";\nvar replyToken = event[\"replyToken\"];\nvar replyMessage = {\"type\": \"text\", \"text\": message}\nmsg.payload = {\"messages\": [replyMessage], \"replyToken\": replyToken};\nmsg.headers ={ \"Content-Type\": \"application/json\", \"Authorization\": \"Bearer UAUhWiqKAQE75xUjF5HvkBmctcOHS6cw0R+HnigweWhbH6/dPAqyU+msRtcT4alitYL+xMkQubnqvAHeHWf83HZ1+/jAU3w5KQfvm5zJXgMXlzJUU1ikam92ewBFfOGopNYucVZ+0Bn7K8rpSGxF8AdB04t89/1O/w1cDnyilFU=\"};\n\nreturn msg;\n}",
"outputs": 1,
"noerr": 0,
"x": 304,
"y": 299,
"wires": [
[
"5a8605a1.bd4b4c",
"1744b4c.598c74b",
"117f0f11.e007c1"
]
]
},
{
"id": "5a8605a1.bd4b4c",
"type": "http request",
"z": "d1cc3ace.5b5638",
"name": "LINE REPLY API",
"method": "POST",
"ret": "txt",
"url": "https://api.line.me/v2/bot/message/reply",
"tls": "",
"x": 555,
"y": 323,
"wires": [
[
"58fa7566.44eb6c"
]
]
},
{
"id": "93129dc8.a1de8",
"type": "mqtt out",
"z": "d1cc3ace.5b5638",
"name": "",
"topic": "YMC2018/data",
"qos": "0",
"retain": "",
"broker": "3faed9e7.73bbe6",
"x": 739.5,
"y": 406,
"wires": []
},
{
"id": "1744b4c.598c74b",
"type": "function",
"z": "d1cc3ace.5b5638",
"name": "beacon HOME action",
"func": "var dm = msg.dm;\nvar btype = msg.btype;\nif(dm.indexOf(\"HOME\") >-1 ){\n if(btype ==\"enter\"){\n msg.mqtt_msg = \"1\";\n var replyMessage = {\"type\": \"text\", \"text\": \"ยินดีต้อนรับกลับค่ะ นายท่าน\"}\n msg.payload = {\"messages\": [replyMessage], \"to\": msg.uid};\nmsg.headers ={ \"Content-Type\": \"application/json\", \"Authorization\": \"Bearer UAUhWiqKAQE75xUjF5HvkBmctcOHS6cw0R+HnigweWhbH6/dPAqyU+msRtcT4alitYL+xMkQubnqvAHeHWf83HZ1+/jAU3w5KQfvm5zJXgMXlzJUU1ikam92ewBFfOGopNYucVZ+0Bn7K8rpSGxF8AdB04t89/1O/w1cDnyilFU=\"};\n\n return msg;\n }else if(btype ==\"leave\"){\n msg.mqtt_msg = \"0\";\n var replyMessage = {\"type\": \"text\", \"text\": \"เดินทางปลอดภัยนะคะ นายท่าน\"}\n msg.payload = {\"messages\": [replyMessage], \"to\": msg.uid};\nmsg.headers ={ \"Content-Type\": \"application/json\", \"Authorization\": \"Bearer UAUhWiqKAQE75xUjF5HvkBmctcOHS6cw0R+HnigweWhbH6/dPAqyU+msRtcT4alitYL+xMkQubnqvAHeHWf83HZ1+/jAU3w5KQfvm5zJXgMXlzJUU1ikam92ewBFfOGopNYucVZ+0Bn7K8rpSGxF8AdB04t89/1O/w1cDnyilFU=\"};\n\n return msg;\n }\n \n}",
"outputs": 1,
"noerr": 0,
"x": 326.5,
"y": 382,
"wires": [
[
"3c875699.2f470a",
"5fb79d2e.683844"
]
]
},
{
"id": "3c875699.2f470a",
"type": "http request",
"z": "d1cc3ace.5b5638",
"name": "LINE PUSH API",
"method": "POST",
"ret": "txt",
"url": "https://api.line.me/v2/bot/message/push",
"tls": "",
"x": 548,
"y": 357,
"wires": [
[
"58fa7566.44eb6c"
]
]
},
{
"id": "fc9e5b43.802a48",
"type": "mysql",
"z": "d1cc3ace.5b5638",
"mydb": "37a4ef55.e02d8",
"name": "ymc_db",
"x": 584,
"y": 466,
"wires": [
[
"58fa7566.44eb6c"
]
]
},
{
"id": "117f0f11.e007c1",
"type": "function",
"z": "d1cc3ace.5b5638",
"name": "บันทึกประวัติ user ที่ผ่าน beacon ",
"func": "var dm = msg.dm;\nvar btype = msg.btype;\nvar uid = msg.uid;\nif(dm.indexOf(\"YMC2018\") >-1 ){\n \n msg.mqtt_msg = \"1\";\n var name = msg.payload.name;\n var number = msg.payload.number;\n msg.topic = \"INSERT INTO beacon(dm,uid)values('\"+dm+\"','\"+uid+\"')\";\n return msg;\n \n}\n\n\n",
"outputs": 1,
"noerr": 0,
"x": 344,
"y": 467,
"wires": [
[
"fc9e5b43.802a48"
]
]
},
{
"id": "5fb79d2e.683844",
"type": "function",
"z": "d1cc3ace.5b5638",
"name": "mqtt send",
"func": "msg.payload = msg.mqtt_msg;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 537.5,
"y": 411,
"wires": [
[
"93129dc8.a1de8"
]
]
},
{
"id": "3f55eec0.e569e2",
"type": "mqtt in",
"z": "d1cc3ace.5b5638",
"name": "",
"topic": "YMC2018/data",
"qos": "0",
"broker": "873e3630.a894e8",
"x": 599.5,
"y": 535,
"wires": [
[
"58fa7566.44eb6c"
]
]
},
{
"id": "3faed9e7.73bbe6",
"type": "mqtt-broker",
"z": "",
"broker": "iot.eclipse.org",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": ""
},
{
"id": "37a4ef55.e02d8",
"type": "MySQLdatabase",
"z": "",
"host": "127.0.0.1",
"port": "3306",
"db": "ymc2018",
"tz": ""
},
{
"id": "873e3630.a894e8",
"type": "mqtt-broker",
"z": "",
"name": "eclipse",
"broker": "iot.eclipse.org",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
}
]

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

แจ้งเตือนเข้าไลน์กลุ่ม ผ่าน Line notify เมื่อมีคน login เข้า server ของเราผ่าน SSH (linux) หรือ remote desktop เข้ามา (windows server)

การทำ cloud iot ด้วย thingsboard ไว้ใช้เองครับ

การประยุกต์ใช้ line notify ในการแจ้งปัญหาการใช้งาน สำหรับ php