dj-nitehawk / Hybrid-Inverter-Monitor

Monitoring application for hybrid inverters using the Voltronic communication protocol & JK BMS via USB port.
MIT License
82 stars 23 forks source link

How to send a news by SSE to every browser clients? #25

Closed bobbydog closed 9 months ago

bobbydog commented 9 months ago

This SSE example Endpoint GetStatus , I wonder when there are more than two browser clients subsribed "status", the code is seemed to be the CommandQueue.GetCommand() method will just Peek one comand for the one client to comsume, yet others won't get response ?

dj-nitehawk commented 9 months ago

there is no SSE being used. it's just an http stream (done via IAsyncEnumerable):

https://github.com/dj-nitehawk/Hybrid-Inverter-Monitor/blob/6ea7af8b5c78c423c7075c0ff4b9d9cda93aebb7/src/Server/Endpoints/GetStatus/Endpoint.cs#L19-L22

also the endpoint does not cause a GetStatus Command to be issued to the inverter per browser client.

it sends the same status data to all connected browsers.

reading the status data from the inverter is done by a background service which queues GetStatus Commands which queues the QPIGS command every 2 seconds.

there's a separate background service for the main queue (which stores all type of commands) and executes them serially.

the architecture is a bit difficult to understand but that's the only way i found to query data from the inverter and distribute that data to multiple client browsers in a reliable way.