-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·53 lines (45 loc) · 1.77 KB
/
test.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
51
52
53
#!/usr/bin/python3
'''test.py April 13, 2021 Larry Priest priestlt@proton.com
Recreating blinka_bridge or adafruit_ble_broadcastnet.py
Going to start from scratchish
'''
from secrets import secrets
import msmts
import requests
# from adafruit_ble import BLERadio
# import adafruit_ble_broadcastnet
def get_existing_feeds(aio_auth_header, aio_base_url, **kwargs):
'''Get the existing feeds from io.adafruit.'''
existing_feeds = {}
kwargs['headers'] = aio_auth_header
response = requests.get(aio_base_url+"/groups", **kwargs)
print('return code: ', response.status_code)
if response.status_code == 200:
for group in response.json():
if "-" not in group['key']:
continue
pieces = group['key'].split("-")
if len(pieces) != 4 or pieces[0] != 'bridge' or (
pieces[2] != "sensor"):
continue
_, bridge, _, sensor_address = pieces
if bridge != 'b827ebdeb6d6': # replace with bridge_address
continue
existing_feeds[sensor_address] = []
for feed in group["feeds"]:
existing_feeds[sensor_address].append(
feed["key"].split(".")[-1])
else:
print('Some error occured!')
return existing_feeds
def main():
# ble_radio = BLERadio()
# bridge_address = adafruit_ble_broadcastnet.device_address
aio_auth_header = {"X-AIO-KEY": secrets["aio_key"]}
aio_base_url = "https://io.adafruit.com/api/v2/" + secrets["aio_username"]
measurements = msmts.measure
# print("This is BroadcastNet bridge: ", bridge_address)
existing_feeds = get_existing_feeds(aio_auth_header, aio_base_url)
print('existing feeds:\n', existing_feeds)
if __name__ == '__main__':
main()