summaryrefslogtreecommitdiff
path: root/si7021d
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-11-12 15:12:51 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-11-12 15:12:51 +0300
commit93986d97672f2a7bbfd11929ad8f5c7dc7181b5a (patch)
treebd1d90fc68e6000a0964aca118e8aeed8727c21c /si7021d
parent585a130ecd828b03cf06ae1cfbedac49ad01e7ec (diff)
add timeout while waiting for i2c calls
Diffstat (limited to 'si7021d')
-rw-r--r--si7021d8
1 files changed, 6 insertions, 2 deletions
diff --git a/si7021d b/si7021d
index 123fc39..2a1e6c6 100644
--- a/si7021d
+++ b/si7021d
@@ -38,8 +38,12 @@ async def handle_client(reader, writer):
break
if request == 'read':
- rh, temp = await si7021_read()
- data = dict(humidity=rh, temp=temp)
+ try:
+ rh, temp = await asyncio.wait_for(si7021_read(), timeout=3)
+ data = dict(humidity=rh, temp=temp)
+ except asyncio.TimeoutError as e:
+ logger.exception(e)
+ data = dict(error='i2c call timed out')
else:
data = dict(error='invalid request')