forked from aru949/Appliance_scheduling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_sender.py
36 lines (28 loc) · 1.17 KB
/
data_sender.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
"""
@author : Jeevesh Juneja
(https://github.com/Jeevesh8/)
"""
from Adafruit_IO import Client, Feed, Data, RequestError
import device_feed_map as dfm
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--feed_no', help='Feed number to which to send data')
parser.add_argument('--onoff_lis', nargs = '*', help='0 for switching off, 1 for switching on; list of states of all devices on feed_no')
parser.add_argument('--time', help='UNIX timestamp for swithcing time')
args=parser.parse_args()
ADAFRUIT_IO_USERNAME = input('Adafruit-io-username :')
ADAFRUIT_IO_KEY = input('Adafruit-io-key :')
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
def send(feed_no=args.feed_no, onoff_lis=args.onoff_lis, time=args.time, device_states=dfm.initial_device_states) :
try :
feed = aio.feeds(feed_no)
except RequestError :
new_feed = Feed(name=feed_no)
feed = aio.create_feed(new_feed)
onoff_string = ''
for elem in onoff_lis :
onoff_string = onoff_string+','+str(elem)
packet = args.time+','+ onoff_string
aio.send_data(feed.key, packet)
#if(success)
dfm.write_files(initial_device_states=device_states)