I want to develop my first binding for SMA inverters. To identify the devices during discovery, I need to log in to the inverter using a username and password. Usually these are “user” and “1111”. But if someone changed the password on the inverter, discovery would fail.
To get rid of this problem, I need a way that the user can specify username/password (or a list of this pairs) for the discovery. How can I achieve that?
It’s a bit of a chicken-egg problem. I’ve had a similar situation where a device needs a authentication key. I solved this as follows. While direct access isn’t possible. It is possible to detect the device due to the way it reports back. I assume you can do something similar. The device will probably report back if you make a connection with an error that the username/password is incorrect. In such a case in discovery you simply add the device with either the default username/password or empty values. When the thing is then initialized you handle in this in the initialization phase of the binding by setting the status to configuration error with a clear message the user need to set the username/password.
If there is only one speedwire device in the network, this might work. But the only data I get from this first discovery phase is the IP address of a device which replies to my multicast package with a defined answer. What do I do, if I get multiple answers from different devices? How should the user know, which IP address corresponds to which device?
How do you send the username/password? I would guess when you have the ip you connect directly to it? Does it report something back than? Even if the username/password is not correct. During discovery you can connect and use what it reports back, if that is any useful information of course.
The ThingUID is less relevant because there is no direct relation between the device and the ThingUID. It’s free format. Technically any overlap would be coincidental. So you can set it to any string you want.
To avoid rediscovering you need to set some unique id and ip address could be cause or rediscovering the same device if the ip changes. But you can tackle that by setting the serial afterwards in the configuration if the device is authenticated. This will only cause rediscovering of unauthenticated devices that changed ip address.