Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

MAC Addres

Good day!

I have an esp8266 running connected to a COM port. When I open the console and reboot the board, then the OS shows me the device's MAC addres. But, when I look at the connected devices in my network (look into arp table), I could see the MAC isn't the same. The MAC informed by Mongoose os starts with 5E:CF:7F, and I think ESPRESSIF's MAC address should start with 5C:CF:7F (i've cheked here: https://macvendors.com/)
Does Mongoose OS get the vendor's portion of MAC address from the chip or is it written in some file?

Thanks in advace!

BR

Comments

  • rojerrojer Dublin, Ireland

    ESP devices use different MAC for AP and STA modes, they differ by prefix and latter bytes are the same.

  • Fede_1988Fede_1988 Argentina
    Ahh! Then in my console i'm looking at the softAP MAC. How should i do to get the sta mac addres? Later on, esp8266 will have to inform it through an AP connection. Thank you!!
  • rojerrojer Dublin, Ireland

    device_get_mac_address returns AP's MAC, there is currently no way to get STA MAC.
    are you interested in a C or JS API?

  • Fede_1988Fede_1988 Argentina

    I'm using C.

    Ok then, maybe i can implement a rutine in esp8266 that runs device_get_mac_address and overwrite the first fields with ESPRESSIF code! As soon as i get it working, i'll share it here.

    BR!

  • rojerrojer Dublin, Ireland

    yeah, they only differ in the first octet. i'll note the ncessity to provide both AP and STA MACs, but cannot promise a quick fix.

  • Fede_1988Fede_1988 Argentina

    Great thanks!

  • Fede_1988Fede_1988 Argentina

    Hello!
    Here's a workaround:
    Get's AP mac address in specified uint8_t array, overrite vendors field to get correct sta MAC address, and also converts to string.

    void get_mac_address (uint8_t * mac_uin8t, char * mac_str)
    {
        device_get_mac_address(mac_uin8t);
        *mac_uin8t=0x5C;                //Originally informs 5E (AP MAC ADDRESS)
        *(mac_uin8t+1)=0xCF;                            //Not really necessary
        *(mac_uin8t+2)=0x7F;                            //Not really necessary
        sprintf(mac_str, "%02x%02x%02x%02x%02x%02x\n", mac_uin8t[0]&0xFF,mac_uin8t[1]&0xFF,mac_uin8t[2]&0xFF,mac_uin8t[3]&0xFF,mac_uin8t[4]&0xFF,mac_uin8t[5]&0xFF);
        puts(mac_string);
    }

    Hope it's helpful to someone

    Regards!

  • igraczechigraczech Prague, Czech Republic

    I am on ESP32 and this crashes, also Sys.ro_vars.mac_address in mJS is useless (ro_vars do not exist). Any help would be appreaciated. https://github.com/suculent/thinx-firmware-esp8266-mos.git

  • @igraczech
    uint8_t * mac_uin8t; => uint8_t mac_uin8t[8]; ?

  • @Sergey The URL in the above comment doesn't seem to work anymore since the site URLs were changed. Is there a way to repost the solution to this. I have used it in the past, but can't find. Thanks!

  • That content has vanished indeed, hmm. Here it is, for your reference:

    The solution is to call Sys.GetInfo RPC service.
    From your terminal, run:

    mos call Sys.GetInfo
    [Aug 21 08:29:17.016] {
    ...
    [Aug 21 08:29:17.016]   "mac": "5ECF7F060046",
    [Aug 21 08:29:17.016]   "arch": "esp8266",
    [Aug 21 08:29:17.016]   "wifi": {
    [Aug 21 08:29:17.016]     "sta_ip": "192.168.1.31",
    ...
    
    You can see e.g. MAC and IP addresses in the output.
    In order to call the same function in JS, do:
    
    ```javascript
    load('api_rpc.js');
    RPC.call(RPC.LOCAL, 'Sys.GetInfo', null, function(resp, ud) {
      print('Response:', JSON.stringify(resp));
      print('MAC address:', resp.mac);
    }, null);
    

    The device would print to the output:

    [Aug 21 08:23:33.162] Response: {... "arch":"esp8266",... } 
    [Aug 21 08:23:33.170] MAC address: 5ECF7F060046 
    
  • edited May 2018

    @dimonomid, unfortunately, this is the AP mode MAC address, not the STA mode one. The only change I am aware of is having the second octal in the MAC address having a value that is two less. But I don't know if that will always be the case. I think the best way to do it as of now is just to use the ESP SDK.

Sign In or Register to comment.