Pi : Pi moition camera notification Line Nofity API
ติดตั้ง motion
https://porpramarn.blogspot.com/2019/02/pi-pi-camera-motion.html
เพิ่มเติม แก้ Motion ให้ไปเรียกใช้งาน ไฟล์ python ที่สร้างขึ้นเมื่อมีการสร้าง Video
- nana /etc/motion/motion.conf
on_movie_start python3 /home/pi/line.py
Code python ส่ง Line
https://porpramarn.blogspot.com/2020/09/line-python-line-api-notify.html
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