forked from RichardHabeeb/InsecureBuildingAutomationSystem
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsensor.py
50 lines (35 loc) · 1.49 KB
/
sensor.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
################################################################################
# Tempurature Sensor
################################################################################
################################################################################
# IMPORTS
################################################################################
import time
import json
import socket
import bmp180
################################################################################
# CLASSES
################################################################################
################################################################################
# VARIABLES
################################################################################
################################################################################
# FUNCTIONS
################################################################################
################################################################################
# MAIN
################################################################################
def main():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
while True:
time.sleep(1)
temp, presure = bmp180.readBmp180()
data = {
'currentTemp': temp
}
#Publish temp data to the network
sock.sendto(json.dumps(data), ("192.168.0.255", 4444))
if __name__ == "__main__":
main()