homieiot / homie-esp8266

💡 ESP8266 framework for Homie, a lightweight MQTT convention for the IoT
http://homieiot.github.io/homie-esp8266
MIT License
1.36k stars 308 forks source link

Wifi.begin not working on BootNormal.cpp #607

Closed nemiliani closed 5 years ago

nemiliani commented 5 years ago

Hi All,

First thing first. Loving Homie. Great job! This is more a question than anything else. I am using platformio and v2.0.0 on top of a wemos d1 that has the arduino shield compatibility. I was having a really hard time having the Homie connected to WiFi in normal mode. I debugged the code and found that for some reason the callback BootNormal::_onWifiGotIp was not getting invoked even though I could see in my router the IP being assigned as well as the board replying to ICMP ping. I got it working by calling WiFi.begin on the setup function in my main.cpp ...

void setup(){

  /********************* HOMIE *********************/
  // The underscore is not a typo! See Magic bytes
  Homie_setFirmware("liquid-probe", "1.0.0");
  Homie.setSetupFunction(setupHandler).setLoopFunction(loopHandler);
  temperature_node.advertise("unit");
  temperature_node.advertise("degrees");
  Homie.onEvent(onHomieEvent);
  Homie.setup();

  WiFi.begin(
      HomieInternals::Interface::get().getConfig().get().wifi.ssid,
      HomieInternals::Interface::get().getConfig().get().wifi.password);
  /*************************************************/
}

Haven't been able to figure out why the WiFi.begin in BootNormal::_wifiConnect isn't working. My intuition says it has to do with some race condition between events in the event loop. But just a hunch.

Has anybody experienced this ? Any ideas on where to dig ?

Thanks!

stritti commented 5 years ago

I think you do not need to call WiFi.begin(..); in setup() it is done by Homie.setup(); internal already.