Commit 2e9dec82 authored by schneider's avatar schneider
Browse files

iaq: better error handling

parent c63eaa95
Pipeline #5456 failed with stages
in 53 seconds
......@@ -29,6 +29,7 @@ a = mgr.get_adapter()
devices=a.get_devices('0000181a-0000-1000-8000-00805f9b34fb')
if len(devices)>1:
device=None
print("Mutiple devices found:")
for d in devices:
print("-", d.Name, d.Address, end=" ")
......@@ -49,8 +50,11 @@ else:
print("No capable device found")
sys.exit(1)
#print('Device:', device)
device.connect()
try:
device.connect()
except Exception as e:
print('Could not connect to %s: %s'%(device.Address,str(e)))
sys.exit(1)
services = device.get_gattservices()
......@@ -99,27 +103,32 @@ else:
post=None
while True:
if args.influx is not None:
post={}
try:
while True:
if args.influx is not None:
post={}
ready,_,_ = select.select(fds,[],[])
ready,_,_ = select.select(fds,[],[])
for fd in ready:
ble_data=os.read(fd, 100) #read max 100 characters
if len(ble_data)==0:
raise ConnectionResetError("BLE disconnect")
parse=mapping[fd](ble_data)
if args.influx is not None:
post.update(parse)
else:
print("notify:", parse)
for fd in ready:
ble_data=os.read(fd, 100) #read max 100 characters
parse=mapping[fd](ble_data)
if args.influx is not None:
post.update(parse)
else:
print("notify:", parse)
line=" ".join(["air",",".join([k+"="+str(v) for k,v in post.items()])])
if args.verbose:
print(line)
r = requests.post(args.influx, data=line)
if r.status_code != 204:
print(r.status_code, r.reason)
if args.influx is not None:
line=" ".join(["air",",".join([k+"="+str(v) for k,v in post.items()])])
if args.verbose:
print(line)
r = requests.post(args.influx, data=line)
if r.status_code != 204:
print(r.status_code, r.reason)
except(KeyboardInterrupt, ConnectionResetError) as e:
print(str(e))
#device.disconnect()
print('Exit')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment