執行畫面 127.0.0.1:1880/UI
1) 設定 On LED , Off LED
設定 payload : Light-emitting diode on 與 Light-emitting diode off
2) 設定 audio out 讓 LED 設定的 payload Light-emitting diode on 與 Light-emitting diode off 能說出來
MQTT Server : broker.mqtt-dashboard.com:1883
Topic : alex9ufo/led/led_event
4) 設定 dashboard Text
5) 取得 Line Notify 的 發行權杖 使得LEN ON , LED OFF 狀態可以隨時由手機APP LINE取得資訊
LINE結果 畫面
進入 發行權杖
指定 名稱 與 要Line通知的人 或 群組
將發行權杖 複製
檢視一下 發行的權杖是否active
6) LINE 通知 的方法1
將剛才設定的 放入Name 與 Access Token 中
手機Line Notify 會送出 HEllo! LED Change 與一個貼圖
7) LINE 通知 的方法2
設定2個function
function1
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
if(h<10){
h = '0'+h;
}
if(m<10){
m = '0' + m;
}
if(s<10){
s = '0' + s;
}
msg.payload = msg.payload + ' --> Time:(' + h + ':' + m + ':' + s + ')' ;
return msg;
function 2
發行權杖 放入 Authorization':'Bearer 後面
A4wwPNh2WqB723dlfeQyyIAwtggn1kfZSI5LkkCdia1gB'};
msg.headers = {'content-type':'application/x-www-form-urlencoded','Authorization':'Bearer A4wwPNh2WqB723dlfeQyyIAwtggn1kfZSI5LkkCdia1gB'};
msg.payload = {"message":msg.payload};
return msg;
//oR7KdXvK1eob33Rr2sRRgsl4PMq23DjDlhfUs96SyUBZu
設定Htpp Request
Request 方法 :POST
URL : https://notify-api.line.me/api/notify
8) 整個 程式碼
[{"id":"7377d363.84128c","type":"tab","label":"MQTT_LED","disabled":false,"info":""},{"id":"9a9808d2.b904e8","type":"mqtt in","z":"7377d363.84128c","name":"","topic":"alex9ufo/led/led_event","qos":"1","datatype":"auto","broker":"841df58d.ee5e98","x":140,"y":100,"wires":[["ff64ce35.d54d6","cc43c13c.49236","bd66ced7.e745b","7b270a19.2bfba4"]]},{"id":"ff64ce35.d54d6","type":"ui_text","z":"7377d363.84128c","group":"6c9116b.b62d4e8","order":0,"width":0,"height":0,"name":"","label":"MQTT Suscribe Data","format":"{{msg.payload}}","layout":"col-center","x":400,"y":100,"wires":[]},{"id":"e10b330a.0e832","type":"ui_button","z":"7377d363.84128c","name":"","group":"6c9116b.b62d4e8","order":0,"width":0,"height":0,"passthru":false,"label":"On led","tooltip":"","color":"white","bgcolor":"","icon":"fa-circle","payload":"Light-emitting diode on","payloadType":"str","topic":"","x":110,"y":300,"wires":[["a4db0e32.936f8","6d69def.f1acb2"]]},{"id":"5ccc4685.ea9d18","type":"ui_button","z":"7377d363.84128c","name":"","group":"6c9116b.b62d4e8","order":0,"width":0,"height":0,"passthru":false,"label":"Off led","tooltip":"","color":"black","bgcolor":"","icon":"fa-circle-o","payload":"Light-emitting diode off","payloadType":"str","topic":"","x":110,"y":360,"wires":[["a4db0e32.936f8","6d69def.f1acb2"]]},{"id":"a4db0e32.936f8","type":"mqtt out","z":"7377d363.84128c","name":"","topic":"alex9ufo/led/led_event","qos":"1","retain":"false","broker":"841df58d.ee5e98","x":360,"y":300,"wires":[]},{"id":"6d69def.f1acb2","type":"ui_audio","z":"7377d363.84128c","name":"","group":"6c9116b.b62d4e8","voice":"zh-TW","always":"","x":320,"y":360,"wires":[]},{"id":"cc43c13c.49236","type":"function","z":"7377d363.84128c","name":"Format timestamp","func":"var date = new Date();\nvar h = date.getHours();\nvar m = date.getMinutes();\nvar s = date.getSeconds();\nif(h<10){\n h = '0'+h;\n}\nif(m<10){\n m = '0' + m;\n}\nif(s<10){\n s = '0' + s;\n}\nmsg.payload = msg.payload + ' --> Time:(' + h + ':' + m + ':' + s + ')' ;\n\nreturn msg;","outputs":1,"noerr":0,"x":190,"y":240,"wires":[["d3901e4c.e507d"]]},{"id":"d3901e4c.e507d","type":"function","z":"7377d363.84128c","name":"Set Line API ","func":"msg.headers = {'content-type':'application/x-www-form-urlencoded','Authorization':'Bearer A4wwPNh2WqB7dlfeQyyIAwtggn1kfZSI5LkkCdia1gB'};\nmsg.payload = {\"message\":msg.payload};\nreturn msg;\n\n//oR7KdXvK1eobRr2sRRgsl4PMq23DjDlhfUs96SyUBZu","outputs":1,"noerr":0,"x":370,"y":240,"wires":[["2d2f8066.cb721"]]},{"id":"2d2f8066.cb721","type":"http request","z":"7377d363.84128c","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","authType":"","x":540,"y":240,"wires":[["6085953d.1462ec"]]},{"id":"6085953d.1462ec","type":"debug","z":"7377d363.84128c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":240,"wires":[]},{"id":"bd66ced7.e745b","type":"debug","z":"7377d363.84128c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":370,"y":60,"wires":[]},{"id":"7b270a19.2bfba4","type":"line-notify","z":"7377d363.84128c","name":"NODE-RED MQTT LED","message":"Hello! \nLED Changed","contentType":"sticker","imageUrl":"","stickerPackageId":"1","stickerId":"2","x":410,"y":160,"wires":[]},{"id":"841df58d.ee5e98","type":"mqtt-broker","z":"","name":"","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"6c9116b.b62d4e8","type":"ui_group","z":"","name":"LED","tab":"28920cc.c23e2f4","order":1,"disp":true,"width":"6","collapse":false},{"id":"28920cc.c23e2f4","type":"ui_tab","z":"","name":"MQTT_LED","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
沒有留言:
張貼留言