Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 8d0a03f
Author: Boris Brock <[email protected]>
Date:   Fri Aug 9 09:04:30 2024 +0200

    Fixing typo

commit d451a8c
Author: Boris Brock <[email protected]>
Date:   Wed Aug 7 08:50:23 2024 +0200

    Removing debug code

commit 3e0bf34
Author: Boris Brock <[email protected]>
Date:   Sat Jul 27 16:20:50 2024 +0200

    Adding debug code
  • Loading branch information
BorisBrock committed Aug 9, 2024
1 parent 7b5aded commit 54237f0
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/Components/WiFi/WifiConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,44 @@

namespace WifiConnection
{
WiFiManager gWifiManager;
const char *ssid = "YourSSID";
const char *password = "YourPassword";

void Init()
void WiFiStationConnected(WiFiEvent_t event, WiFiEventInfo_t info)
{
Serial.print("Starting WiFi Manager");
Serial.println("Connected to AP successfully!");
}

WiFi.hostname(Constants::WiFi::HostName);
gWifiManager.setDebugOutput(false);
gWifiManager.setConfigPortalTimeout(180);
gWifiManager.setTitle(Constants::WiFi::CaptivePortalTitle);
void WiFiGotIP(WiFiEvent_t event, WiFiEventInfo_t info)
{
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

// Hide everything except the wifi button
std::vector<const char *> menu = {"wifi"};
gWifiManager.setMenu(menu);
void WiFiStationDisconnected(WiFiEvent_t event, WiFiEventInfo_t info)
{
Serial.println("Disconnected from WiFi access point");
Serial.print("WiFi lost connection. Reason: ");
Serial.println(info.wifi_sta_disconnected.reason);
Serial.println("Trying to reconnect");
WiFi.begin(ssid, password);
}

// Open up the access point
gWifiManager.autoConnect(Constants::WiFi::HotspotSSID, Constants::WiFi::HotspotPassword);
void Init()
{
// Delete old config
Serial.println("Preparing Wifi");
WiFi.disconnect(true);
delay(100);

// If we got here, connection was established successfully
Serial.println("WiFi setup completed successfully");
Serial.print("Local IP address: ");
Serial.println(WiFi.localIP());
// Register WiFi events
WiFi.onEvent(WiFiStationConnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_CONNECTED);
WiFi.onEvent(WiFiGotIP, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
WiFi.onEvent(WiFiStationDisconnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);

// Start Wifi connection
Serial.println("Connecting WiFi");
WiFi.begin(ssid, password);
}
};

0 comments on commit 54237f0

Please sign in to comment.