Skip to content

Commit ed71e54

Browse files
rdragonrydreasytarget
authored andcommitted
Mdns additions (#230)
* Update README.md * Make necessary changes to support MDNS name lookup of camera server * Remove note in README regarding the parent project
1 parent b1db350 commit ed71e54

File tree

3 files changed

+59
-47
lines changed

3 files changed

+59
-47
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ But expanded with:
1313
* Over The Air firmware updates
1414
* Lots of minor fixes and tweaks, documentation etc.
1515

16-
And 'reduced' by removing the Face Recognition features
16+
And 'reduced' by removing the Face Recognition features
1717
* **If you want to try the Face Recognition features** please use the [`3.x` maintenance branch](https://github.com/easytarget/esp32-cam-webserver/tree/3.x), which still recieves bugfixes, but is not receiving any further development.
1818
* They were a demo, only worked in low resolution modes, did not preserve the face database between power cycles, and were of little use in real-world applications.
1919
* There are other (specialised) sketches for the ESP-CAM that do use face recognitioni more effectively, if this is your thing :-)
@@ -33,7 +33,7 @@ I have four [AI-THINKER ESP32-CAM](https://github.com/raphaelbs/esp32-cam-ai-thi
3333
https://github.com/raphaelbs/esp32-cam-ai-thinker
3434
* The AI thinker wiki can be quite informative, when run through an online translator and read sensibly:
3535
https://wiki.ai-thinker.com/esp32-cam
36-
* Default pinouts are also included for WRover Kit, ESP Eye and M5Stack esp32 camera modules.
36+
* Default pinouts are also included for WRover Kit, ESP Eye and M5Stack esp32 camera modules.
3737
I do not have any of these boards, so they are untested by me. Please [let me know](https://github.com/easytarget/esp32-cam-webserver/issues) if you find issues or have a board not [in the list](./camera_pins.h).
3838

3939
## Troubleshooting:
@@ -74,7 +74,7 @@ Is pretty simple, You just need jumper wires, no soldering really required, see
7474
Download the latest release of the sketch from https://github.com/easytarget/esp32-cam-webserver/releases/latest
7575
- You can get the latest stable development release by cloning / downloading the `master` branch of the repo.
7676

77-
This will give you an archive file with the Version number in it, eg.`esp32-cam-webserver-3.0.zip`. Tou need to unpack this into your Arduino sketch folder, and then you need to rename the folder you just extracted to remove the version number, eg.`esp32-cam-webserver-3.0` becomes `esp32-cam-webserver`.
77+
This will give you an archive file with the Version number in it, eg.`esp32-cam-webserver-3.0.zip`. Tou need to unpack this into your Arduino sketch folder, and then you need to rename the folder you just extracted to remove the version number, eg.`esp32-cam-webserver-3.0` becomes `esp32-cam-webserver`.
7878

7979
Once you have done that you can open the sketch in the IDE by going to the `esp32-cam-webserver` sketch folder and selecting `esp32-cam-webserver.ino`.
8080

@@ -84,7 +84,7 @@ By default the sketch assumes you have an AI-THINKER board, it creates an Access
8484

8585
To make a permanent config with your home wifi settings, different defaults or a different board; copy (or rename) the file `myconfig.sample.h` in the sketch folder to `myconfig.h` and edit that, all the usable defaults are in that file. Because this is your private copy of the config it will not get overwritten if you update the main sketch!
8686

87-
### Programming
87+
### Programming
8888

8989
Assuming you are using the latest Espressif Arduino core the `ESP32 Dev Module` board will appear in the ESP32 Arduino section of the boards list. Select this (do not use the `AI-THINKER` entry listed in the boiards menu, it is not OTA compatible, and will caus the module to crash and reboot rather than updating if you use it.
9090
![IDE board config](Docs/ota-board-selection.png)
@@ -107,7 +107,7 @@ Go to the URL given in the serial output, the web UI should appear with the sett
107107

108108
The WiFi details can be stored in an (optional) header file to allow easier code development, and a camera name for the UI title can be configured. The lamp and status LED's are optional, and the lamp uses a exponential scale for brightness so that the control has some finess.
109109

110-
All of the face recognition code has been removed as of V4.0; this reduces the code size enough to allow OTA programming while improving compile and programming times.
110+
All of the face recognition code has been removed as of V4.0; this reduces the code size enough to allow OTA programming while improving compile and programming times.
111111

112112
The compressed and binary encoded HTML used in the example has been unpacked to raw text, this makes it much easier to access and modify the Javascript and UI elements. Given the relatively small size of the index page there is very little benefit from compressing it.
113113

@@ -141,17 +141,16 @@ Contributions are welcome; please see the [Contribution guidelines](CONTRIBUTING
141141

142142
Time allowing; my Current plan is:
143143

144-
V4
144+
V4
145145
* Remove face recognition entirely;
146146
* **Done**, see the `NoFace` branch :sunglasses:
147147
* Not optional, this is a code and maintenance nightmare. V3 can be maintained on a branch for those who need it.
148148
* Investigate using SD card to capture images
149149
* Implement OTA and a better network stack for remembering multiple AP's, auto-config etc.
150150
* **Basic OTA is Done**, see the `NoFace` branch.
151151
* Advanced (web upload) OTA might be nice to have if possible
152-
* For the Network setup I want to implement https://github.com/Hieromon/AutoConnect
152+
* For the Network setup I want to implement https://github.com/Hieromon/AutoConnect
153153
* UI Skinning/Theming
154154
* OSD
155155
* Temperature/humidity/pressure sensor support (bme20,dht11)
156156
You can check the [enhancement list](https://github.com/easytarget/esp32-cam-webserver/issues?q=is%3Aissue+label%3Aenhancement) (past and present), and add any thoughts you may have there.
157-

esp32-cam-webserver.ino

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <ArduinoOTA.h>
77
#include "src/parsebytes.h"
88
#include "time.h"
9+
#include <ESPmDNS.h>
910

1011

1112
/* This sketch is a extension/expansion/reork of the 'official' ESP32 Camera example
@@ -16,7 +17,7 @@
1617
* greater feedback via a status LED, and the HTML contents are present in plain text
1718
* for easy modification.
1819
*
19-
* A camera name can now be configured, and wifi details can be stored in an optional
20+
* A camera name can now be configured, and wifi details can be stored in an optional
2021
* header file to allow easier updated of the repo.
2122
*
2223
* The web UI has had changes to add the lamp control, rotation, a standalone viewer,
@@ -26,7 +27,7 @@
2627
*/
2728

2829

29-
/*
30+
/*
3031
* FOR NETWORK AND HARDWARE SETTINGS COPY OR RENAME 'myconfig.sample.h' TO 'myconfig.h' AND EDIT THAT.
3132
*
3233
* By default this sketch will assume an AI-THINKER ESP-CAM and create
@@ -42,7 +43,7 @@
4243
#warning "Using Defaults: Copy myconfig.sample.h to myconfig.h and edit that to use your own settings"
4344
#define WIFI_AP_ENABLE
4445
#define CAMERA_MODEL_AI_THINKER
45-
struct station { const char ssid[65]; const char password[65]; const bool dhcp;}
46+
struct station { const char ssid[65]; const char password[65]; const bool dhcp;}
4647
stationList[] = {{"ESP32-CAM-CONNECT","InsecurePassword", true}};
4748
#endif
4849

@@ -103,7 +104,7 @@ int stationCount = sizeof(stationList)/sizeof(stationList[0]);
103104

104105
// If we have AP mode enabled, ignore first entry in the stationList[]
105106
#if defined(WIFI_AP_ENABLE)
106-
int firstStation = 1;
107+
int firstStation = 1;
107108
#else
108109
int firstStation = 0;
109110
#endif
@@ -158,7 +159,7 @@ int myRotation = CAM_ROTATION;
158159
#else
159160
int lampVal = 0; //default to off
160161
#endif
161-
#else
162+
#else
162163
int lampVal = -1; // no lamp pin assigned
163164
#endif
164165

@@ -234,7 +235,7 @@ void handleSerial() {
234235
while (Serial.available()) Serial.read(); // chomp the buffer
235236
}
236237

237-
// Notification LED
238+
// Notification LED
238239
void flashLED(int flashtime) {
239240
#ifdef LED_PIN // If we have it; flash it.
240241
digitalWrite(LED_PIN, LED_ON); // On at full power.
@@ -297,7 +298,7 @@ void WifiSetup() {
297298
flashLED(300);
298299
Serial.println("Starting WiFi");
299300

300-
// Disable power saving on WiFi to improve responsiveness
301+
// Disable power saving on WiFi to improve responsiveness
301302
// (https://github.com/espressif/arduino-esp32/issues/1484)
302303
WiFi.setSleep(false);
303304

@@ -311,13 +312,13 @@ void WifiSetup() {
311312
byte mac[6] = {0,0,0,0,0,0};
312313
WiFi.macAddress(mac);
313314
Serial.printf("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
314-
315+
315316
int bestStation = -1;
316317
long bestRSSI = -1024;
317318
char bestSSID[65] = "";
318319
uint8_t bestBSSID[6];
319320
if (stationCount > firstStation) {
320-
// We have a list to scan
321+
// We have a list to scan
321322
Serial.printf("Scanning local Wifi Networks\r\n");
322323
int stationsFound = WiFi.scanNetworks();
323324
Serial.printf("%i networks found\r\n", stationsFound);
@@ -330,15 +331,15 @@ void WifiSetup() {
330331
Serial.printf("%3i : [%s] %s (%i)", i + 1, thisBSSID.c_str(), thisSSID.c_str(), thisRSSI);
331332
// Scan our list of known external stations
332333
for (int sta = firstStation; sta < stationCount; sta++) {
333-
if ((strcmp(stationList[sta].ssid, thisSSID.c_str()) == 0) ||
334+
if ((strcmp(stationList[sta].ssid, thisSSID.c_str()) == 0) ||
334335
(strcmp(stationList[sta].ssid, thisBSSID.c_str()) == 0)) {
335336
Serial.print(" - Known!");
336337
// Chose the strongest RSSI seen
337338
if (thisRSSI > bestRSSI) {
338339
bestStation = sta;
339340
strncpy(bestSSID, thisSSID.c_str(), 64);
340341
// Convert char bssid[] to a byte array
341-
parseBytes(thisBSSID.c_str(), ':', bestBSSID, 6, 16);
342+
parseBytes(thisBSSID.c_str(), ':', bestBSSID, 6, 16);
342343
bestRSSI = thisRSSI;
343344
}
344345
}
@@ -348,11 +349,11 @@ void WifiSetup() {
348349
}
349350
} else {
350351
// No list to scan, therefore we are an accesspoint
351-
accesspoint = true;
352+
accesspoint = true;
352353
}
353354

354355
if (bestStation == -1) {
355-
if (!accesspoint) {
356+
if (!accesspoint) {
356357
#if defined(WIFI_AP_ENABLE)
357358
Serial.println("No known networks found, entering AccessPoint fallback mode");
358359
accesspoint = true;
@@ -363,14 +364,14 @@ void WifiSetup() {
363364
Serial.println("AccessPoint mode selected in config");
364365
}
365366
} else {
366-
Serial.printf("Connecting to Wifi Network %d: [%02X:%02X:%02X:%02X:%02X:%02X] %s \r\n",
367-
bestStation, bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3],
367+
Serial.printf("Connecting to Wifi Network %d: [%02X:%02X:%02X:%02X:%02X:%02X] %s \r\n",
368+
bestStation, bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3],
368369
bestBSSID[4], bestBSSID[5], bestSSID);
369370
// Apply static settings if necesscary
370371
if (stationList[bestStation].dhcp == false) {
371372
#if defined(ST_IP)
372373
Serial.println("Applying static IP settings");
373-
#if !defined (ST_GATEWAY) || !defined (ST_NETMASK)
374+
#if !defined (ST_GATEWAY) || !defined (ST_NETMASK)
374375
#error "You must supply both Gateway and NetMask when specifying a static IP address"
375376
#endif
376377
IPAddress staticIP(ST_IP);
@@ -400,7 +401,7 @@ void WifiSetup() {
400401
WiFi.begin(bestSSID, stationList[bestStation].password, 0, bestBSSID);
401402

402403
// Wait to connect, or timeout
403-
unsigned long start = millis();
404+
unsigned long start = millis();
404405
while ((millis() - start <= WIFI_WATCHDOG) && (WiFi.status() != WL_CONNECTED)) {
405406
delay(500);
406407
Serial.print('.');
@@ -495,7 +496,7 @@ void setup() {
495496
Serial.println("\r\nFatal Error; Halting");
496497
while (true) {
497498
Serial.println("No wifi details have been configured; we cannot connect to existing WiFi or start our own AccessPoint, there is no point in proceeding.");
498-
delay(5000);
499+
delay(5000);
499500
}
500501
}
501502

@@ -504,7 +505,7 @@ void setup() {
504505
digitalWrite(LED_PIN, LED_ON);
505506
#endif
506507

507-
// Create camera config structure; and populate with hardware and other defaults
508+
// Create camera config structure; and populate with hardware and other defaults
508509
camera_config_t config;
509510
config.ledc_channel = LEDC_CHANNEL_0;
510511
config.ledc_timer = LEDC_TIMER_0;
@@ -560,7 +561,7 @@ void setup() {
560561
critERR += "<p>We will continue to reboot once per minute since this error sometimes clears automatically.</p>";
561562
// Start a 60 second watchdog timer
562563
esp_task_wdt_init(60,true);
563-
esp_task_wdt_add(NULL);
564+
esp_task_wdt_add(NULL);
564565
} else {
565566
Serial.println("Camera init succeeded");
566567

@@ -607,7 +608,7 @@ void setup() {
607608
/*
608609
* Add any other defaults you want to apply at startup here:
609610
* uncomment the line and set the value as desired (see the comments)
610-
*
611+
*
611612
* these are defined in the esp headers here:
612613
* https://github.com/espressif/esp32-camera/blob/master/driver/include/sensor.h#L149
613614
*/
@@ -675,7 +676,7 @@ void setup() {
675676
// Start OTA once connected
676677
Serial.println("Setting up OTA");
677678
// Port defaults to 3232
678-
// ArduinoOTA.setPort(3232);
679+
// ArduinoOTA.setPort(3232);
679680
// Hostname defaults to esp3232-[MAC]
680681
ArduinoOTA.setHostname(myName);
681682
// No authentication by default
@@ -712,8 +713,17 @@ void setup() {
712713
ArduinoOTA.begin();
713714
} else {
714715
Serial.println("OTA is disabled");
716+
717+
if (!MDNS.begin(myName)) {
718+
Serial.println("Error setting up MDNS responder!");
719+
}
720+
Serial.println("mDNS responder started");
715721
}
716722

723+
//MDNS Config -- note that if OTA is NOT enabled this needs prior steps!
724+
MDNS.addService("http", "tcp", 80);
725+
Serial.println("Added HTTP service to MDNS server");
726+
717727
// Set time via NTP server when enabled
718728
if (haveTime) {
719729
Serial.print("Time: ");
@@ -758,7 +768,7 @@ void setup() {
758768
}
759769

760770
void loop() {
761-
/*
771+
/*
762772
* Just loop forever, reconnecting Wifi As necesscary in client mode
763773
* The stream and URI handler processes initiated by the startCameraServer() call at the
764774
* end of setup() will handle the camera and UI processing from now on.
@@ -774,12 +784,12 @@ void loop() {
774784
if (captivePortal) dnsServer.processNextRequest();
775785
}
776786
} else {
777-
// client mode can fail; so reconnect as appropriate
787+
// client mode can fail; so reconnect as appropriate
778788
static bool warned = false;
779789
if (WiFi.status() == WL_CONNECTED) {
780790
// We are connected, wait a bit and re-check
781791
if (warned) {
782-
// Tell the user if we have just reconnected
792+
// Tell the user if we have just reconnected
783793
Serial.println("WiFi reconnected");
784794
warned = false;
785795
}

myconfig.sample.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
/*
1+
/*
22
* Rename this example to 'myconfig.h' and fill in your details.
3-
*
3+
*
44
* The local config is in the '.gitignore' file, which helps to keep details secret.
55
*/
66

77

8-
/* Give the camera a name for the web interface */
8+
/* Give the camera a name for the web interface
9+
* A word of warning: This name is also used for OTA updates and MDNS addressing.
10+
* Pick something convenient!
11+
*/
912
#define CAM_NAME "ESP32 camera server"
1013

1114

1215
/*
1316
* WiFi Settings
14-
*
17+
*
1518
* For the simplest connection to an existing network
1619
* just replace your ssid and password in the line below.
1720
*/
@@ -31,18 +34,18 @@ struct station stationList[] = {{"ssid1", "pass1", true},
3134
* it will be used for the AccessPoint ssid and password. See the comments there for more.
3235
*
3336
* The 'dhcp' setting controls whether the station uses DHCP or static IP settings; if in doubt leave 'true'
34-
*
37+
*
3538
* You can also use a BSSID (eg: "2F:67:94:F5:BB:6A", a colon separated mac address string) in place of
3639
* the ssid to force connections to specific networks even when the ssid's collide,
3740
*/
3841

3942
/* Extended WiFi Settings */
4043

41-
/*
44+
/*
4245
* Hostname. Optional, uncomment and set if desired
4346
* - used in DHCP request when connecting to networks, not used in AP mode
4447
* - Most useful when used with a static netwrk config, not all routers respect this setting
45-
*
48+
*
4649
* The URL_HOSTNAME will be used in place of the IP address in internal URL's
4750
*/
4851

@@ -51,22 +54,22 @@ struct station stationList[] = {{"ssid1", "pass1", true},
5154

5255
/*
5356
* Static network settings for client mode
54-
*
57+
*
5558
* Note: The same settings will be applied to all client connections where the dhcp setting is 'false'
5659
* You must define all three: IP, Gateway and NetMask
5760
*/
5861
// warning - IP addresses must be separated with commas (,) and not decimals (.)
5962
// #define ST_IP 192,168,0,123
60-
// #define ST_GATEWAY 192,168,0,2
63+
// #define ST_GATEWAY 192,168,0,2
6164
// #define ST_NETMASK 255,255,255,0
6265
// One or two DNS servers can be supplied, only the NTP code currently uses them
6366
// #define ST_DNS1 192,168,0,2
6467
// #define ST_DNS2 8,8,8,8
6568

66-
/*
67-
* AccessPoint;
69+
/*
70+
* AccessPoint;
6871
*
69-
* Uncomment to enable AP mode;
72+
* Uncomment to enable AP mode;
7073
*
7174
*/
7275
// #define WIFI_AP_ENABLE
@@ -79,7 +82,7 @@ struct station stationList[] = {{"ssid1", "pass1", true},
7982
* if they are found. AP then works as a fallback mode for when there are no 'real' networks available.
8083
*
8184
* Setting the 'dhcp' field to true for the AP enables a captive portal and attempts to send
82-
* all visitors to the webcam page, with varying degrees of success depending on the visitors
85+
* all visitors to the webcam page, with varying degrees of success depending on the visitors
8386
* browser and other settings.
8487
*/
8588
// Optionally change the AccessPoint ip address (default = 192.168.4.1)
@@ -185,7 +188,7 @@ struct station stationList[] = {{"ssid1", "pass1", true},
185188
// #define CAMERA_MODEL_ARDUCAM_ESP32S_UNO
186189

187190
// Camera module bus communications frequency, setting too high can cause visual artifacts.
188-
// Currently defaults to 16.5MHz, but some (non-clone) modules may be able to use the
191+
// Currently defaults to 16.5MHz, but some (non-clone) modules may be able to use the
189192
// original frequency of 20MHz for to allow higher framerates etc.
190193
// #define XCLK_FREQ_HZ 20000000;
191194
// For clone modules that have camera module artifacts and SPIFFS issues; try setting this very low:

0 commit comments

Comments
 (0)