Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
card10
firmware
Commits
a4d553b5
Commit
a4d553b5
authored
Jan 02, 2022
by
schneider
Browse files
iaq: better error handling
parent
c63eaa95
Pipeline
#5457
failed with stages
in 54 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tools/iaq/card10_iaq_notify.py
View file @
a4d553b5
...
...
@@ -27,11 +27,17 @@ a = mgr.get_adapter()
# Get devices which support environmental sensing
devices
=
a
.
get_devices
(
'0000181a-0000-1000-8000-00805f9b34fb'
)
devices
=
a
.
get_devices
()
if
len
(
devices
)
>
1
:
device
=
None
print
(
"Mutiple devices found:"
)
for
d
in
devices
:
print
(
"-"
,
d
.
Name
,
d
.
Address
,
end
=
" "
)
try
:
device_name
=
d
.
Name
except
AttributeError
:
device_name
=
"<none>"
print
(
"-"
,
device_name
,
d
.
Address
,
end
=
" "
)
if
d
.
Address
==
args
.
mac
:
print
(
"(selected)"
)
...
...
@@ -49,8 +55,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 +108,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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment