now also works with PlatformIO

master
Alan 2021-11-21 21:21:37 +00:00 zatwierdzone przez GitHub
rodzic 8d43b1c7cd
commit e8a1298cc6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 239 dodań i 204 usunięć

Wyświetl plik

@ -1,6 +1,6 @@
/*******************************************************************************************************************
*
* ESP32Cam development board demo sketch using Arduino IDE
* ESP32Cam development board demo sketch using Arduino IDE or PlatformIO
* Github: https://github.com/alanesq/ESP32Cam-demo
*
* Tested with ESP32 board manager version 1.0.6
@ -42,14 +42,6 @@
#error This sketch is only for an ESP32Cam module
#endif
#include "esp_camera.h" // https://github.com/espressif/esp32-camera
// #include "camera_pins.h"
// ******************************************************************************************************************
// ---------------------------------------------------------------------------------------------------------
@ -65,6 +57,37 @@
// ---------------------------------------------------------------------------------------------------------
#include <Arduino.h> // required by PlatformIO
#include "esp_camera.h" // https://github.com/espressif/esp32-camera
// #include "camera_pins.h"
#include <WiFi.h>
#include <WebServer.h>
#include <HTTPClient.h> // used by requestWebPage()
#include "driver/ledc.h" // used to configure pwm on illumination led
// spiffs used to store images without an sd card
#include <SPIFFS.h>
#include <FS.h> // gives file access on spiffs
// forward declarations (required by PlatformIO)
bool initialiseCamera();
bool cameraImageSettings();
String localTime();
void flashLED(int reps);
void showError(int errorNo);
byte storeImage();
void handleRoot();
void handlePhoto();
bool handleImg();
void handleNotFound();
void readRGBImage();
bool getNTPtime(int sec);
void handleStream();
String requestWebPage(String ip, String page, int port, int maxChars, String cuttoffText);
void handleTest();
void brightLed(byte ledBrightness);
void MessageRGB(WiFiClient &client, String theText);
// ---------------------------------------------------------------
@ -72,7 +95,7 @@
// ---------------------------------------------------------------
const char* stitle = "ESP32Cam-demo"; // title of this sketch
const char* sversion = "08Oct21"; // Sketch version
const char* sversion = "21Nov21"; // Sketch version
bool sendRGBfile = 0; // if set '/rgb' will send the rgb data as a file rather than display some on a HTML page
@ -141,15 +164,6 @@
// ******************************************************************************************************************
#include <WiFi.h>
#include <WebServer.h>
#include <HTTPClient.h> // used by requestWebPage()
#include "driver/ledc.h" // used to configure pwm on illumination led
// spiffs used to store images without an sd card
#include <SPIFFS.h>
#include <FS.h> // gives file access on spiffs
WebServer server(80); // serve web pages on port 80
// Used to disable brownout detection
@ -1036,9 +1050,9 @@ void readRGBImage() {
delay(3);
client.stop();
// finished with the data so free up the space used in psram
esp_camera_fb_return(fb);
heap_caps_free(ptrVal);
// finished with the data so free up the memory space used in psram
esp_camera_fb_return(fb); // camera frame buffer
heap_caps_free(ptrVal); // rgb data
} // readRGBImage
@ -1047,7 +1061,7 @@ void readRGBImage() {
// send line of text to both serial port and web page
void MessageRGB(WiFiClient &client, String theText) {
if (!sendRGBfile) client.print(theText + "<br>\n");
if (serialDebug || theText.indexOf('error') > 0) Serial.println(theText);
if (serialDebug || theText.indexOf("error") > 0) Serial.println(theText);
}
@ -1145,15 +1159,20 @@ void handleStream(){
// ----------------------------------------------------------------
// request a web page
// ----------------------------------------------------------------
// parameters = ip address, page to request, port to use (usually 80), maximum chars to receive, ignore all in reply before this text
// e.g. String q = requestWebPage("192.168.1.166","/log",80,600,"");
// @param ip ip address
// @param page web page to request
// @param port ip port to use (usually 80)
// @param maxChars maximum number of chars to receive
// @param cuttoffText ignore all in reply before this text
// @return the reply as a string
// Example usage: requestWebPage("192.168.1.166", "/log", 80, 600, "");
String requestWebPage(String ip, String page, int port, int maxChars, String cuttoffText = ""){
int maxWaitTime = 3000; // max time to wait for reply (ms)
uint32_t maxWaitTime = 3000; // max time to wait for reply (ms)
char received[maxChars + 1]; // temp store for incoming character data
int received_counter = 0; // number of characters which have been received
int received_counter = 0; // counter of number of characters which have been received
if (!page.startsWith("/")) page = "/" + page; // make sure page begins with "/"
@ -1173,23 +1192,24 @@ String requestWebPage(String ip, String page, int port, int maxChars, String cut
if (serialDebug) Serial.println("Connected to host - sending request...");
// send request - A basic request looks something like: "GET /index.html HTTP/1.1\r\nHost: 192.168.0.4:8085\r\n\r\n"
client.print("GET " + page + " HTTP/1.1\r\n" +
"Host: " + ip + "\r\n" +
"Connection: close\r\n\r\n");
client.println("GET " + page + " HTTP/1.1 ");
client.println("Host: " + ip );
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println(); // needed to end HTTP header
if (serialDebug) Serial.println("Request sent - waiting for reply...");
// Wait for a response
uint32_t ttimer = millis();
while ( !client.available() && (uint32_t)(millis() - ttimer) < maxWaitTime ) {
while ( client.connected() && !client.available() && (uint32_t)(millis() - ttimer) < maxWaitTime ) {
delay(10);
}
if ( ((uint32_t)(millis() - ttimer) > maxWaitTime ) && serialDebug) Serial.println("-Timed out");
// read the response
while ( client.available() && received_counter < maxChars ) {
#if defined ESP8266
delay(2); // it just reads 255s on esp8266 if this delay is not included
#endif
while ( client.connected() && client.available() && received_counter < maxChars ) {
delay(4);
received[received_counter] = char(client.read()); // read one character
received_counter+=1;
}
@ -1215,7 +1235,8 @@ String requestWebPage(String ip, String page, int port, int maxChars, String cut
}
return received; // return the full reply text
}
} // requestWebPage

14
platformio.ini 100644
Wyświetl plik

@ -0,0 +1,14 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32cam]
platform = espressif32
board = esp32cam
framework = arduino