suaveolent / hoymiles-wifi

Library to communicate with Hoymiles DTUs and HMS-XXXXW-2T microinverters via protobuf.
MIT License
49 stars 9 forks source link

Two WLAN-Devices and two HMS-800W-2T on one Raspi #27 #28

Open Jo-Bl opened 2 weeks ago

Jo-Bl commented 2 weeks ago
          Thanks.

But sorry, this doesn't work. Independent from the setting at "--local_addr" it requests server every time on wlan1 (10.10.100.151 -> 10.10.100.254) but sadly never wlan0 (10.10.100.150 -> 10.10.100.254)

Not working (wlan0, requests wlan1 instead): ./hoymiles-wifi --host 10.10.100.254 --local_addr 10.10.100.150 --as-json get-real-data-new

working (wlan1); ./hoymiles-wifi --host 10.10.100.254 --local_addr 10.10.100.151 --as-json get-real-data-new

Originally posted by @Jo-Bl in https://github.com/suaveolent/hoymiles-wifi/issues/27#issuecomment-2345712890

suaveolent commented 2 weeks ago

Thanks for the feedback. That is weird indeed.

What about if you enter a non existend interface, e.g. 10.10.100.149? To you still get a response?

Jo-Bl commented 1 week ago

I'm only seeing your answer now, sorry.

I'm now using the two HMS-800W-2Ts with two Rasps.

But I was able to test it with only wlan0 and eth0 interfaces, if I remember correctly: Then no data query is possible with an incorrect IP. But if wlan0 and wlan1 are present, then a query with an incorrect IP is possible. As I said: I can't test that at the moment because I'm now working with two Rasps. Sorry.

RaspiOS is bookworm (12.x) 32bit. Network is handled within bookworm with "networkmanager" not as in versions before with wpa_supplicant

suaveolent commented 1 week ago

Thanks for letting me know.

by the way: you can also connect the inverter directly to your WiFi router. So you can query both inverters with one raspberry too.

Jo-Bl commented 1 week ago

You wrote:

you can also connect the inverter directly to your WiFi router

Aha, how?

I do not found an option about that 'connecting to my router' in the android app "S-Miles Installer" (, which I only used once per inverter to change the password).

My conditions are:

Is this possible than, if the inverters are connected to the router?

In the moment (if I use AP mode of the inverters) I'm the boss ;-)

But what is if the inverters are connected to the router? (Disallowing inverters an outgoing connection in the router configuration, may disturbing the inverters in this case is my fear). By the way: I do not have an account at hoymiles and I will never set up one.

And about the '(nearly)' we discuss here...

Thank you for discussing it and thanks for software and support!

One remark: At the moment I use two raspis for the two inverters and everything works well.

suaveolent commented 1 week ago

You can set the wifi network of the inverter via the set-wifi command. This allows you to connect the inverter to your main wifi. Then you can use the IP address from the main router to query your inverters as before.

To prevent the inverter from communicating with hoymiles servers you need to create a firewall rule in your router. I have set up my inverter this way.

The only issue which arises from this setup is that the inverter sometimes is not reachable (presumably due to it trying to connect to the Hoymiles server at this time).

Also bear in mind: There might be some wifi stability issues if you have never update the firmware up until now (I'm working on an offline approach to do so, but it does not work as of this moment).

Jo-Bl commented 1 week ago

You wrote:

You can set the wifi network of the inverter via the set-wifi command.

I know that (thanks for implement this), but I don't want it.

Reasons (as you wrote):

To prevent the inverter from communicating with hoymiles servers you need to create a firewall rule in your router.

The only issue which arises from this setup is that the inverter sometimes is not reachable (presumably due to it trying to connect to the Hoymiles server at this time).

*)

There might be some wifi stability issues if you have never update the firmware up until now

So I preferr AP mode and will stay on this mode for both inverters.

You wrote:

(I'm working on an offline approach to do so, but it does not work as of this moment).

Thanks for this!

*) This is an issue same in AP mode, which I do not understand completely

suaveolent commented 1 week ago

I see makes sense :)

There are two reasons for the disconnects:

  1. old firmware is buggy. You need to update to the latest firmware to improve WiFi stability
  2. Offline mode, as described above.
Jo-Bl commented 1 week ago

