tinytuya: "[Errno 98] Address already in use" occurs when two clients calls tinytuya.OutletDevice() with address="Auto"

Hello,

Thank you for providing the great software.

Today, I found a problem. I’m using tinytuya version 1.12.9 with Python 3.9.11.

So far, I was running a client with the following call:

d = tinytuya.OutletDevice(
    dev_id="xxxxxxxx",
    address="Auto",  # Or set to 'Auto' to auto-discover the IP address
    local_key="yyyyyyyy",
    version=3.3,
)

When I was running one client, it was working fine.

However, today, I added another client using the same approach. After that, both clients started to cause the error very frequently.

[Errno 98] Address already in use

I have two DHCP servers on my network, so the Tuya devices’ IP address may change. Therefore, I preferred the “Auto” configuration.

In addition, my client tries to call tinytuya.OutletDevice() to query new data every minute.

Is this idea bad? What are your recommendations or best practices when:

  • Due to two DHCP servers, Tuya devices’ addresses may change. So I want to use “Auto” for tinytuya.OutletDevice().
  • To avoid disconnection, I want to establish a connection whenever new data should be queried.

Any suggestions would be appreciated.

Regards, Atsushi

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 17 (2 by maintainers)

Most upvoted comments

Nice @yokoyama-flogics ! Thanks for sharing the code and dashboard JSON!

I’m a big fan of Grafana dashboards as well as you can see from my other project, Powerwall-Dashboard. I like your use of ES… makes sense.

@jasonacox,

Of course! I have placed the code below:

The Python code stores data in Elasticsearch (Tuya device reconnection has not been implemented yet). It also publishes to the MQTT broker, though I’m not currently using it for anything specific.

On the other hand, the JSON file is an export from the Grafana dashboard that I created.

Regards, Atsushi

Hi @uzlonewolf,

OK, I understand that it is acceptable to use status() in this case.

By the way, my application is calling status() every 20 seconds (not actually every 10 seconds). It measures the power consumption of an air conditioner, and I’m getting the following results. Since the power consumption of the air conditioner changes frequently, I believe that measuring it every 20 or 30 seconds is necessary to monitor it precisely.

Visualization by Grafana

In any case, thank you for your answers. I’ll consider this topic closed.

Regards, Atsushi