Initial commit of Arduino libraries
This commit is contained in:
3
Micro-RTSP/examples/.gitignore
vendored
Normal file
3
Micro-RTSP/examples/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
wifikeys.h
|
||||
.pioenvs
|
||||
.piolibdeps
|
||||
223
Micro-RTSP/examples/ESP32-devcam.ino
Normal file
223
Micro-RTSP/examples/ESP32-devcam.ino
Normal file
@@ -0,0 +1,223 @@
|
||||
#include "OV2640.h"
|
||||
#include <WiFi.h>
|
||||
#include <WebServer.h>
|
||||
#include <WiFiClient.h>
|
||||
|
||||
#include "SimStreamer.h"
|
||||
#include "OV2640Streamer.h"
|
||||
#include "CRtspSession.h"
|
||||
|
||||
#define ENABLE_OLED //if want use oled ,turn on thi macro
|
||||
// #define SOFTAP_MODE // If you want to run our own softap turn this on
|
||||
#define ENABLE_WEBSERVER
|
||||
#define ENABLE_RTSPSERVER
|
||||
|
||||
#ifdef ENABLE_OLED
|
||||
#include "SSD1306.h"
|
||||
#define OLED_ADDRESS 0x3c
|
||||
#define I2C_SDA 14
|
||||
#define I2C_SCL 13
|
||||
SSD1306Wire display(OLED_ADDRESS, I2C_SDA, I2C_SCL, GEOMETRY_128_32);
|
||||
bool hasDisplay; // we probe for the device at runtime
|
||||
#endif
|
||||
|
||||
OV2640 cam;
|
||||
|
||||
#ifdef ENABLE_WEBSERVER
|
||||
WebServer server(80);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_RTSPSERVER
|
||||
WiFiServer rtspServer(8554);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SOFTAP_MODE
|
||||
IPAddress apIP = IPAddress(192, 168, 1, 1);
|
||||
#else
|
||||
#include "wifikeys.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_WEBSERVER
|
||||
void handle_jpg_stream(void)
|
||||
{
|
||||
WiFiClient client = server.client();
|
||||
String response = "HTTP/1.1 200 OK\r\n";
|
||||
response += "Content-Type: multipart/x-mixed-replace; boundary=frame\r\n\r\n";
|
||||
server.sendContent(response);
|
||||
|
||||
while (1)
|
||||
{
|
||||
cam.run();
|
||||
if (!client.connected())
|
||||
break;
|
||||
response = "--frame\r\n";
|
||||
response += "Content-Type: image/jpeg\r\n\r\n";
|
||||
server.sendContent(response);
|
||||
|
||||
client.write((char *)cam.getfb(), cam.getSize());
|
||||
server.sendContent("\r\n");
|
||||
if (!client.connected())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void handle_jpg(void)
|
||||
{
|
||||
WiFiClient client = server.client();
|
||||
|
||||
cam.run();
|
||||
if (!client.connected())
|
||||
{
|
||||
return;
|
||||
}
|
||||
String response = "HTTP/1.1 200 OK\r\n";
|
||||
response += "Content-disposition: inline; filename=capture.jpg\r\n";
|
||||
response += "Content-type: image/jpeg\r\n\r\n";
|
||||
server.sendContent(response);
|
||||
client.write((char *)cam.getfb(), cam.getSize());
|
||||
}
|
||||
|
||||
void handleNotFound()
|
||||
{
|
||||
String message = "Server is running!\n\n";
|
||||
message += "URI: ";
|
||||
message += server.uri();
|
||||
message += "\nMethod: ";
|
||||
message += (server.method() == HTTP_GET) ? "GET" : "POST";
|
||||
message += "\nArguments: ";
|
||||
message += server.args();
|
||||
message += "\n";
|
||||
server.send(200, "text/plain", message);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_OLED
|
||||
#define LCD_MESSAGE(msg) lcdMessage(msg)
|
||||
#else
|
||||
#define LCD_MESSAGE(msg)
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_OLED
|
||||
void lcdMessage(String msg)
|
||||
{
|
||||
if(hasDisplay) {
|
||||
display.clear();
|
||||
display.drawString(128 / 2, 32 / 2, msg);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
CStreamer *streamer;
|
||||
|
||||
void setup()
|
||||
{
|
||||
#ifdef ENABLE_OLED
|
||||
hasDisplay = display.init();
|
||||
if(hasDisplay) {
|
||||
display.flipScreenVertically();
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
}
|
||||
#endif
|
||||
LCD_MESSAGE("booting");
|
||||
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
{
|
||||
;
|
||||
}
|
||||
cam.init(esp32cam_config);
|
||||
|
||||
IPAddress ip;
|
||||
|
||||
|
||||
#ifdef SOFTAP_MODE
|
||||
const char *hostname = "devcam";
|
||||
// WiFi.hostname(hostname); // FIXME - find out why undefined
|
||||
LCD_MESSAGE("starting softAP");
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
|
||||
bool result = WiFi.softAP(hostname, "12345678", 1, 0);
|
||||
if (!result)
|
||||
{
|
||||
Serial.println("AP Config failed.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("AP Config Success.");
|
||||
Serial.print("AP MAC: ");
|
||||
Serial.println(WiFi.softAPmacAddress());
|
||||
|
||||
ip = WiFi.softAPIP();
|
||||
}
|
||||
#else
|
||||
LCD_MESSAGE(String("join ") + ssid);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Serial.print(F("."));
|
||||
}
|
||||
ip = WiFi.localIP();
|
||||
Serial.println(F("WiFi connected"));
|
||||
Serial.println("");
|
||||
Serial.println(ip);
|
||||
#endif
|
||||
|
||||
LCD_MESSAGE(ip.toString());
|
||||
|
||||
#ifdef ENABLE_WEBSERVER
|
||||
server.on("/", HTTP_GET, handle_jpg_stream);
|
||||
server.on("/jpg", HTTP_GET, handle_jpg);
|
||||
server.onNotFound(handleNotFound);
|
||||
server.begin();
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_RTSPSERVER
|
||||
rtspServer.begin();
|
||||
|
||||
//streamer = new SimStreamer(true); // our streamer for UDP/TCP based RTP transport
|
||||
streamer = new OV2640Streamer(cam); // our streamer for UDP/TCP based RTP transport
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
#ifdef ENABLE_WEBSERVER
|
||||
server.handleClient();
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_RTSPSERVER
|
||||
uint32_t msecPerFrame = 100;
|
||||
static uint32_t lastimage = millis();
|
||||
|
||||
// If we have an active client connection, just service that until gone
|
||||
streamer->handleRequests(0); // we don't use a timeout here,
|
||||
// instead we send only if we have new enough frames
|
||||
uint32_t now = millis();
|
||||
if(streamer->anySessions()) {
|
||||
if(now > lastimage + msecPerFrame || now < lastimage) { // handle clock rollover
|
||||
streamer->streamImage(now);
|
||||
lastimage = now;
|
||||
|
||||
// check if we are overrunning our max frame rate
|
||||
now = millis();
|
||||
if(now > lastimage + msecPerFrame) {
|
||||
printf("warning exceeding max frame rate of %d ms\n", now - lastimage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WiFiClient rtspClient = rtspServer.accept();
|
||||
if(rtspClient) {
|
||||
Serial.print("client: ");
|
||||
Serial.print(rtspClient.remoteIP());
|
||||
Serial.println();
|
||||
streamer->addSession(rtspClient);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
15
Micro-RTSP/examples/platformio.ini
Normal file
15
Micro-RTSP/examples/platformio.ini
Normal file
@@ -0,0 +1,15 @@
|
||||
; 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:m5stack-core-esp32]
|
||||
platform = espressif32@>=1.6.0
|
||||
board = m5stack-core-esp32
|
||||
framework = arduino
|
||||
lib_deps = Micro-RTSP
|
||||
3
Micro-RTSP/examples/wifikeys_template.h
Normal file
3
Micro-RTSP/examples/wifikeys_template.h
Normal file
@@ -0,0 +1,3 @@
|
||||
// copy this file to wifikeys.h and edit
|
||||
const char *ssid = "YOURNETHERE"; // Put your SSID here
|
||||
const char *password = "YOURPASSWORDHERE"; // Put your PASSWORD here
|
||||
Reference in New Issue
Block a user