Is it possible to get the Impee ID (or some other ID unique to the device and not the agent) in the agent without me having to send a message from the device to the agent explicitly?
Both hardware.getimpeeid() and imp.getmacaddress() seem to only be available to the device.
Unfortunately no. These two values are directly related to the hardware.
getimpeeid() returns the ATSHA chip’s Unique ID (the ATSHA chip is what we use to uniquely identift what hardware your imp is plugged into).
getmacaddress() returns the imp’s MAC address, which is also a hardware thing.
Is there a reason you don’t want to / cannot send the information from the device? You could store it locally on the agent with server.save() and server.load():
function loadData() {
// get saved data
local data = server.load();
if (“macAddress” in data && “impeeId” in data) {
// if we have saved data, load it into the global variables
macAddress = data.macAddress;
impeeId = data.impeeId;
} else {
// otherwise send a request to data from the imp
device.send(“getInfo”, null);
}
}
device.on(“getInfoCallback”, impData) {
// set global variables
macAddress = impData.macAddress;
impeeId = impData.impeeId;
// save data
local data = server.load();
data.macAddress <- impData.macAddress;
data.impeeId <- impData.impeeId;
server.save(data);
}
I mostly just wanted to be lazy. I was assuming that the device sends that information anyways since it’s displayed in the IDE (at least for the impeeid) and was hoping that there was something simple that I wasn’t seeing.
I hadn’t thought of just generating a random ID, I’ll have to think about how that would work in my case.
Thanks for the answers and thanks for the code beardedinventor.