Skip to content

Commit

Permalink
Merge pull request #737 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Made the AP mode use the ssid and passphrase from the STA mode. Allows Secure AP.
  • Loading branch information
forkineye authored Feb 12, 2024
2 parents a7f23da + 00d1f9e commit 964ae43
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions ESPixelStick/src/network/WiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,39 +470,52 @@ bool c_WiFiDriver::SetConfig (JsonObject & json)
String sIp = ip.toString ();
String sGateway = gateway.toString ();
String sNetmask = netmask.toString ();

ConfigChanged |= setFromJSON (ssid, json, CN_ssid);
ConfigChanged |= setFromJSON (passphrase, json, CN_passphrase);
ConfigChanged |= setFromJSON (sIp, json, CN_ip);
ConfigChanged |= setFromJSON (sNetmask, json, CN_netmask);
ConfigChanged |= setFromJSON (sGateway, json, CN_gateway);
ConfigChanged |= setFromJSON (UseDhcp, json, CN_dhcp);
bool chanChanged = setFromJSON (ap_channelNumber, json, CN_ap_channel);
ConfigChanged |= chanChanged;
ConfigChanged |= setFromJSON (ap_channelNumber, json, CN_ap_channel);
ConfigChanged |= setFromJSON (sta_timeout, json, CN_sta_timeout);
ConfigChanged |= setFromJSON (ap_fallbackIsEnabled, json, CN_ap_fallback);
ConfigChanged |= setFromJSON (ap_timeout, json, CN_ap_timeout);
ConfigChanged |= setFromJSON (RebootOnWiFiFailureToConnect, json, CN_ap_reboot);
ConfigChanged |= setFromJSON (StayInApMode, json, CN_StayInApMode);

// DEBUG_V (" ip: " + ip);
// DEBUG_V ("gateway: " + gateway);
// DEBUG_V ("netmask: " + netmask);

// DEBUG_V(String("ap_channelNumber: ") + String(ap_channelNumber));
// DEBUG_V (" ip: " + ip);
// DEBUG_V ( "gateway: " + gateway);
// DEBUG_V ( "netmask: " + netmask);
// DEBUG_V (String("ap_channelNumber: ") + String(ap_channelNumber));
// String StateName;
// pCurrentFsmState->GetStateName(StateName);
// DEBUG_V(String(" CurrState: ") + StateName);

if(chanChanged & pCurrentFsmState == &fsm_WiFi_state_ConnectedToSta_imp)
{
// DEBUG_V("need to cycle the WiFi to move to a new channel");
WiFi.softAPdisconnect();
}
ip.fromString (sIp);
gateway.fromString (sGateway);
netmask.fromString (sNetmask);

if((passphrase.length() < 8) && (passphrase.length() > 0))
{
logcon (String (F ("WiFi Passphrase is too short. Using Empty String")));
passphrase = emptyString;
}

if(ConfigChanged)
{
// DEBUG_V("WiFi Settings changed");
if(pCurrentFsmState == &fsm_WiFi_state_ConnectedToAP_imp)
{
// DEBUG_V("need to cycle the WiFi to move to new STA settings");
WiFi.disconnect();
}
else if(pCurrentFsmState == &fsm_WiFi_state_ConnectedToSta_imp)
{
// DEBUG_V("need to cycle the WiFi to move to new AP settings");
WiFi.softAPdisconnect();
}
}

// DEBUG_V (String("ConfigChanged: ") + String(ConfigChanged));
// DEBUG_END;
return ConfigChanged;
Expand Down Expand Up @@ -803,11 +816,15 @@ void fsm_WiFi_state_ConnectingAsAP::Init ()
{
WiFi.enableSTA(false);
WiFi.enableAP(true);
String Hostname;
NetworkMgr.GetHostname (Hostname);
String ssid = "ESPixelStick-" + String (Hostname);
String ssid = pWiFiDriver->ssid;
if(ssid.equals(emptyString))
{
String Hostname;
NetworkMgr.GetHostname (Hostname);
ssid = "ESPixelStick-" + String (Hostname);
}
// DEBUG_V(String("ap_channelNumber: ") + String(pWiFiDriver->ap_channelNumber));
WiFi.softAP (ssid.c_str (), NULL, pWiFiDriver->ap_channelNumber);
WiFi.softAP (ssid.c_str (), pWiFiDriver->passphrase.c_str (), int(pWiFiDriver->ap_channelNumber));

pWiFiDriver->setIpAddress (WiFi.localIP ());
pWiFiDriver->setIpSubNetMask (WiFi.subnetMask ());
Expand Down

0 comments on commit 964ae43

Please sign in to comment.