victronenergy / venus-influx-loader

NodeJS server that takes from MQTT into Influx, and config UI and still more
MIT License
12 stars 4 forks source link

Feature request: recognizable client ID and better random #107

Closed wiebeytec closed 3 days ago

wiebeytec commented 1 month ago

For debugging, it's always convenient to have recognizable client IDs. The default is 'mqttjs_' + Math.random().toString(16).substr(2, 8). This is generic, and the randomness is bad. If 'random()` is 0, the string is empty.

Unfortunately the MQTT protocol puts the burdon of good random uniqueness on the client. Do you have crypto available in all run-time environments? If so, we can do:

'venus_influx_loader_' + crypto.randomUUID();
mman commented 3 weeks ago

@wiebeytec We are already generating a (kind of) random identifier to identify VRM token on each login, so I will invent something that will be visible on the VRM token management page and will be used as well when connecting to MQTT. That should make pairing things together easy.

mman commented 3 weeks ago

I do not see a problem using Math.random in our situation, probability of collision when connecting from multiple loaders to the same VenusOS on LAN seems rather low, and in case of VRM I added the VRM token ID to identify client, as token IDs shall be unique for each loader instance.