WLED icon indicating copy to clipboard operation
WLED copied to clipboard

Send Websocket message when device name changes

Open Moustachauve opened this issue 3 months ago • 8 comments

Is your feature request related to a problem? Please describe. Currently, if I go on my device settings, click on "User Interface", change the value of "Server description" to something else and hit "Save", the name is updated but nothing more is done.

Describe the solution you'd like It would be nice if a status update could be sent through websocket to inform clients that the name has changed.

Additional context I've noticed this lack of update when working on an new version of WLED Native using websockets. When I change the name of the device, I won't receive the new name until there's a new state change, which could take a while.

Moustachauve avatar Dec 01 '25 04:12 Moustachauve

(New) name is sent via node broadcast message every 30s (if enabled). Websockets messages have a somewhat greater toll on WLED so they should be used sparsely IMO.

If you want to test the implications there is only one line of code that is needed:

interfaceUpdateCallMode = CALL_MODE_WS_SEND;

In set.cpp in UI if section.

blazoncek avatar Dec 01 '25 06:12 blazoncek

When you say "node broadcast", I assume you are talking about UDP?

Websockets messages have a somewhat greater toll on WLED so they should be used sparsely IMO.

I don't think that there would be much load if there would be a websocket broadcast on a settings page "Save" event. Those would be much less frequent than regular state changes, in theory, right?

Moustachauve avatar Dec 01 '25 07:12 Moustachauve

Yes (its intention is to make entire network aware of node's presence).

Nevertheless, one additional WS broadcast that will lock JSON buffer and use network stack. 😁 Not that it will make a huge impact but one needs to be aware of it. It falls in the same category as the need for update, eventually your app (client) will receive a new name without any change in code.

But, as said, one line of code will resolve the issue. If you want a bit fancy solution that will only broadcast when needed, check if name actually changed.

blazoncek avatar Dec 01 '25 07:12 blazoncek

Users would expect to see the change on a near realtime basis, if we have a websocket for pushing data, then it seems reasonable this would be data you would receive. Also the app supports manually adding devices for when your devices are not on the same subnet doesn't it? So can't rely on the discovery to push the new name

netmindz avatar Dec 01 '25 08:12 netmindz

I think just sending a whole update on every setting page save would be reasonable. I personally don't think it's even worth the hassle to try to see if anything changed, but I am not familiar with the device resource restrictions.

Main arguments are:

  1. Those updates happen very rarely
  2. Instant update notification on websocket gives the best UX for 3rd party clients
  3. Remote devices (like netmindz mentioned) can't rely on other sync methods
  4. Should have much less impact than polling or even liveview

Anyway, the app can work fine just as it is, especially since people don't go around updating settings all the time, but it would give a bit nicer user experience if the update could happen instantly.

Moustachauve avatar Dec 01 '25 22:12 Moustachauve

Workflow, when changing device name, is as follows:

  1. enter settings (leave main UI, WS is closed)
  2. change device name (no WS connection to device is made)
  3. return to main UI (new WS connection is opened and info/state JSON is sent during connect which includes new device name)

However, if there are other clients connected and have main UI open, then, yes, they will not get an update until they refresh UI or state in WLED changes. There are not many users which have more than one connection to a device open at any time.

This is just my reasoning why additional WS broadcast may be superfluous. As mentioned earlier a one line addition to the code will fulfil this request.

blazoncek avatar Dec 02 '25 06:12 blazoncek

There are not many users which have more than one connection to a device open at any time.

I'm about to change this! There's a lot of WLED users using my app, and there's a few other apps out there that already uses websocket too.

Is the device aware of how many clients are connected to its websocket server? If so, maybe an idea would be to skip sending the update if no clients are connected (avoid serializing to JSON for nothing).

As mentioned earlier a one line addition to the code will fulfil this request.

I'd gladly open a pull request but sadly, my work contract prevent me from directly contributing code to the project.

Moustachauve avatar Dec 02 '25 06:12 Moustachauve

I'm about to change this!

Poor ESP. 😉

skip sending the update

That's implemented already. 😄

blazoncek avatar Dec 02 '25 07:12 blazoncek