2024-09-15T12:48:29|get-real-data-new|No response or unable to retrieve ) 2024-09-15T12:49:23|get-real-data-new|{"deviceSerialNumber":.... 2024-09-15T12:50:11|get-real-data-new|{"deviceSerialNumber":... 2024-09-15T12:50:58|get-real-data-new|{"deviceSerialNumber":.... 2024-09-15T12:51:45|get-real-data-new|No response or unable to retrieve ) 2024-09-15T12:52:37|get-real-data-new|{"deviceSerialNumber":... 2024-09-15T12:53:25|get-real-data-new|{"deviceSerialNumber":.... 2024-09-15T12:54:12|get-real-data-new|{"deviceSerialNumber":.... 2024-09-15T12:55:00|get-real-data-new|No response or unable to retrieve ) 2024-09-15T12:55:53|get-real-data-new|{"deviceSerialNumber":... 2024-09-15T12:56:40|get-real-data-new|{"deviceSerialNumber": 2024-09-15T12:57:28|get-real-data-new|{"deviceSerialNumber": 2024-09-15T12:58:15|get-real-data-new|No response or unable to retrieve ) 2024-09-15T12:59:08|get-real-data-new|{"deviceSerialNumber":...

*) No response or unable to retrieve response for get-real-data-new

suaveolent commented 1 week ago

2024-09-15T12:48:29|get-real-data-new|No response or unable to retrieve response for get-real-data-new 2024-09-15T12:49:23|get-real-data-new|{"deviceSerialNumber":.... 2024-09-15T12:50:11|get-real-data-new|{"deviceSerialNumber":... 2024-09-15T12:50:58|get-real-data-new|{"deviceSerialNumber":.... 2024-09-15T12:51:45|get-real-data-new|No response or unable to retrieve response for get-real-data-new 2024-09-15T12:52:37|get-real-data-new|{"deviceSerialNumber":... 2024-09-15T12:53:25|get-real-data-new|{"deviceSerialNumber":...

That looks a lot like the output I would expect if run in offline mode. So in the end it probably doesn’t really matter if you use AP mode or offline mode.

Jo-Bl commented 1 week ago

Yes, no matter ;-)

But to come back to the original issue ;-): If it is possible to separate wlan0 and wlan1 it will be nice to have to save a raspi.

suaveolent commented 1 week ago

Yes, I’m still investigating. Will probably run some tests on a rpi tomorrow.

Jo-Bl commented 1 week ago

Thank you. Maybe you have to go deep inside 'asyncio' for this?

It is not urgent, because I also have a shelly PMminiGen3 and a shelly Pro3EM for data checking.

Jo-Bl commented 1 week ago

Yes, I’m still investigating. Will probably run some tests on a rpi tomorrow.

A hint about the additional usb wlan stick for testing wlan0 and wlan1 on one raspi: As HMS-800W-2T used 802.11​n, the easiest way is to use a stick, which is nativ supported by RaspiOS: e.g. Edimax Wi-Fi Nano USB Adapter (N150) or TP-Link TL-WN823N, ...

suaveolent commented 1 week ago

@Jo-Bl I begin to wonder whether this is an OS/underlying library issue.

When i was using eth0 and wlan0 I could switch between the interfaces using local_addr just fine. I also verified it setting special firewall rules in my router.

However, as soon as I also connected my Edimax USB adapter and set up wlan1 it would only allow connections via wlan1. When I tried to use the local_addr for eth0 or wlan0 I would not get any response.

According to the documentation, the use of local_addr, however, should be exactly what you are looking for.

suaveolent commented 1 week ago

I am also seeing a lot of these errors, when the edimax is connected:

https://github.com/raspberrypi/linux/issues/6049

Jo-Bl commented 1 week ago

@Jo-Bl I begin to wonder whether this is an OS/underlying library issue.

When i was using eth0 and wlan0 I could switch between the interfaces using local_addr just fine. I also verified it setting special firewall rules in my router.

However, as soon as I also connected my Edimax USB adapter and set up wlan1 it would only allow connections via wlan1. When I tried to use the local_addr for eth0 or wlan0 I would not get any response.

According to the documentation, the use of local_addr, however, should be exactly what you are looking for.

Sorry for not describing the behavior better (I was more interested in the data than in testing and trying it out): It is here nearly as you describe and tested it. Difference: If I use the other connection, I receive not no data, but the data from the same wlan.

According what documentation?

suaveolent commented 1 week ago

Right, I forgot to paste the link to the documentation:

https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.create_connection

Jo-Bl commented 1 week ago

I am also seeing a lot of these errors, when the edimax is connected:

raspberrypi/linux#6049

But it is possible to connect to two different (hoymiles-)APs with wlan0 and wlan1, only to sepatate them via IP does not work. Is there another way to do that? Via 'wlan0' and 'wlan1' or so?

suaveolent commented 1 week ago

Yes, it might be possible by directly creating a socket. However, this approach will only work for Linux based systems. The IP-based approach should look up the interface independet of the OS and select the appropriate interface automatically.

I can try to push an update today with this approach to see if it works.

By the way, just to make sure: I assume you set the IP-adddress manually right? Because the hoymiles begins setting the IP at 10.10.100.150. So if you have two different devices, both of them would try to assign the client the 10.10.100.150 IP.

Jo-Bl commented 1 week ago

First I let it be assigned automatically and that worked very well. (I got .150 from the first inverter and .151 from the second inverter).

When fetching on two interfaces didn't work and you then implemented --local_addr, I also tried with static IPs.

Please note: RaspiOS Bookwork is now based on networkmanager, which is completely different than before.

Jo-Bl commented 1 week ago

You wrote:

The IP-based approach should look up the interface independet of the OS and select the appropriate interface automatically.

Yes, this is like e.g. a linux app 'wol' do it to select the interface to send the magic packet.

On the oher hand 'ssh' selects the interface according the routing table?