Pi : Pi moition camera notification Line Nofity API
ติดตั้ง motion
https://intranet.sci.com/blog.php?u=281&b=1667
เพิ่มเติม แก้ Motion ให้ไปเรียกใช้งาน ไฟล์ python ที่สร้างขึ้นเมื่อมีการสร้าง Video
- nana /etc/motion/motion.conf
แก้ตรง
on_movie_start python3 /home/pi/line.py
Code pyton ส่ง Line
http://intranet.sci.com/blog.php?u=281&b=1809
Code สำเร็จ
- import requests, json
- import urllib.parse
- import sys
- import glob
- import os
- import time
- LINE_ACCESS_TOKEN = "XXXXXXX"
- URL_LINE = "https://notify-api.line.me/api/notify"
- def line_text(message):
- msg = urllib.parse.urlencode({"message":message})
- LINE_HEADERS = {'Content-Type':'application/x-www-form-urlencoded',"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
- session = requests.Session()
- session_post = session.post(URL_LINE, headers=LINE_HEADERS, data=msg)
- print(session_post.text)
- def line_pic(message, path_file):
- file_img = {'imageFile': open(path_file, 'rb')}
- msg = ({'message': message})
- LINE_HEADERS = {"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
- session = requests.Session()
- session_post = session.post(URL_LINE, headers=LINE_HEADERS, files=file_img, data=msg)
- print(session_post.text)
- list_of_files = glob.glob('/home/pi/Monitor/*.jpg')
- latest_file = max(list_of_files, key=os.path.getctime)
- #print(latest_file)
- text_send = "Motion Detect OD."
- line_pic(text_send, latest_file)
- #//// Delete All File In Folder Monitor ////#
- parth = "/home/pi/Monitor/"
- for i in os.listdir ( parth ):
- os.remove(parth+i)
No comments:
Post a Comment