-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.py
113 lines (46 loc) · 1.75 KB
/
post.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from pyfcm import FCMNotification
import time
from grovepi import *
from grove_rgb_lcd import *
import RPi.GPIO as GPIO
pin=18
led=24
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin,GPIO.OUT)
GPIO.setup(led,GPIO.IN)
p=GPIO.PWM(pin,50)
p.start(0)
cnt=0
push_service = FCMNotification(api_key="AAAAqPYubo0:APA91bGV1-EbpRxxa1KmLfVx-Cm0gbU7wxnRDhXn52DeUqxoG3iML4KMcfnl670n234HbCbEn3gnLTtnoD63VZbbl3ZXwIrOHw80Hfs6LSu5b_ptttnJmKUqhDmD2PXzMibyzU3bJ7oD")
GPIO.setup(led,GPIO.OUT)
buzzer_pin=6
ultrasonic_ranger=8
pinMode(buzzer_pin,"OUTPUT")
time.sleep(1)
while True:
try:
distant = ultrasonicRead(ultrasonic_ranger)
inputled=GPIO.input(24)
if inputled==True:
p.ChangeDutyCycle(9)
if distant > 4:
digitalWrite(buzzer_pin,1)
print(distant)
registration_id = "eJNp6RtzX3E:APA91bGNn48DONuHecmg0J_UN7BVvP6ubuyKKg-PxiI7Ihb9377ZAWxDcMXPaqqfXQGhod8ZL3hhO-Im9f_RnsvokJktKArsvIpPta1Yhbf7QSraQvsi2Gt-U5LLIDbKjqrX078DjLZo"
message_title = "Smart PostBox Service"
message_body = "Smart PostBox open! Please Check Camera Streaming!"
result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title, message_body=message_body)
else:
digitalWrite(buzzer_pin,0)
print(distant)
else:
p.ChangeDutyCycle(5)
digitalWrite(buzzer_pin,0)
except KeyboardInterrupt:
GPIO.output(led,GPIO.LOW)
digitalWrite(buzzer_pin,0)
break
except IOError:
print("Error")
p.stop()
GPIO.cleanup()