-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzerobutton3.py
More file actions
52 lines (40 loc) · 1.6 KB
/
zerobutton3.py
File metadata and controls
52 lines (40 loc) · 1.6 KB
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
#button press will send to api end point, 10 sec hold will shut down
#todo, connect to wifi, double/tripple clicks
from gpiozero import Button
from gpiozero import LED
from gpiozero import PWMLED
from subprocess import check_call
from signal import pause
import time
import requests
import datetime
import json as simplejson
# api-endpoint
url = "<ENTER END POINT>"
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
#startup
led = PWMLED(17)
now = datetime.datetime.now()
timestamp = now.strftime('%Y-%m-%dT%H:%M:%S') + ('-%02d' % (now.microsecond / 10000))
data = {'id': 'meeseeks001', 'datetime': timestamp, 'message': 'Meeseeks Box On'}
requests.post(url, data=simplejson.dumps(data), headers=headers)
led.pulse(n=2, background=False)
led.value = 1
def send_logicapp():
led.blink(on_time=.1, off_time=.1,n=1,background=False)
led.value = 1
# get timestamp
now = datetime.datetime.now()
timestamp = now.strftime('%Y-%m-%dT%H:%M:%S') + ('-%02d' % (now.microsecond / 10000))
data = {'id': 'meeseeks001', 'datetime': timestamp, 'message': 'Button Push'}
requests.post(url, data=simplejson.dumps(data), headers=headers)
print("LogicApp Request Sent! : " + timestamp)
def shutdown():
# get timestamp
now = datetime.datetime.now()
timestamp = now.strftime('%Y-%m-%dT%H:%M:%S') + ('-%02d' % (now.microsecond / 10000))
data = {'id': 'meeseeks001', 'datetime': timestamp, 'message': 'Button Shutdown'}
requests.post(url, data=simplejson.dumps(data), headers=headers)
led.pulse(n=3, background=False)
check_call(['sudo', 'poweroff'])
def push_button():