User Tools

Site Tools


splitbasicotantpserverdebugwebserial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
splitbasicotantpserverdebugwebserial [2025/03/01 02:58] – jwansplitbasicotantpserverdebugwebserial [2025/10/10 10:15] (current) – external edit 127.0.0.1
Line 42: Line 42:
 const char* password = "YOUR_PASSWORD"; const char* password = "YOUR_PASSWORD";
 const char* hostname = "HOSTNAME"; const char* hostname = "HOSTNAME";
 +String IPaddr;
 +
  
 // Function to initialize WiFi // Function to initialize WiFi
Line 49: Line 51:
   while (WiFi.status() != WL_CONNECTED) {   while (WiFi.status() != WL_CONNECTED) {
     delay(500);     delay(500);
-    Serial.print(".");+    debug(".");
   }   }
-  Serial.println("\nConnected to WiFi"); +  IPaddr = WiFi.localIP().toString(); 
-  Serial.print("IP address: "); +  debugln("\nConnected to WiFi"); 
-  Serial.println(WiFi.localIP());+  debug("IP address: "); 
 +  debugln(IPaddr);
 } }
 +
 +#endif
  
 #endif #endif
Line 121: Line 126:
 </html> </html>
 )rawliteral"; )rawliteral";
 +
 +void handleRoot(AsyncWebServerRequest *request) {
 +    String message = "<html><body>"; 
 +    message += "<h1>ESP32-CAM Project: IoT Clock</h1>"; 
 +    message += "Hostname: " + String(hostname) + "<br>"; 
 +    message += "IP Address: " + IPaddr + "<br>"; 
 +    message += "ElegantOTA ready for <a href=\"/update\">firmware updates</a>.<br>"; 
 +    message += "</body></html>"; 
 +    request->send(200, "text/html", message);
 +  }
  
 // Function to initialize the web server // Function to initialize the web server
 void webServerInit() { void webServerInit() {
   // Route for root / web page   // Route for root / web page
-  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){+  server.on("/", HTTP_GET, handleRoot); 
 +  server.on("/time", HTTP_GET, [](AsyncWebServerRequest *request){
     request->send_P(200, "text/html", index_html);     request->send_P(200, "text/html", index_html);
   });   });
Line 132: Line 148:
   events.onConnect([](AsyncEventSourceClient *client){   events.onConnect([](AsyncEventSourceClient *client){
     if(client->lastId()){     if(client->lastId()){
-      Serial.printf("Client reconnected! Last message ID: %u\n", client->lastId());+      debugln("Client reconnected! Last message ID: %u\n", client->lastId());
     }     }
     client->send("hello!", NULL, millis(), 1000);     client->send("hello!", NULL, millis(), 1000);
Line 156: Line 172:
 // Declare and define NTP objects // Declare and define NTP objects
 WiFiUDP ntpUDP; WiFiUDP ntpUDP;
-NTPClient timeClient(ntpUDP, "pool.ntp.org", 28800, 60000); // GMT+8+NTPClient timeClient(ntpUDP, "ntp.pagasa.dost.gov.ph", 28800, 60000); // Update every 60 seconds
  
 // Function to initialize NTP // Function to initialize NTP
splitbasicotantpserverdebugwebserial.1740797919.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki