socket_receive()
The receive function will retrieve data that is sent to the sensor node from the socket server. There are several different methods that can be used to pull data from the socket, but the one that we are going to use is recv. The recv method allows us to specify how many bytes of data we want to pull from the socket before processing it. This is more of a maximum number than a minimum. The data in the socket is received as a string. We want to take that string and convert it into a JSON dictionary that can then be parsed. We do this by using the ujson.loads method.
There is something important to understand about our socket_receive function. The function is going to be running as a task through uasyncio. This means that after ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access