-
Notifications
You must be signed in to change notification settings - Fork 0
/
atSchool.py
32 lines (24 loc) · 903 Bytes
/
atSchool.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
# check if Zion is in School
import authentification # password file
import paho.mqtt.client as mqtt
import os
def ping():
response = os.system("ping -c 1 -w 1 %s > /dev/null" % authentification.iphoneSchoolDomain)
response &= os.system("ping -c 1 -w 1 %s > /dev/null" % authentification.ipadSchoolDomain)
response &= os.system("ping -c 1 -w 1 %s > /dev/null" % authentification.macSchoolDomain)
if response == 0:
print("ping success")
else:
print("ping fail")
return response
# publish position section
client = mqtt.Client()
# connect to server
client.username_pw_set(authentification.servername, authentification.serverpassword)
client.connect(authentification.host, authentification.port)
# publish msg
if ping() == 0: # at home
ret = client.publish("school", "y")
else: # not at home
ret = client.publish("school", "n")
client.disconnect()