> On 16 May 2020, at 12:49, Stefano Miccoli via Owfs-developers 
> <owfs-developers@lists.sourceforge.net> wrote:
> 
> The python code could also be improved a little bit, shortly I will post a 
> gist with some corrections.
> 

Please, see at https://gist.github.com/miccoli/5a6fcb400e13a22873863df6d3b48c02 
<https://gist.github.com/miccoli/5a6fcb400e13a22873863df6d3b48c02> for a 
refactored python3 script.

Here my modifications:

- no need to perform °C -> °F conversion explicitly, just query owserver with 
the appropriate flag, see 
https://pyownet.readthedocs.io/en/latest/protocol.html#pyownet.protocol.FLG_TEMP_F
 
<https://pyownet.readthedocs.io/en/latest/protocol.html#pyownet.protocol.FLG_TEMP_F>

- temperature conversion is cached in owserver; since you are reading in a 
tight busy loop, better to use uncached values, and force temperature 
conversion at each read (supposing there is a single process querying the 
owserver)
https://pyownet.readthedocs.io/en/latest/protocol.html#pyownet.protocol.FLG_UNCACHED
 
<https://pyownet.readthedocs.io/en/latest/protocol.html#pyownet.protocol.FLG_UNCACHED>

- since you are in a tight busy loop, use a persistent connection
https://pyownet.readthedocs.io/en/latest/protocol.html#persistent-vs-non-persistent-proxy-objects
 
<https://pyownet.readthedocs.io/en/latest/protocol.html#persistent-vs-non-persistent-proxy-objects>

- better error handling

regards,

Stefano
_______________________________________________
Owfs-developers mailing list
Owfs-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to