Udp.begin(localPort) causes Wifi.localIP() to not work

The ip and mac spark variables, below, works fine until I start UDP. The UDP works so no problem there. I can probably make a work around to start the UDP after I query the ip and mac addresses but thought I might point it out just in case someone has ran into it.

//Code without UDP works perfect.
IPAddress myIp = WiFi.localIP();
WiFi.macAddress(mac);
sprintf(myIpString, “%d.%d.%d.%d”, myIp[0], myIp[1], myIp[2], myIp[3]);
sprintf(myMacString, “%02x:%02x:%02x:%02x:%02x:%02x”, mac[5],mac[41], mac[3],mac[2], mac[1], mac[0]);
Spark.variable(“ipAddress”, myIpString, STRING);
Spark.variable(“MacAddress”, myMacString, STRING);

//Until I add UDP.
Udp.begin(localPort);

Is the typo "mac[41]" in your actual code?

Yes, not sure what happened there… but the original code is ‘4’ and it works. I have compared both addresses, mac and ip, on my router and they are the same. Only when I include the Udp.begin is when it returns all zeroes otherwise my code does what I want it to do.

OK. It worked all of a sudden. I guess this is a timing thing?
I added a couple more variables to watch some UDP messages and tried the mac and ip address again with success.

I think this is a startup race condition. You could loop waiting for the local IP address to be non-zero call SPARK_WLAN_Loop(); I guess.

I hope Photon will be better in this regard.