Commit 09ef3b69 authored by Jerome Courat's avatar Jerome Courat

Fixed WiFi STA erroneous use of WiFi.begin()

parent 0990cf4f
......@@ -28,28 +28,62 @@ void setup_wifi()
Serial.println(wifi_settings.wifi_sta_active);
if (wifi_settings.wifi_sta_active == true)
{
if (strcmp(wifi_settings.wifi_sta_mode.c_str(), "static") == 0)
{
Serial.println("Using Static Addressing");
IPAddress localIp;
if (!localIp.fromString(wifi_settings.wifi_sta_network_ip))
{
Serial.print("Invalid IP address : ");
Serial.println(wifi_settings.wifi_sta_network_ip);
}
IPAddress gateway;
if (!gateway.fromString(wifi_settings.wifi_sta_network_gateway))
{
Serial.print("Invalid gateway IP address : ");
Serial.println(wifi_settings.wifi_sta_network_gateway);
}
IPAddress subnet;
if (!subnet.fromString(wifi_settings.wifi_sta_network_netmask))
{
Serial.print("Invalid subnet IP address : ");
Serial.println(wifi_settings.wifi_sta_network_netmask);
}
WiFi.config(localIp, gateway, subnet);
}
else
{
Serial.println("Using DHCP");
}
Serial.print("Connecting to AP: ");
Serial.println(wifi_settings.wifi_sta_ssid);
if (WiFi.begin(wifi_settings.wifi_sta_ssid.c_str(),
wifi_settings.wifi_sta_pwd.c_str()) !=
WL_CONNECTED)
WiFi.begin(wifi_settings.wifi_sta_ssid.c_str(),
wifi_settings.wifi_sta_pwd.c_str());
int i = 0;
while (WiFi.status() != WL_CONNECTED && (i++ < 20))
{
Serial.print(".");
delay(1000);
}
if (WiFi.status() == WL_CONNECTED)
{
Serial.println("Connected to Wifi :)");
Serial.print("IP: ");
Serial.println(WiFi.localIP());
Serial.print("Gateway: ");
Serial.println(WiFi.subnetMask());
Serial.print("Netmask: ");
Serial.println(WiFi.gatewayIP());
MDNS.begin(wifi_settings.wifi_name.c_str());
}
else
{
Serial.println("Connection to wifi failed.");
}
randomSeed(micros());
delay(500);
Serial.println(WiFi.localIP());
}
}
else
{
Serial.println("Could not read settings");
}
MDNS.begin(wifi_settings.wifi_name.c_str());
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment