Skip to content

Commit 198902f

Browse files
committed
Thanks @giampaolo Mancini: only one call is available per RpcClient instance
1 parent 599fb8e commit 198902f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

python-rpc-sensors/python/main.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
m4_proxy_host = 'm4-proxy'
99
m4_proxy_call_port = 5001
1010

11-
def get_data_from_m4(rpc_client):
11+
def get_data_from_m4(rpc_address):
1212
"""Get data from the M4 via RPC (MessagePack-RPC)
1313
1414
The Arduino sketch on the M4 must implement the following methods
@@ -20,17 +20,18 @@ def get_data_from_m4(rpc_client):
2020
* `gas`
2121
* `altitude`
2222
23+
WARNING: due to a known issue with msgpackrpc library, we can only
24+
make a single call after RpcClient. If we need to make multiple calls,
25+
we need to create a new RpcClient instance for each call.
26+
2327
"""
2428
data = ()
2529
try:
26-
temperature = rpc_client.call('temperature')
27-
humidity = rpc_client.call('humidity')
28-
pressure = rpc_client.call('pressure')
29-
gas = rpc_client.call('gas')
30-
altitude = rpc_client.call('altitude')
31-
data = temperature, humidity, pressure, gas, altitude
30+
get_value = lambda value: RpcClient(rpc_address).call(value)
31+
data = tuple(get_value(measure) for measure in sensors)
32+
3233
except RpcError.TimeoutError:
33-
print("Unable to retrive data from the M4.")
34+
print("Unable to retrieve data from the M4.")
3435
return data
3536

3637
if __name__ == '__main__':

0 commit comments

Comments
 (0)