User Tools

Site Tools


splitbasicotantpserverdebugwebserial

Differences

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

Link to this comparison view

Next revision
Previous revision
splitbasicotantpserverdebugwebserial [2025/03/01 00:59] – created jwansplitbasicotantpserverdebugwebserial [2025/10/10 10:15] (current) – external edit 127.0.0.1
Line 41: Line 41:
 const char* ssid = "YOUR_SSID"; const char* ssid = "YOUR_SSID";
 const char* password = "YOUR_PASSWORD"; const char* password = "YOUR_PASSWORD";
 +const char* hostname = "HOSTNAME";
 +String IPaddr;
 +
  
 // Function to initialize WiFi // Function to initialize WiFi
 void wifiInit() { void wifiInit() {
 +  WiFi.hostname(hostname);
   WiFi.begin(ssid, password);   WiFi.begin(ssid, password);
   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 119: 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 130: 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 154: 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.1740790792.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki