Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed Dec 9, 2021
1 parent de65ee8 commit 7da3479
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
5 changes: 0 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,4 @@ board_build.partitions = min_spiffs.csv
board_build.embed_txtfiles =
src/index.html

build_flags =
'-DWIFI_SSID="${sysenv.SSID}"'
'-DWIFI_PASS="${sysenv.PASS}"'
'-DHUSARNET_HOSTNAME="${sysenv.HOSTNAME}"'
'-DHUSARNET_JOINCODE="${sysenv.JOINCODE}"'

4 changes: 2 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>ESP32 boilerplate</title>
<title>ESP32 IP camera</title>
</head>
<body>
<p>Hello world!</p>
<a href="/stream">Open video stream</a>
</body>
</html>
60 changes: 33 additions & 27 deletions src/simple-webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,11 @@

#define HTTP_PORT 8080

WebServer server(HTTP_PORT);

void handleMjpeg() {
// Configure stream
static struct esp32cam::CameraClass::StreamMjpegConfig mjcfg;
mjcfg.frameTimeout = 1000; // ms
mjcfg.minInterval = 0; // ms
mjcfg.maxFrames =
-1; // -1 means - send frames until error occurs or client disconnects

// Actually stream
auto client = server.client();
auto startTime = millis();

int res = esp32cam::Camera.streamMjpeg(client, mjcfg);
// int res = esp32cam::Camera.streamMjpeg(client);
if (res <= 0) {
Serial1.printf("Stream error: %d\n", res);
return;
}
// index.html available in "index_html" const String
extern const char index_html_start[] asm("_binary_src_index_html_start");
const String index_html = String((const char *)index_html_start);

auto duration = millis() - startTime;
Serial1.printf("Stream end %d frames, on average %0.2f FPS\n", res,
1000.0 * res / duration);
}
WebServer server(HTTP_PORT);

void setup(void) {
// ===============================================
Expand All @@ -42,14 +22,15 @@ void setup(void) {

// remap default Serial (used by Husarnet logs)
Serial.begin(115200, SERIAL_8N1, 16, 17); // from P3 & P1 to P16 & P17
Serial1.begin(115200, SERIAL_8N1, 3, 1); // remap Serial1 from P9 & P10 to P3 & P1
Serial1.begin(115200, SERIAL_8N1, 3,
1); // remap Serial1 from P9 & P10 to P3 & P1

Serial1.println("\r\n**************************************");
Serial1.println("ESP32 IP camera example");
Serial1.println("**************************************\r\n");

// Init Wi-Fi
Serial1.printf("📻 1. Connecting to: %s Wi-Fi network ", ssid);
Serial1.printf("📻 1. Connecting to: \"%s\" Wi-Fi network ", ssid);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Expand Down Expand Up @@ -96,6 +77,7 @@ void setup(void) {

// Configure camera
// Tested on M5CAMERA X

esp32cam::Config cfg;

cfg.setPins(esp32cam::pins::M5CameraLED);
Expand All @@ -109,9 +91,33 @@ void setup(void) {
}

// Setup the stream webserver
server.on("/stream", handleMjpeg);

server.on("/stream", []() {
// Configure stream
static struct esp32cam::CameraClass::StreamMjpegConfig mjcfg;
mjcfg.frameTimeout = 1000; // ms
mjcfg.minInterval = 0; // ms
mjcfg.maxFrames = -1; // send frames until error occurs or client disconnects

// Actually stream
auto client = server.client();
auto startTime = millis();

int res = esp32cam::Camera.streamMjpeg(client, mjcfg);
if (res <= 0) {
Serial1.printf("Stream error: %d\n", res);
return;
}

auto duration = millis() - startTime;
Serial1.printf("Stream end %d frames, on average %0.2f FPS\n", res, 1000.0 * res / duration);
});
server.on("/", []() { server.send(200, "text/html", index_html); });
server.onNotFound( []() { server.send(200, "text/plain", "not found :("); });
server.begin();

// Print peer addresses and link to the stream

Serial1.println("🚀 HTTP server with a live video stream started\r\n");
Serial1.printf("Visit:\r\nhttp://%s:%d/stream\r\n\r\n", hostName, HTTP_PORT);

Expand Down

0 comments on commit 7da3479

Please sign in to comment.