This repository was archived by the owner on Sep 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLaundro.py
More file actions
executable file
·69 lines (57 loc) · 1.95 KB
/
Laundro.py
File metadata and controls
executable file
·69 lines (57 loc) · 1.95 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import requests
import datetime
import math
import time
import board
import busio
import adafruit_ads1x15.ads1015 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
import json
MACHINE_COUNT = 1
MACHINE_THRESHOLD = [3.0] * MACHINE_COUNT
machine_status = [False] * MACHINE_COUNT
# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
# Create the ADC object using the I2C bus
ads = ADS.ADS1015(i2c)
# Create single-ended input on channel 0
chan = []
chan.append( AnalogIn(ads, ADS.P0) )
# Create differential input between channel 0 and 1
#chan = AnalogIn(ads, ADS.P0, ADS.P1)
#machines = list(MACHINE_COUNT)
# print("{:>5}\t{:>5}".format('raw', 'v'))
def available(): #boolean
ave_val = monitor_average() #ave volt over 10s
should_update_server = True # change later
for j in range(MACHINE_COUNT):
new_status = ave_val[j] > MACHINE_THRESHOLD[j]
if new_status != machine_status[j]:
should_update_server = True
machine_status[j] = new_status
if should_update_server:
out = {}
for j in range(MACHINE_COUNT):
out['hello'+str(j)] = {'minsleft':'god knows', 'available':machine_status[j],'intensity':ave_val[j]}
out_json = json.dumps(out)
with open('data.json', 'w') as outfile:
json.dump(out_json, outfile)
print(out_json) #will be pushed
else:
print('static')
print('end of monitoring')
def createDict():
ndict = {}
for j in range(MACHINE_COUNT):
ndict['hello'+str(j)] = {'minsleft':'god knows', 'available':machine_status[j]}
return ndict
def monitor_average():
lst = [0.0]*MACHINE_COUNT
for i in range(20):
for j in range(MACHINE_COUNT):
# chan.value
lst[j] = lst[j] + (chan[j].voltage) * 0.1
time.sleep(0.5/MACHINE_COUNT)
return lst
while True:
valueToBePushed = available()