Created
June 18, 2025 20:57
-
-
Save juancamiloqhz/a360d0d572369a76d2292657e2231817 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <WiFi.h> | |
| #include <ESPmDNS.h> | |
| // --- Configuration --- | |
| const char* ssid = "YOUR_WIFI_SSID"; // This will be set by the user | |
| const char* password = "YOUR_WIFI_PASSWORD"; // This will be set by the user | |
| const char* mdns_hostname = "esp32-cam"; // The base .local hostname | |
| const int stream_port = 81; // The port for the video stream | |
| void setup() { | |
| Serial.begin(115200); | |
| // --- Connect to WiFi --- | |
| WiFi.begin(ssid, password); | |
| while (WiFi.status() != WL_CONNECTED) { | |
| delay(500); | |
| Serial.print("."); | |
| } | |
| Serial.println("\nWiFi connected!"); | |
| Serial.println(WiFi.localIP()); | |
| // --- Initialize mDNS --- | |
| if (!MDNS.begin(mdns_hostname)) { | |
| Serial.println("Error setting up MDNS responder!"); | |
| while(1) { delay(1000); } | |
| } | |
| Serial.println("mDNS responder started."); | |
| // --- Advertise the Camera Service --- | |
| // My app will be looking for the "_camera._tcp" service type. | |
| MDNS.addService("camera", "tcp", stream_port); | |
| // --- Add the required TXT records for metadata --- | |
| MDNS.addServiceTxt("camera", "tcp", "model", "ESP32-S-CAM"); | |
| MDNS.addServiceTxt("camera", "tcp", "fw_version", "1.0.0"); | |
| MDNS.addServiceTxt("camera", "tcp", "path", "/stream"); | |
| Serial.printf("Service 'camera' advertised on port %d\n", stream_port); | |
| // ======================================================= | |
| // YOUR CAMERA AND VIDEO STREAMING SERVER CODE GOES HERE | |
| // Ensure it's running on the `stream_port` defined above. | |
| // ======================================================= | |
| } | |
| void loop() { | |
| // Main loop | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment