Bladeren bron

#fix no parameters passed wihile creating ap

faqmoroz 1 week geleden
bovenliggende
commit
c2e0e968c6
3 gewijzigde bestanden met toevoegingen van 38 en 51 verwijderingen
  1. 29 31
      HTTPServer.cpp
  2. 7 18
      HTTPServer.h
  3. 2 2
      minolta_remote_v1.ino

+ 29 - 31
HTTPServer.cpp

@@ -1,14 +1,15 @@
 #include "HTTPServer.h"
+#include "Config.h"
 #include <Arduino.h>
 
 /// <summary>
-/// Constructs an HTTPServer instance with the specified port and shutter controller.
+/// Constructs an HTTPServer instance using Config::HTTP_PORT.
 /// Creates a new AsyncWebServer instance but does not start it yet.
 /// </summary>
-HTTPServer::HTTPServer(uint16_t port, IShutterController* controller)
+HTTPServer::HTTPServer(IShutterController* controller)
     : shutterController(controller)
 {
-    server = new AsyncWebServer(port);
+    server = new AsyncWebServer(Config::HTTP_PORT);
 }
 
 /// <summary>
@@ -23,17 +24,16 @@ HTTPServer::~HTTPServer()
 }
 
 /// <summary>
-/// Configures the ESP8266 as a WiFi access point with the provided credentials.
-/// Sets up the static IP configuration and starts the access point.
+/// Configures the ESP8266 as a WiFi access point using Config WiFi settings.
+/// Uses Config::WIFI_IP, Config::WIFI_GATEWAY, and Config::WIFI_SUBNET for softAPConfig.
 /// </summary>
-void HTTPServer::setupWiFiAP(const char* ssid, const char* password,
-                             IPAddress local_IP, IPAddress gateway, IPAddress subnet)
+void HTTPServer::setupWiFiAP()
 {
-    if (!WiFi.softAPConfig(local_IP, gateway, subnet))
+    if (!WiFi.softAPConfig(Config::WIFI_IP, Config::WIFI_GATEWAY, Config::WIFI_SUBNET))
     {
         Serial.println("Failed to config IP");
     }
-    WiFi.softAP(ssid, password);
+    WiFi.softAP(Config::WIFI_SSID, Config::WIFI_PASSWORD);
     Serial.println(WiFi.softAPIP());
     Serial.println("AP Started - Waiting for connections");
 }
@@ -187,19 +187,19 @@ void HTTPServer::handleRoot(AsyncWebServerRequest *request)
 </head>
 <body>
     <div class="container">
-        <h1>📷 Minolta Remote</h1>
+        <h1>Minolta Remote</h1>
         
         <div class="section">
             <h2>Basic Controls</h2>
-            <button class="btn-focus" onclick="sendRequest('/api/focus')">🎯 Focus</button>
-            <button class="btn-photo" onclick="sendRequest('/api/takePhoto')">📸 Take Photo</button>
-            <button class="btn-reset" onclick="sendRequest('/api/reset')">🔄 Reset</button>
+            <button class="btn-focus" onclick="sendRequest('/api/focus')">Focus</button>
+            <button class="btn-photo" onclick="sendRequest('/api/takePhoto')">Take Photo</button>
+            <button class="btn-reset" onclick="sendRequest('/api/reset')">Reset</button>
         </div>
         
         <div class="section">
             <h2>Photo Hold Duration</h2>
             <input type="number" id="msec" min="100" max="5000" value="1000" placeholder="Duration (ms)">
-            <button class="btn-photo" onclick="takePhotoWithDelay()">📸 Take with Delay</button>
+            <button class="btn-photo" onclick="takePhotoWithDelay()">Take with Delay</button>
         </div>
         
         <div class="section">
@@ -211,7 +211,7 @@ void HTTPServer::handleRoot(AsyncWebServerRequest *request)
             <div class="input-group">
                 <input type="number" id="msecMulti" min="100" max="5000" value="1000" placeholder="Duration (ms)">
             </div>
-            <button class="btn-multiple" onclick="multipleShoot()">🎬 Multiple Shots</button>
+            <button class="btn-multiple" onclick="multipleShoot()">Multiple Shots</button>
         </div>
         
         <div id="status" class="status"></div>
@@ -222,12 +222,12 @@ void HTTPServer::handleRoot(AsyncWebServerRequest *request)
             fetch(endpoint)
                 .then(response => {
                     if (response.ok) {
-                        showStatus('Success: ' + endpoint, 'success');
+                        showStatus('Success: ' + endpoint, 'success');
                     } else {
-                        showStatus('Error: ' + response.statusText, 'error');
+                        showStatus('Error: ' + response.statusText, 'error');
                     }
                 })
-                .catch(error => showStatus('Connection Error', 'error'));
+                .catch(error => showStatus('Connection Error', 'error'));
         }
 
         function takePhotoWithDelay() {
@@ -235,12 +235,12 @@ void HTTPServer::handleRoot(AsyncWebServerRequest *request)
             fetch('/api/takePhoto?msec=' + msec)
                 .then(response => {
                     if (response.ok) {
-                        showStatus('Photo taken (' + msec + 'ms)', 'success');
+                        showStatus('Photo taken (' + msec + 'ms)', 'success');
                     } else {
-                        showStatus('Error taking photo', 'error');
+                        showStatus('Error taking photo', 'error');
                     }
                 })
-                .catch(error => showStatus('Connection Error', 'error'));
+                .catch(error => showStatus('Connection Error', 'error'));
         }
 
         function multipleShoot() {
@@ -249,19 +249,19 @@ void HTTPServer::handleRoot(AsyncWebServerRequest *request)
             const msec = document.getElementById('msecMulti').value;
             
             if (count < 1 || count > 100) {
-                showStatus('Count must be between 1 and 100', 'error');
+                showStatus('Count must be between 1 and 100', 'error');
                 return;
             }
             
             fetch('/api/multiple?count=' + count + '&delay=' + delay + '&msec=' + msec)
                 .then(response => {
                     if (response.ok) {
-                        showStatus('✓ ' + count + ' shots queued', 'success');
+                        showStatus(count + ' shots queued', 'success');
                     } else {
-                        showStatus('Error taking photos', 'error');
+                        showStatus('Error taking photos', 'error');
                     }
                 })
-                .catch(error => showStatus('Connection Error', 'error'));
+                .catch(error => showStatus('Connection Error', 'error'));
         }
 
         function showStatus(message, type) {
@@ -383,14 +383,12 @@ void HTTPServer::onRequestEnd(const char* endpoint)
 }
 
 /// <summary>
-/// Initializes the WiFi access point and starts the HTTP server.
-/// Must be called during application setup to enable the server.
-/// Calls setupWiFiAP() to configure WiFi, setupRoutes() to register endpoints, and starts the server.
+/// Initializes the WiFi access point using Config settings and starts the HTTP server.
+/// Calls setupWiFiAP() to configure WiFi, then setupRoutes() to register API endpoints.
 /// </summary>
-void HTTPServer::begin(const char* ssid, const char* password,
-                       IPAddress local_IP, IPAddress gateway, IPAddress subnet)
+void HTTPServer::begin()
 {
-    setupWiFiAP(ssid, password, local_IP, gateway, subnet);
+    setupWiFiAP();
     setupRoutes();
     server->begin();
     Serial.println("HTTP Server started");

+ 7 - 18
HTTPServer.h

@@ -76,11 +76,10 @@ private:
     
 public:
     /// <summary>
-    /// Constructs an HTTPServer instance.
+    /// Constructs an HTTPServer instance using Config::HTTP_PORT.
     /// </summary>
-    /// <param name="port">HTTP server port number (typically 80)</param>
     /// <param name="controller">Pointer to ShutterController for camera operations</param>
-    HTTPServer(uint16_t port, IShutterController* controller);
+    HTTPServer(IShutterController* controller);
     
     /// <summary>
     /// Destructor that cleans up the AsyncWebServer instance.
@@ -89,26 +88,16 @@ public:
     
     /// <summary>
     /// Initializes the WiFi access point and starts the HTTP server.
+    /// Uses WiFi settings from Config class constants.
     /// Must be called during application setup.
     /// </summary>
-    /// <param name="ssid">WiFi network name</param>
-    /// <param name="password">WiFi network password</param>
-    /// <param name="local_IP">Static IP address for the access point</param>
-    /// <param name="gateway">Gateway IP address</param>
-    /// <param name="subnet">Subnet mask</param>
-    void begin(const char* ssid, const char* password, 
-               IPAddress local_IP, IPAddress gateway, IPAddress subnet);
+    void begin();
     
     /// <summary>
-    /// Configures the ESP8266 as a WiFi access point with the specified credentials.
+    /// Configures the ESP8266 as a WiFi access point using Config WiFi settings.
+    /// Uses Config::WIFI_SSID, Config::WIFI_PASSWORD, Config::WIFI_IP, Config::WIFI_GATEWAY, and Config::WIFI_SUBNET.
     /// </summary>
-    /// <param name="ssid">WiFi network name</param>
-    /// <param name="password">WiFi network password</param>
-    /// <param name="local_IP">Static IP address for the access point</param>
-    /// <param name="gateway">Gateway IP address</param>
-    /// <param name="subnet">Subnet mask</param>
-    void setupWiFiAP(const char* ssid, const char* password,
-                     IPAddress local_IP, IPAddress gateway, IPAddress subnet);
+    void setupWiFiAP();
 };
 
 #endif // HTTP_SERVER_H

+ 2 - 2
minolta_remote_v1.ino

@@ -108,8 +108,8 @@ void setup() {
   shutterController = new ShutterController(D1, D2);
   
   // Initialize HTTPServer
-  httpServer = new HTTPServer(Config::HTTP_PORT, shutterController);
-  httpServer->begin(ssid, password, local_IP, gateway, subnet);
+  httpServer = new HTTPServer(shutterController);
+  httpServer->begin();
 }
 
 /// <summary>