uni-meter icon indicating copy to clipboard operation
uni-meter copied to clipboard

Persistent Outbound connection

Open MuellBin2 opened this issue 1 year ago • 10 comments

Since Version 1.1.1 it is possible to bind devices to the outbound connection. However, Uni-Meter needs a new connection to be set up every time the software is restarted. In contrast, the binding stays active on the connected devices. So it would be possible, after a restart, to automatically start sending the values again.

In praxis, the connected device (APSystems EZHI) needs following steps to reconnect to Uni-Meter after the software has been restarted:

  • delete the old connection
  • reconnect to uni meter
  • name the new connection
  • do a phase detect, where several 800w pulses are sent into the grid (=energy loss)
  • enable intelligent connection again

Instead of an IP adress, the network name could be used to overcome changing IP adresses. The settings should be done in the config file.

MuellBin2 avatar Mar 16 '25 09:03 MuellBin2

Yes, that is a good point. I will add a configuration parameter for the outbound websocket URL within the uni-meter.conf file.

sdeigm avatar Mar 17 '25 07:03 sdeigm

You can now test the persistent outbound connection feature in the uni-meter-1.1.3-SNAPSHOT snapshot version which I have just build. A docker container sdeigm/uni-meter:1.1.3-SNAPSHOT is also available.

The outbound websocket connection is configured like below:

uni-meter {
  
  # ...
  
  output-devices {
    shelly-pro3em {
      # ...
      ws = {
        enabled = true
        server = "ws://localhost:4242/websocket"
        ssl_ca = "*"
      }
    }
  }
}

sdeigm avatar Mar 20 '25 04:03 sdeigm

Okay, this enables the websocket, I get this message on start-up now:

25-03-21 08:50:33.549 ERROR uni-meter.output         - outbound websocket connection to ws://192.168.1.96/meter failed: unexpected response status: 404 Not Found
25-03-21 08:50:33.564 DEBUG uni-meter.output         - incoming websocket connection 2404ce23-74f7-4d6c-a7be-42fa91ce35f6 failed: WebSocket upgrade did not finish because of 'unexpected status code: 404 Not Found'

I tried to put in the host name, with the same result:

25-03-21 08:53:19.628 ERROR uni-meter.output - outbound websocket connection to ws://apsystems/meter failed: unexpected response status: 404 Not Found

MuellBin2 avatar Mar 21 '25 08:03 MuellBin2

Are you sure the Websocket server on the other side is running?

You can test this with this tool https://websocket.tech/

sdeigm avatar Mar 21 '25 09:03 sdeigm

25-03-21 09:22:28.259 DEBUG uni-meter.output         - incoming websocket connection 1facac62-13af-4afa-aa17-c9db376d4090 failed: WebSocket upgrade did not finish because of 'unexpected status code: 404 Not Found'
25-03-21 09:22:28.259 DEBUG uni-meter.output         - outbound websocket connection to ws://192.168.1.96/meter failed: unexpected response status: 404 Not Found
25-03-21 09:22:30.160 DEBUG uni-meter.output         - outgoing websocket connection 0476772a-4ebc-47b5-810a-538e8fa73cfa to /192.168.1.96 created
25-03-21 09:22:30.161 DEBUG uni-meter.output         - incoming websocket connection 0476772a-4ebc-47b5-810a-538e8fa73cfa opened
25-03-21 09:22:30.301 DEBUG uni-meter.output         - incoming websocket connection 0476772a-4ebc-47b5-810a-538e8fa73cfa failed: WebSocket upgrade did not finish because of 'unexpected status code: 404 Not Found'
25-03-21 09:22:30.301 DEBUG uni-meter.output         - outbound websocket connection to ws://192.168.1.96/meter failed: unexpected response status: 404 Not Found
25-03-21 09:22:43.279 DEBUG uni-meter.output         - outgoing websocket connection 71c3a94e-49d3-4843-a6cd-bff3b0152948 to /192.168.1.96 created
25-03-21 09:22:43.280 DEBUG uni-meter.output         - incoming websocket connection 71c3a94e-49d3-4843-a6cd-bff3b0152948 opened
25-03-21 09:22:43.405 DEBUG uni-meter.output         - incoming websocket connection 71c3a94e-49d3-4843-a6cd-bff3b0152948 failed: WebSocket upgrade did not finish because of 'unexpected status code: 404 Not Found'
25-03-21 09:22:43.405 DEBUG uni-meter.output         - outbound websocket connection to ws://192.168.1.96/meter failed: unexpected response status: 404 Not Found
25-03-21 09:22:45.323 DEBUG uni-meter.output         - outgoing websocket connection 25f8fe03-1063-4d64-b9ba-096412de99d5 to /192.168.1.96 created
25-03-21 09:22:45.323 DEBUG uni-meter.output         - incoming websocket connection 25f8fe03-1063-4d64-b9ba-096412de99d5 opened
25-03-21 09:22:45.458 DEBUG uni-meter.output         - incoming websocket connection 25f8fe03-1063-4d64-b9ba-096412de99d5 failed: WebSocket upgrade did not finish because of 'unexpected status code: 404 Not Found'
25-03-21 09:22:45.458 DEBUG uni-meter.output         - outbound websocket connection to ws://192.168.1.96/meter failed: unexpected response status: 404 Not Found

