Add AP mode option for file transfers (#98)
## Summary
* **What is the goal of this PR?** Adds WiFi Access Point (AP) mode
support for File Transfer, allowing the device to create its own WiFi
network that users can connect to directly - useful when no existing
WiFi network is available. And in my experience is faster when the
device is right next to your laptop (but maybe further from your wifi)
* **What changes are included?**
- New `NetworkModeSelectionActivity` - an interstitial screen asking
users to choose between:
- "Join a Network" - connects to an existing WiFi network (existing
behavior)
- "Create Hotspot" - creates a WiFi access point named
"CrossPoint-Reader"
- Modified `CrossPointWebServerActivity` to:
- Launch the network mode selection screen before proceeding
- Support starting an Access Point with mDNS (`crosspoint.local`) and
DNS server for captive portal behavior
- Display appropriate connection info for both modes
- Modified `CrossPointWebServer` to support starting when WiFi is in AP
mode (not just STA connected mode)
## Additional Context
* **AP Mode Details**: The device creates an open WiFi network named
"CrossPoint-Reader". Once connected, users can access the file transfer
page at `http://crosspoint.local/` or `http://192.168.4.1/`
* **DNS Captive Portal**: A DNS server redirects all domain requests to
the device's IP, enabling captive portal behavior on some devices
* **mDNS**: Hostname resolution via `crosspoint.local` is enabled for
both AP and STA modes
* **No breaking changes**: The "Join a Network" option preserves the
existing WiFi connection flow
* **Memory impact**: Minimal - the AP mode uses roughly the same
resources as STA mode
This commit is contained in:
@@ -7,12 +7,15 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "NetworkModeSelectionActivity.h"
|
||||
#include "activities/ActivityWithSubactivity.h"
|
||||
#include "network/CrossPointWebServer.h"
|
||||
|
||||
// Web server activity states
|
||||
enum class WebServerActivityState {
|
||||
WIFI_SELECTION, // WiFi selection subactivity is active
|
||||
MODE_SELECTION, // Choosing between Join Network and Create Hotspot
|
||||
WIFI_SELECTION, // WiFi selection subactivity is active (for Join Network mode)
|
||||
AP_STARTING, // Starting Access Point mode
|
||||
SERVER_RUNNING, // Web server is running and handling requests
|
||||
SHUTTING_DOWN // Shutting down server and WiFi
|
||||
};
|
||||
@@ -20,8 +23,10 @@ enum class WebServerActivityState {
|
||||
/**
|
||||
* CrossPointWebServerActivity is the entry point for file transfer functionality.
|
||||
* It:
|
||||
* - Immediately turns on WiFi and launches WifiSelectionActivity on enter
|
||||
* - When WifiSelectionActivity completes successfully, starts the CrossPointWebServer
|
||||
* - First presents a choice between "Join a Network" (STA) and "Create Hotspot" (AP)
|
||||
* - For STA mode: Launches WifiSelectionActivity to connect to an existing network
|
||||
* - For AP mode: Creates an Access Point that clients can connect to
|
||||
* - Starts the CrossPointWebServer when connected
|
||||
* - Handles client requests in its loop() function
|
||||
* - Cleans up the server and shuts down WiFi on exit
|
||||
*/
|
||||
@@ -29,15 +34,19 @@ class CrossPointWebServerActivity final : public ActivityWithSubactivity {
|
||||
TaskHandle_t displayTaskHandle = nullptr;
|
||||
SemaphoreHandle_t renderingMutex = nullptr;
|
||||
bool updateRequired = false;
|
||||
WebServerActivityState state = WebServerActivityState::WIFI_SELECTION;
|
||||
WebServerActivityState state = WebServerActivityState::MODE_SELECTION;
|
||||
const std::function<void()> onGoBack;
|
||||
|
||||
// Network mode
|
||||
NetworkMode networkMode = NetworkMode::JOIN_NETWORK;
|
||||
bool isApMode = false;
|
||||
|
||||
// Web server - owned by this activity
|
||||
std::unique_ptr<CrossPointWebServer> webServer;
|
||||
|
||||
// Server status
|
||||
std::string connectedIP;
|
||||
std::string connectedSSID;
|
||||
std::string connectedSSID; // For STA mode: network name, For AP mode: AP name
|
||||
|
||||
// Performance monitoring
|
||||
unsigned long lastHandleClientTime = 0;
|
||||
@@ -47,7 +56,9 @@ class CrossPointWebServerActivity final : public ActivityWithSubactivity {
|
||||
void render() const;
|
||||
void renderServerRunning() const;
|
||||
|
||||
void onNetworkModeSelected(NetworkMode mode);
|
||||
void onWifiSelectionComplete(bool connected);
|
||||
void startAccessPoint();
|
||||
void startWebServer();
|
||||
void stopWebServer();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user