Skip to content

Commit

Permalink
Mdns additions (#230)
Browse files Browse the repository at this point in the history
* Update README.md
* Make necessary changes to support MDNS name lookup of camera server
* Remove note in README regarding the parent project
  • Loading branch information
rdragonrydr authored and easytarget committed Mar 9, 2022
1 parent b1db350 commit ed71e54
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 47 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ But expanded with:
* Over The Air firmware updates
* Lots of minor fixes and tweaks, documentation etc.

And 'reduced' by removing the Face Recognition features
And 'reduced' by removing the Face Recognition features
* **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.
* 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.
* There are other (specialised) sketches for the ESP-CAM that do use face recognitioni more effectively, if this is your thing :-)
Expand All @@ -33,7 +33,7 @@ I have four [AI-THINKER ESP32-CAM](https://github.com/raphaelbs/esp32-cam-ai-thi
https://github.com/raphaelbs/esp32-cam-ai-thinker
* The AI thinker wiki can be quite informative, when run through an online translator and read sensibly:
https://wiki.ai-thinker.com/esp32-cam
* Default pinouts are also included for WRover Kit, ESP Eye and M5Stack esp32 camera modules.
* Default pinouts are also included for WRover Kit, ESP Eye and M5Stack esp32 camera modules.
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).

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

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`.
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`.

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`.

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

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!

### Programming
### Programming

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.
![IDE board config](Docs/ota-board-selection.png)
Expand All @@ -107,7 +107,7 @@ Go to the URL given in the serial output, the web UI should appear with the sett

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.

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.
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.

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.

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

Time allowing; my Current plan is:

V4
V4
* Remove face recognition entirely;
* **Done**, see the `NoFace` branch :sunglasses:
* Not optional, this is a code and maintenance nightmare. V3 can be maintained on a branch for those who need it.
* Investigate using SD card to capture images
* Implement OTA and a better network stack for remembering multiple AP's, auto-config etc.
* **Basic OTA is Done**, see the `NoFace` branch.
* Advanced (web upload) OTA might be nice to have if possible
* For the Network setup I want to implement https://github.com/Hieromon/AutoConnect
* For the Network setup I want to implement https://github.com/Hieromon/AutoConnect
* UI Skinning/Theming
* OSD
* Temperature/humidity/pressure sensor support (bme20,dht11)
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.

60 changes: 35 additions & 25 deletions esp32-cam-webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ArduinoOTA.h>
#include "src/parsebytes.h"
#include "time.h"
#include <ESPmDNS.h>


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


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

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

// If we have AP mode enabled, ignore first entry in the stationList[]
#if defined(WIFI_AP_ENABLE)
int firstStation = 1;
int firstStation = 1;
#else
int firstStation = 0;
#endif
Expand Down Expand Up @@ -158,7 +159,7 @@ int myRotation = CAM_ROTATION;
#else
int lampVal = 0; //default to off
#endif
#else
#else
int lampVal = -1; // no lamp pin assigned
#endif

Expand Down Expand Up @@ -234,7 +235,7 @@ void handleSerial() {
while (Serial.available()) Serial.read(); // chomp the buffer
}

// Notification LED
// Notification LED
void flashLED(int flashtime) {
#ifdef LED_PIN // If we have it; flash it.
digitalWrite(LED_PIN, LED_ON); // On at full power.
Expand Down Expand Up @@ -297,7 +298,7 @@ void WifiSetup() {
flashLED(300);
Serial.println("Starting WiFi");

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

Expand All @@ -311,13 +312,13 @@ void WifiSetup() {
byte mac[6] = {0,0,0,0,0,0};
WiFi.macAddress(mac);
Serial.printf("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

int bestStation = -1;
long bestRSSI = -1024;
char bestSSID[65] = "";
uint8_t bestBSSID[6];
if (stationCount > firstStation) {
// We have a list to scan
// We have a list to scan
Serial.printf("Scanning local Wifi Networks\r\n");
int stationsFound = WiFi.scanNetworks();
Serial.printf("%i networks found\r\n", stationsFound);
Expand All @@ -330,15 +331,15 @@ void WifiSetup() {
Serial.printf("%3i : [%s] %s (%i)", i + 1, thisBSSID.c_str(), thisSSID.c_str(), thisRSSI);
// Scan our list of known external stations
for (int sta = firstStation; sta < stationCount; sta++) {
if ((strcmp(stationList[sta].ssid, thisSSID.c_str()) == 0) ||
if ((strcmp(stationList[sta].ssid, thisSSID.c_str()) == 0) ||
(strcmp(stationList[sta].ssid, thisBSSID.c_str()) == 0)) {
Serial.print(" - Known!");
// Chose the strongest RSSI seen
if (thisRSSI > bestRSSI) {
bestStation = sta;
strncpy(bestSSID, thisSSID.c_str(), 64);
// Convert char bssid[] to a byte array
parseBytes(thisBSSID.c_str(), ':', bestBSSID, 6, 16);
parseBytes(thisBSSID.c_str(), ':', bestBSSID, 6, 16);
bestRSSI = thisRSSI;
}
}
Expand All @@ -348,11 +349,11 @@ void WifiSetup() {
}
} else {
// No list to scan, therefore we are an accesspoint
accesspoint = true;
accesspoint = true;
}

if (bestStation == -1) {
if (!accesspoint) {
if (!accesspoint) {
#if defined(WIFI_AP_ENABLE)
Serial.println("No known networks found, entering AccessPoint fallback mode");
accesspoint = true;
Expand All @@ -363,14 +364,14 @@ void WifiSetup() {
Serial.println("AccessPoint mode selected in config");
}
} else {
Serial.printf("Connecting to Wifi Network %d: [%02X:%02X:%02X:%02X:%02X:%02X] %s \r\n",
bestStation, bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3],
Serial.printf("Connecting to Wifi Network %d: [%02X:%02X:%02X:%02X:%02X:%02X] %s \r\n",
bestStation, bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3],
bestBSSID[4], bestBSSID[5], bestSSID);
// Apply static settings if necesscary
if (stationList[bestStation].dhcp == false) {
#if defined(ST_IP)
Serial.println("Applying static IP settings");
#if !defined (ST_GATEWAY) || !defined (ST_NETMASK)
#if !defined (ST_GATEWAY) || !defined (ST_NETMASK)
#error "You must supply both Gateway and NetMask when specifying a static IP address"
#endif
IPAddress staticIP(ST_IP);
Expand Down Expand Up @@ -400,7 +401,7 @@ void WifiSetup() {
WiFi.begin(bestSSID, stationList[bestStation].password, 0, bestBSSID);

// Wait to connect, or timeout
unsigned long start = millis();
unsigned long start = millis();
while ((millis() - start <= WIFI_WATCHDOG) && (WiFi.status() != WL_CONNECTED)) {
delay(500);
Serial.print('.');
Expand Down Expand Up @@ -495,7 +496,7 @@ void setup() {
Serial.println("\r\nFatal Error; Halting");
while (true) {
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.");
delay(5000);
delay(5000);
}
}

Expand All @@ -504,7 +505,7 @@ void setup() {
digitalWrite(LED_PIN, LED_ON);
#endif

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

Expand Down Expand Up @@ -607,7 +608,7 @@ void setup() {
/*
* Add any other defaults you want to apply at startup here:
* uncomment the line and set the value as desired (see the comments)
*
*
* these are defined in the esp headers here:
* https://github.com/espressif/esp32-camera/blob/master/driver/include/sensor.h#L149
*/
Expand Down Expand Up @@ -675,7 +676,7 @@ void setup() {
// Start OTA once connected
Serial.println("Setting up OTA");
// Port defaults to 3232
// ArduinoOTA.setPort(3232);
// ArduinoOTA.setPort(3232);
// Hostname defaults to esp3232-[MAC]
ArduinoOTA.setHostname(myName);
// No authentication by default
Expand Down Expand Up @@ -712,8 +713,17 @@ void setup() {
ArduinoOTA.begin();
} else {
Serial.println("OTA is disabled");

if (!MDNS.begin(myName)) {
Serial.println("Error setting up MDNS responder!");
}
Serial.println("mDNS responder started");
}

//MDNS Config -- note that if OTA is NOT enabled this needs prior steps!
MDNS.addService("http", "tcp", 80);
Serial.println("Added HTTP service to MDNS server");

// Set time via NTP server when enabled
if (haveTime) {
Serial.print("Time: ");
Expand Down Expand Up @@ -758,7 +768,7 @@ void setup() {
}

void loop() {
/*
/*
* Just loop forever, reconnecting Wifi As necesscary in client mode
* The stream and URI handler processes initiated by the startCameraServer() call at the
* end of setup() will handle the camera and UI processing from now on.
Expand All @@ -774,12 +784,12 @@ void loop() {
if (captivePortal) dnsServer.processNextRequest();
}
} else {
// client mode can fail; so reconnect as appropriate
// client mode can fail; so reconnect as appropriate
static bool warned = false;
if (WiFi.status() == WL_CONNECTED) {
// We are connected, wait a bit and re-check
if (warned) {
// Tell the user if we have just reconnected
// Tell the user if we have just reconnected
Serial.println("WiFi reconnected");
warned = false;
}
Expand Down
31 changes: 17 additions & 14 deletions myconfig.sample.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
/*
/*
* Rename this example to 'myconfig.h' and fill in your details.
*
*
* The local config is in the '.gitignore' file, which helps to keep details secret.
*/


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


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

/* Extended WiFi Settings */

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

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

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

/*
* AccessPoint;
/*
* AccessPoint;
*
* Uncomment to enable AP mode;
* Uncomment to enable AP mode;
*
*/
// #define WIFI_AP_ENABLE
Expand All @@ -79,7 +82,7 @@ struct station stationList[] = {{"ssid1", "pass1", true},
* if they are found. AP then works as a fallback mode for when there are no 'real' networks available.
*
* Setting the 'dhcp' field to true for the AP enables a captive portal and attempts to send
* all visitors to the webcam page, with varying degrees of success depending on the visitors
* all visitors to the webcam page, with varying degrees of success depending on the visitors
* browser and other settings.
*/
// Optionally change the AccessPoint ip address (default = 192.168.4.1)
Expand Down Expand Up @@ -185,7 +188,7 @@ struct station stationList[] = {{"ssid1", "pass1", true},
// #define CAMERA_MODEL_ARDUCAM_ESP32S_UNO

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

0 comments on commit ed71e54

Please sign in to comment.