ESP8266 - Mac address retrieval

#1

Hello everyone, I’ve been trying to retrieve the device’s mac address. For instance, I’m using a standard
ESP8266 nodeMCU.

  1. My goal is: Retrieve de device Mac address in a way I can use it further.

  2. My actions are: I’ve pasted the sample code as follows:

let rpcMC = RPC.call(RPC.LOCAL, 'Sys.GetInfo', null, function(resposta, ud) 
{
  print('MAC address:', resposta.mac);
}, null);

Edit: When trying to put the function inside the below timer, I received a calling non-callable feedback.

Timer.set(1000, Timer.REPEAT, rpcMC())
{

};

This sample code works just fine, but I want to be able to use the Mac address further on (to create a thing name in AWS).

  1. The result I see is: - This RPC call returns a bunch of information regarding the device, including the mac address, and the function prints it out, but since the ‘resposta’ variable does not exist outside the function, I’m trying to print it in a timer of just somewhere else.

  2. My expectation & question is: I expect to be able to use this MAC address to create a thing name inside AWS further down the road.

Tks,

#3

Just call the config-get function, or call theRPC if you wish, you’ll get a JSON object, parse that object and save what you care for in a global variable.

let client_id = Cfg.get('device.id');
1 Like
#4

on the specifics of AWS, just leave your thing ID empty in your mos.yml and mOS will do it for you

 - ["aws.thing_name", ""]

If you can read spanish: this

1 Like
#5

Hello scaprile,

Thank you, I have managed to do it over RPC and parse the object using jq.

As for the AWS, I made a bash script using AWS CLI to create a thing for me using the MAC Address as part of the thing name, such as:

MAC=$(mos call Sys.GetInfo | jq ‘.mac’ -r)

aws iot create-thing --thing-name KO_$MAC