From 6d5e2989b7fd7b1dfd680a83434a529601f924f3 Mon Sep 17 00:00:00 2001 From: Alan <60433566+alanesq@users.noreply.github.com> Date: Thu, 26 Nov 2020 17:40:39 +0000 Subject: [PATCH] Add files via upload --- esp32cam-demo.ino | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/esp32cam-demo.ino b/esp32cam-demo.ino index 67023c9..4f2edb5 100644 --- a/esp32cam-demo.ino +++ b/esp32cam-demo.ino @@ -35,6 +35,7 @@ #include "esp_camera.h" // https://github.com/espressif/esp32-camera #include #include +#include // used by requestWebPage() // --------------------------------------------------------------- @@ -226,7 +227,7 @@ void setup() { } Serial.println("\nSetup complete..."); - + } // setup @@ -491,7 +492,7 @@ void handleRoot() { // Note: if using an input box etc. you would read the value with the command: String Bvalue = server.arg("demobutton1"); if (server.hasArg("button1")) { digitalWrite(iopinA,!digitalRead(iopinA)); // toggle output pin on/off - if (debugInfo) Serial.println("Button 1 pressed"); + if (debugInfo) Serial.println("Button 1 pressed"); } // if button2 was pressed (toggle io pin B) @@ -892,6 +893,37 @@ void handleStream(){ } // handleStream +// ---------------------------------------------------------------- +// -request a web page (wifi client) +// ---------------------------------------------------------------- +// usage example: String q = requestWebPage("http://192.168.1.176:80/index.htm"); +// original code from: https://techtutorialsx.com/2017/05/19/esp32-http-get-requests/ + +String requestWebPage(String urlRequested) { + + if ((WiFi.status() != WL_CONNECTED)) return "ERROR: Network not connected"; + + HTTPClient http; + String payload; + + http.begin(urlRequested); //Specify the URL + int httpCode = http.GET(); //Make the request + + if (httpCode > 0) { //Check for the returning code + payload = http.getString(); + if (debugInfo) Serial.println(httpCode); + if (debugInfo) Serial.println(payload); + } + else { + Serial.println("Error on HTTP request"); + } + + http.end(); //Free the resources + + return payload; +} + + // ****************************************************************************************************************** @@ -913,8 +945,6 @@ void handleTest() { client.write(" photo \n"); // basic html header - - // html body client.print("

Test Page

\n"); @@ -924,6 +954,9 @@ void handleTest() { + + + // end html client.write("\n");