question

stm32-0752 avatar image
0 Votes"
stm32-0752 asked JamesHiggins-7505 edited

Get WiFi MAC address using API on Azure Sphere

Hello,

Is there a way to get programmatically the MAC address of the WiFi hardware using the API?

azure-sphere
· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @stm32-0752 , Thanks for reaching out to us!


Could you please let us know a sample Use Case scenario in your project ?


so that we better understand the requirement for Azure Sphere API



Do you want to achieve something like the below via API ?, just wanted to confirm


azsphere device wifi show-status

SSID : NETGEAR21
Configuration state : enabled
Connection state : connected
Security state : psk
Frequency : 2442
Mode : station
Key management : WPA2-PSK
WPA State : COMPLETED
IP Address : 192.168.1.15
MAC Address : 52:cf:ff:3a:76:1b
Command completed successfully in 00:00:01.3976308.


0 Votes 0 ·

Sorry for the late response,I did not get a notification. Yes, I would like to get the same information using the API no the Azure CLI.

0 Votes 0 ·
SatishBoddu-MSFT avatar image SatishBoddu-MSFT CastilloRickeyAvidTechnologies-8121 ·

Hello @CastilloRickeyAvidTechnologies-8121 , Could you please share (if any) the user voice feedback being submitted on Azure Sphere ?


Please create a new user voice feedback request on this page with all details related to your business use case and customer/delivery impact, so that we can support this discussion with all requirements and justifications.





0 Votes 0 ·

Hello @stm32-0752 ,Just checking back, could you please let us know if you need further help in this matter.

0 Votes 0 ·

Hello @stm32-0752 , Just checking back, could you please let us know if you need further help in this matter.

0 Votes 0 ·

Azure Team,

There's always a need to programatically get a unique, immutable device identifier. Maybe this person actually needs the MAC address or maybe actually just needs an ID. Azure Sphere has two (MAC, Device ID), neither of which have an API to access them. My current project has a requirement to provide some unique device ID and we're having to create a solution to provide this, which adds additional work since it now requires a mapping, and additional management, in the cloud.

0 Votes 0 ·

Hello @MarkScott-9536 Thanks for the comment. As of now, we don't have any support for this feature via API. We have requested to submit the user Voice feature request in the past. So that we prioritize the feature and followup with the PG/Dev team. Please make use of this similar user voice to up vote & comment ---> Provide API to read device related information for example, device ID, Remaining storage info, Please make sure to add your comment as well to describe your scenario.




0 Votes 0 ·
SatishBoddu-MSFT avatar image
0 Votes"
SatishBoddu-MSFT answered SatishBoddu-MSFT edited

Hello @stm32-0752 , We had a similar kind of discussion in the past , if possible could you please share any User voice feedback being submitted from your side on this request.


MSDN Similar discussion Thread: MAC address in Ethernet



Quoted Response from Previous discussion:
Friday, January 17, 2020 5:13 PM
At this time there is no command to query the Ethernet interface and list properties associated to IP Address (IPv4) or the MAC address, etc...such as the case for the WiFi interface. This is a product backlog item and will be part of a future release.
If you have additional feedback or questions, please let me know. I would also suggest to add an entry in the Azure IoT UserVoice to detail specific functionality or features you are looking for or that would be desired.
If you are looking to access the Ethernet IP Address (IPv4) programmatically there is the following library: getifaddrs
Please see the following Git Issue related to this: https://github.com/Azure/azure-sphere-samples/issues/97





[3]: /answers/storage/attachments/12901-image.png



image.png (32.9 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @CastilloRickeyAvidTechnologies-8121 , @stm32-0752 , Could you please share (if any) the user voice feedback being submitted on Azure Sphere ?



Please create a new user voice feedback request on this page with all details related to your business use case and customer/delivery impact, so that we can support this discussion with all requirements and justifications.



0 Votes 0 ·
JamesHiggins-7505 avatar image
0 Votes"
JamesHiggins-7505 answered JamesHiggins-7505 edited

You can get the MAC address from the Sphere high-level application, at least with the latest OS/SDK as of this posting:

 #include <ifaddrs.h>
 #include <net/ethernet.h>
 #include <sys/socket.h>
 #include <netpacket/packet.h>
    
 void getIP(void)
 {
     struct ifaddrs* addr_list;
     struct ifaddrs* it;
     int n;
     const char EthInterface[] = "wlan0";
     if (getifaddrs(&addr_list) < 0) {
         Log_Debug("***** GETIFADDRs failed! ***\n");
     }
     else {
         for (it = addr_list, n = 0; it != NULL; it = it->ifa_next, ++n) {
             if (it->ifa_addr == NULL) {
                 continue;
             }
             if (strncmp(it->ifa_name, EthInterface, sizeof(EthInterface)) == 0) {
                 if (it->ifa_addr->sa_family == AF_INET) {
                     struct sockaddr_in* addr = (struct sockaddr_in*)it->ifa_addr;
                     char* ip_address = inet_ntoa(addr->sin_addr);
                     Log_Debug("**** wlan0 IP found: %s ***\n", ip_address);
                 }
                 else if (it->ifa_addr->sa_family == AF_PACKET) {
                     struct sockaddr_ll* mac_addr = (struct sockaddr_ll*)it->ifa_addr;
                     unsigned char* mac = mac_addr->sll_addr;
    
                     char mac_string[20];
                     sprintf(mac_string, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0],
                         mac[1], mac[2], mac[3], mac[4], mac[5]);
                     Log_Debug("**** wlan0 MAC 1 found: %s ****\n", mac_string);
                 }
             }
         }
     }
     freeifaddrs(addr_list);
 }


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.