Image

Maybe, APSystem disabled the websocket in their latest firmware. I can't initialize a new connection either. Im gonna revert to 1.1.2 and try again.

MuellBin2 avatar Mar 21 '25 09:03 MuellBin2

Uni-Meter Version 1.1.2 does not work as well anymore.

25-03-21 09:38:41.022 DEBUG uni-meter.output         - outgoing websocket connection f5e55a0d-e943-4f6d-a75a-3334597ff9e4 to /192.168.1.96 created
25-03-21 09:38:41.022 DEBUG uni-meter.output         - incoming websocket connection f5e55a0d-e943-4f6d-a75a-3334597ff9e4 opened
25-03-21 09:38:41.159 DEBUG uni-meter.output         - incoming websocket connection f5e55a0d-e943-4f6d-a75a-3334597ff9e4 failed: WebSocket upgrade did not finish because of 'unexpected status code: 404 Not Found'
25-03-21 09:38:41.159 DEBUG uni-meter.output         - outbound websocket connection to ws://192.168.1.96/meter failed: unexpected response status: 404 Not Found

MuellBin2 avatar Mar 21 '25 09:03 MuellBin2

Hm, I just checked the latest milestones and tickets in them. I don't see any ticket that might cause this. Since you also can not connect to the Websocket server on your EZHI system, did they perhaps change the entire handling of the connection EZHI <-> Shelly? So my local test setup with the uni-meter and a standalone webserver just echoing the notifications from the uni-meter works without any problems.

sdeigm avatar Mar 21 '25 13:03 sdeigm

Yes they did. First they realeased a new app that would only bind using shelly cloud, now the firmware for the apsystems followed that threw out the websocket i think. I dont know if we can integrate uni-meter in the shelly cloud, but anyhow, if the connection is not possible locally in the end this is a bad design.

MuellBin2 avatar Mar 21 '25 14:03 MuellBin2

if the connection is not possible locally in the end this is a bad design.

agree

looks like neither Zendure, Anker nor APSystems provide (currently) the shelly EM local as we would like to have it. I have less hope for Anker that this will change, they even don't support the Shelly plugs. Anker's shelly support is more or less marketing. Hope APsystems will do better.

tmb80c avatar Mar 21 '25 14:03 tmb80c

In the end they somehow just have to look up the IP address of the shelly. I think they all choose the way over the cloud since that's more easy for them and they have less support requests.

Unfortunately the other side of the cloud interface - between the shelly device and the cloud - is not public and documented. If that information would be available it would be easy to announce uni-meter's IP address to the cloud.

If I find some time I will do a little bit research on that ...

sdeigm avatar Mar 21 '25 14:03 sdeigm