-
• #2
That's as you'd expect I think?
/* Get the IP and MAC address when connected to an AP and call `callback(err, { ip : ..., mac : ...})`. If err isn't null, it contains a string describing the error. This doesn't work when only in AP mode (the IP address is always 192.168.4.1) */ exports.getIP = function (callback) { ... }
So it's that there are two arguments returned by the callback -
err
andip
. It's odd, but it's just the way node.js tended to handle callback functions that can return an error, so I wanted to keep things compliant with them.Since on EspruinoWiFi the WiFi is basically async,
getIP
can't immediately return an IP address.Unfortunately when running on ESP8266 the callback format is different - it's something I'd like to change to bring everything more in-line really.
-
• #3
doooh... me... sorry bothering you for the callback... now I recall that the first argument is the error, and if first argument - error - is null, second argument is the actual data...
I adjusted my code and it does what I needed. THANKS...
Adjusted with 'assuming' I get no err(or) in
getIP()
:... wifi.getIP(function(err,data){ console.log("getIP() in callback: ",data.ip); })); ...
with console output:
... Running onInit()... Connected! getIP() in callback: 192.168.0.113 >
Setup is as documented (and required to start with saved code after power on:
Console:
Even executed much later, I get the same undefined / null.