kopia lustrzana https://github.com/alanesq/esp32cam-demo
Porównaj commity
6 Commity
bb88928f97
...
eb0271b549
Autor | SHA1 | Data |
---|---|---|
Alan | eb0271b549 | |
Alan | 36edc58ddd | |
Alan | c0e2ebe008 | |
Alan | e589297db3 | |
Alan | 9433d83b88 | |
Alan | bc20c99340 |
|
@ -11,7 +11,10 @@
|
|||
* flash led is still available for use (pin 4) and does not flash when accessing sd card
|
||||
* Stores image in Spiffs if no sd card present
|
||||
* PWM control of the illumination/flash LED
|
||||
* Shows how to read the raw image data (greyscale and RGB)
|
||||
*
|
||||
* If ota.h file is in the sketch folder you can enable OTA updating of this sketch by setting '#define ENABLE_OTA 1'
|
||||
* in settings section. You can then update the sketch with a BIN file via OTA by accessing page http://x.x.x.x/ota
|
||||
* This can make updating the sketch more convenient, especially if you have installed the camera in a case etc.
|
||||
*
|
||||
* GPIO:
|
||||
* You can use io pins 13 and 12 for input or output (but 12 must not be high at boot)
|
||||
|
@ -59,10 +62,10 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
|
||||
// forward declarations (this is a list of all procedures in this sketch which Platform IO requires)
|
||||
// forward declarations
|
||||
bool initialiseCamera(bool); // this sets up and enables the camera (if bool=1 standard settings are applied but 0 allows you to apply custom settings)
|
||||
bool cameraImageSettings(); // this applies the image settings to the camera (brightness etc.)
|
||||
void changeResolution(framesize_t); // this changes the capture frame size
|
||||
void changeResolution(); // this changes the capture frame size
|
||||
String localTime(); // returns the current time as a String
|
||||
void flashLED(int); // flashes the onboard indicator led
|
||||
byte storeImage(); // stores an image in Spiffs or SD card
|
||||
|
@ -91,6 +94,9 @@
|
|||
char* stitle = "ESP32Cam-demo"; // title of this sketch
|
||||
char* sversion = "16oct23"; // Sketch version
|
||||
|
||||
#define ENABLE_OTA 0 // If OTA updating of this sketch is enabled (requires ota.h)
|
||||
const String OTAPassword = "password"; // Password reuired to enable OTA (supplied as - http://<ip address>?pwd=xxxx )
|
||||
|
||||
bool sendRGBfile = 0; // if set '/rgb' will just return raw rgb data which can be saved as a file rather than display a HTML pag
|
||||
|
||||
uint16_t dataRefresh = 2; // how often to refresh data on root web page (seconds)
|
||||
|
@ -111,6 +117,7 @@
|
|||
int cameraImageExposure = 0; // Camera exposure (0 - 1200) If gain and exposure both set to zero then auto adjust is enabled
|
||||
int cameraImageGain = 0; // Image gain (0 - 30)
|
||||
int cameraImageBrightness = 0; // Image brightness (-2 to +2)
|
||||
const int camChangeDelay = 200; // delay when deinit camera executed
|
||||
|
||||
const int TimeBetweenStatus = 600; // speed of flashing system running ok status light (milliseconds)
|
||||
|
||||
|
@ -204,6 +211,13 @@ WebServer server(80); // serve web pages on port 80
|
|||
String spiffsFilename = "/image.jpg"; // image name to use when storing in spiffs
|
||||
String ImageResDetails = "Unknown"; // image resolution info
|
||||
|
||||
#if ENABLE_OTA
|
||||
// OTA Stuff
|
||||
void sendHeader(WiFiClient &client, char* hTitle); // forward declarations
|
||||
void sendFooter(WiFiClient &client);
|
||||
bool OTAEnabled = 0; // flag to show if OTA has been enabled (via supply of password in http://x.x.x.x/ota)
|
||||
#include "ota.h" // Over The Air updates (OTA)
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// -SETUP SETUP SETUP SETUP SETUP SETUP
|
||||
|
@ -261,6 +275,9 @@ void setup() {
|
|||
server.on("/test", handleTest); // Testing procedure
|
||||
server.on("/reboot", handleReboot); // restart device
|
||||
server.onNotFound(handleNotFound); // invalid url requested
|
||||
#if ENABLE_OTA
|
||||
server.on("/ota", handleOTA); // ota updates web page
|
||||
#endif
|
||||
|
||||
// NTP - internet time
|
||||
if (serialDebug) Serial.println("\nGetting real time (NTP)");
|
||||
|
@ -657,7 +674,7 @@ void resetCamera(bool type = 0) {
|
|||
} else {
|
||||
// reset via software (handy if you wish to change resolution or image type etc. - see test procedure)
|
||||
esp_camera_deinit();
|
||||
delay(50);
|
||||
delay(camChangeDelay);
|
||||
initialiseCamera(1);
|
||||
}
|
||||
}
|
||||
|
@ -676,7 +693,7 @@ void changeResolution() {
|
|||
const int noAvail = sizeof(cyclingRes) / sizeof(cyclingRes[0]);
|
||||
static int currentRes = 0;
|
||||
esp_camera_deinit(); // disable camera
|
||||
delay(200);
|
||||
delay(camChangeDelay);
|
||||
currentRes++; // change to next resolution available
|
||||
if (currentRes >= noAvail) currentRes=0; // reset loop
|
||||
FRAME_SIZE_IMAGE = cyclingRes[currentRes];
|
||||
|
@ -929,6 +946,9 @@ void handleRoot() {
|
|||
// client.printf("<p>Touch on pin 12: %d </p>\n", touchRead(T5) );
|
||||
// client.printf("<p>Touch on pin 13: %d </p>\n", touchRead(T4) );
|
||||
|
||||
// OTA
|
||||
if (OTAEnabled) client.write("<br>OTA IS ENABLED!");
|
||||
|
||||
// Control buttons
|
||||
client.write("<br><br>");
|
||||
client.write("<input style='height: 35px;' name='button1' value='Toggle pin 12' type='submit'> \n");
|
||||
|
@ -1589,7 +1609,7 @@ void readGreyscaleImage() {
|
|||
|
||||
// change camera to greyscale mode (by default it is in JPG colour mode)
|
||||
esp_camera_deinit(); // disable camera
|
||||
delay(50);
|
||||
delay(camChangeDelay);
|
||||
config.pixel_format = PIXFORMAT_GRAYSCALE; // change camera setting to greyscale (default is JPG)
|
||||
initialiseCamera(0); // restart the camera (0 = without resetting all the other camera settings)
|
||||
|
||||
|
@ -1648,7 +1668,7 @@ void readGreyscaleImage() {
|
|||
|
||||
// change camera back to JPG mode
|
||||
esp_camera_deinit();
|
||||
delay(50);
|
||||
delay(camChangeDelay);
|
||||
initialiseCamera(1); // reset settings (1=apply the cameras settings which includes JPG mode)
|
||||
}
|
||||
|
||||
|
|
12
README.md
12
README.md
|
@ -1,11 +1,12 @@
|
|||
|
||||
Note: I seem to have having trouble with XGA with more recent versions (i.e. 1024x768)
|
||||
|
||||
## ESP32Cam-demo sketch for use with the Arduino IDE or PlatformIO
|
||||
|
||||
I show in this sketch how to use the esp32cam as easily as possible. Everything I learn I try to add to it, please let me know if you have anything which you think can be added or changed to improve it - I am not a professional programmer so am sure there is plenty of room for improvement...
|
||||
<br>It is just a collection of all I have discovered/learned in the process of using them myself<br><br>
|
||||
Note: There is a version of this sketch with OTA updates included here: https://github.com/alanesq/esp32cam-demo/blob/master/esp32CamDemo-OTA_version.zip<br>
|
||||
Note: This sketch now has the facilty for OTA updates over the network, you need to copy the file ota.h in to your sketch folder and enable it in settings (#define ENABLE_OTA 1)
|
||||
<br><br>If you have issues with the camera keep stopping working I have had a couple of these with dodgy camera modules so it is worth trying another one to see if this is the
|
||||
source of your problems.
|
||||
<br>
|
||||
|
||||
<table><tr>
|
||||
<td><img src="/images/root.png" /></td>
|
||||
|
@ -37,9 +38,10 @@ It looks like the esp32cam suplied with them are not standard and have one of th
|
|||
So on esp32cam modules without this feature you have to plug the USB in whilst holding the program button to upload a sketch
|
||||
I find I have to use the lowest serial upload speed or it fails (Select 'ESP32 dev module' in the Arduino IDE to have the option and
|
||||
make sure PSRam is enabled).
|
||||
There is also now a esp32cam with built in USB available called the "ESP32-CAM-CH340".
|
||||
The wifi is very poor whilst in the motherboard (I find this happens if you have something near the antenna on the esp32cam modules)
|
||||
The wifi can be very poor whilst in the motherboard (I find this happens if you have something near the antenna on the esp32cam modules)
|
||||
but if I rest my thumb above the antenna I find the signal works ok).
|
||||
There is also now a esp32cam with built in USB available called the "ESP32-CAM-CH340" which has built in USB this also seems to struggle
|
||||
with Wifi in a similar way.
|
||||
Many of the ebay listing include an external antenna and I would suggest this would b a good option if ordering one.
|
||||
So they are far from perfect but still for the price I think well worth having.
|
||||
|
||||
|
|
Plik binarny nie jest wyświetlany.
|
@ -0,0 +1,204 @@
|
|||
/**************************************************************************************************
|
||||
*
|
||||
* Over The Air updates (OTA) - 02Aug23
|
||||
* MODIFIED FOR USE WITH ESP32CamDemo (no log, different header)
|
||||
*
|
||||
* part of the BasicWebserver sketch - https://github.com/alanesq/BasicWebserver
|
||||
*
|
||||
* If using an esp32cam module In Arduino IDE Select "ESP32 dev module" not "ESP32-cam" with PSRAM enabled
|
||||
*
|
||||
**************************************************************************************************
|
||||
|
||||
Make sure partition with OTA enabled is selected
|
||||
|
||||
To enable/disable OTA updates see setting at top of main sketch (#define ENABLE_OTA 1)
|
||||
|
||||
Then access with http://<esp ip address>/ota
|
||||
|
||||
|
||||
**************************************************************************************************/
|
||||
|
||||
|
||||
#if defined ESP32
|
||||
#include <Update.h>
|
||||
#endif
|
||||
|
||||
|
||||
// forward declarations (i.e. details of all functions in this file)
|
||||
void otaSetup();
|
||||
void handleOTA();
|
||||
|
||||
|
||||
// some useful html/css
|
||||
const char colRed[] = "<span style='color:red;'>"; // red text
|
||||
const char colGreen[] = "<span style='color:green;'>"; // green text
|
||||
const char colBlue[] = "<span style='color:blue;'>"; // blue text
|
||||
const char colEnd[] = "</span>"; // end coloured text
|
||||
const char htmlSpace[] = " "; // leave a space (see 'HTML entity')
|
||||
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// -enable OTA
|
||||
// ----------------------------------------------------------------
|
||||
// Enable OTA updates, called when correct password has been entered
|
||||
|
||||
void otaSetup() {
|
||||
|
||||
OTAEnabled = 1; // flag that OTA has been enabled
|
||||
|
||||
// esp32 version (using webserver.h)
|
||||
#if defined ESP32
|
||||
server.on("/update", HTTP_POST, []() {
|
||||
server.sendHeader("Connection", "close");
|
||||
server.send(200, "text/plain", (Update.hasError()) ? "Update Failed!, rebooting..." : "Update complete, rebooting...");
|
||||
delay(2000);
|
||||
ESP.restart();
|
||||
delay(2000);
|
||||
}, []() {
|
||||
HTTPUpload& upload = server.upload();
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
if (serialDebug) Serial.setDebugOutput(true);
|
||||
if (serialDebug) Serial.printf("Update: %s\n", upload.filename.c_str());
|
||||
if (!Update.begin()) { //start with max available size
|
||||
if (serialDebug) Update.printError(Serial);
|
||||
}
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
|
||||
if (serialDebug) Update.printError(Serial);
|
||||
}
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
if (Update.end(true)) { //true to set the size to the current progress
|
||||
if (serialDebug) Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
|
||||
} else {
|
||||
if (serialDebug) Update.printError(Serial);
|
||||
}
|
||||
if (serialDebug) Serial.setDebugOutput(false);
|
||||
} else {
|
||||
if (serialDebug) Serial.printf("Update Failed Unexpectedly (likely broken connection): status=%d\n", upload.status);
|
||||
}
|
||||
});
|
||||
#endif
|
||||
|
||||
// esp8266 version (using ESP8266WebServer.h)
|
||||
#if defined ESP8266
|
||||
server.on("/update", HTTP_POST, []() {
|
||||
server.sendHeader("Connection", "close");
|
||||
server.send(200, "text/plain", (Update.hasError()) ? "Update Failed!, rebooting..." : "Update complete, rebooting...");
|
||||
delay(2000);
|
||||
ESP.restart();
|
||||
delay(2000);
|
||||
}, []() {
|
||||
HTTPUpload& upload = server.upload();
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
if (serialDebug) Serial.setDebugOutput(true);
|
||||
WiFiUDP::stopAll();
|
||||
if (serialDebug) Serial.printf("Update: %s\n", upload.filename.c_str());
|
||||
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
if (!Update.begin(maxSketchSpace)) { //start with max available size
|
||||
if (serialDebug) Update.printError(Serial);
|
||||
}
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
|
||||
if (serialDebug) Update.printError(Serial);
|
||||
}
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
if (Update.end(true)) { //true to set the size to the current progress
|
||||
if (serialDebug) Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
|
||||
} else {
|
||||
if (serialDebug) Update.printError(Serial);
|
||||
}
|
||||
if (serialDebug) Serial.setDebugOutput(false);
|
||||
}
|
||||
yield();
|
||||
});
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// -OTA web page requested i.e. http://x.x.x.x/ota
|
||||
// ----------------------------------------------------------------
|
||||
// Request OTA password or implement OTA update if already entered
|
||||
|
||||
void handleOTA(){
|
||||
|
||||
WiFiClient client = server.client(); // open link with client
|
||||
|
||||
// check if valid password supplied
|
||||
if (server.hasArg("pwd")) {
|
||||
if (server.arg("pwd") == OTAPassword) otaSetup(); // Enable over The Air updates (OTA)
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
if (OTAEnabled == 0) {
|
||||
|
||||
// OTA is not enabled so request password to enable it
|
||||
|
||||
sendHeader(client, stitle);
|
||||
|
||||
// This is the below javascript/html compacted to save flash memory via https://www.textfixer.com/html/compress-html-compression.php
|
||||
client.print (R"=====(<form name='loginForm'> <table width='20%' bgcolor='A09F9F' align='center'> <tr> <td colspan=2> <center><font size=4><b>Enter OTA password</b></font></center><br> </td> <br> </tr><tr> <td>Password:</td> <td><input type='Password' size=25 name='pwd'><br></td><br><br> </tr><tr> <td><input type='submit' onclick='check(this.form)' value='Login'></td> </tr> </table> </form> <script> function check(form) { window.open('/ota?pwd=' + form.pwd.value , '_self') } </script>)=====");
|
||||
/*
|
||||
client.print (R"=====(
|
||||
<form name='loginForm'>
|
||||
<table width='20%' bgcolor='A09F9F' align='center'>
|
||||
<tr>
|
||||
<td colspan=2>
|
||||
<center><font size=4><b>Enter OTA password</b></font></center><br>
|
||||
</td><br>
|
||||
</tr><tr>
|
||||
<td>Password:</td>
|
||||
<td><input type='Password' size=25 name='pwd'><br></td><br><br>
|
||||
</tr><tr>
|
||||
<td><input type='submit' onclick='check(this.form)' value='Login'></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<script>
|
||||
function check(form)
|
||||
{
|
||||
window.open('/ota?pwd=' + form.pwd.value , '_self')
|
||||
}
|
||||
</script>
|
||||
)=====");
|
||||
*/
|
||||
|
||||
|
||||
sendFooter(client); // close web page
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
|
||||
if (OTAEnabled == 1) { // if OTA is enabled implement it
|
||||
|
||||
sendHeader(client, stitle);
|
||||
|
||||
client.write("<br><H1>Update firmware</H1><br>\n");
|
||||
client.printf("Current version = %s, %s \n\n", stitle, sversion);
|
||||
|
||||
client.write("<form method='POST' action='/update' enctype='multipart/form-data'>\n");
|
||||
client.write("<input type='file' style='width: 300px' name='update'>\n");
|
||||
client.write("<br><br><input type='submit' value='Update'></form><br>\n");
|
||||
|
||||
client.write("<br><br>Device will reboot when upload complete");
|
||||
client.printf("%s <br>To disable OTA restart device<br> %s \n", colRed, colEnd);
|
||||
|
||||
sendFooter(client); // close web page
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
|
||||
// close html page
|
||||
delay(3);
|
||||
client.stop();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------- end ----------------------------------------------
|
Ładowanie…
Reference in New Issue