Isaksson / node-red-contrib-unifi

MIT License
50 stars 19 forks source link

enhancement request: #129

Closed jmorris644 closed 4 months ago

jmorris644 commented 5 months ago

Is it possible to get the device name via the mac address? I would like to be able to convert the received mac address coming form the unifiWS node and display the device name.

Isaksson commented 5 months ago

You could use the command getClientDevices and then loop the array and when your on the correct client based on the MAC then you could return the clients name.

In this example I pass the MAC in the msg.mac from a inject node, in your case you will not use a inject node you will use the WS node I assume. Then I get all clients with Unifi Node and then loop and look for the MAC, then I replace the msg.payload with the clients hostname

Inject -> Unifi getClientDevices -> Function Node

code in the function node msg.payload.forEach(function(element) { if (element.mac === msg.mac) { msg.payload = element.hostname return msg; } });

jmorris644 commented 5 months ago

Thanks. But quite often the hostname is empty. I see that with my iPhone when I initially connect to the network.

Is there no API to query a mac address and get the hostname from the server?

Isaksson commented 5 months ago

If the hostname is empty when running the command getClientsDevices then Unifi don't have the hostname information. This is the API that will query the Unifi server for hostname.

Isaksson commented 5 months ago

I dont know if this is related to the random MAC that probably is turned on, on your iPhone, or do you see that your device always has the same MAC? https://dhcp.msu.edu/help/randommac.html#apple_device