Skip to content
Snippets Groups Projects
Commit d3275bfb authored by Vladislav Vlasuk's avatar Vladislav Vlasuk
Browse files

Merge branch 'master' into 'main'

init

See merge request !1
parents cfa81aac 42b332f7
No related branches found
No related tags found
1 merge request!1init
.vscode
build
# thk_EspCamServer
Zunächst muss die Bibliothek im Sketch inkludiert werden.
Ermöglicht das Erstellen einer Internetressource. Dies kann bspw. dazu genutzt werden das Bild einer Esp32 Kamera im lokalen Netzwerk zu streamen.
#include "thk_EspCamServer.h" // WIFI und HTTP-Server
## Getting started
Anschließend wird das WiFI-Netzwerk konfiguriert und (optional) der Name des HTTP-Ressource festgelegt.
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
const char *ssid = "FRITZBOX";
const char *password = "qqqqqqqq";
const char *uri = "/stream";
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
Nun kann das Objekt erzeugt werden.
## Add your files
thk_EspCamServer server(ssid, password, uri);
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://git-ce.rwth-aachen.de/thk_libs/microcontrollers/thk_espcamserver.git
git branch -M main
git push -uf origin main
```
Für die Verwendung der Klasse ist ein sogenannter Handler erforderlich. Dieser regelt das Verhalten beim Aufrufen der Internetressource (bspw. beim eintippen von http://172.02.11/server im Browser innerhalb des lokalen Netzwerks).\
Hier kann für den Anfang die folgende Funktion außerhalb der setup() und loop() Routine erstellt werden:
## Integrate with your tools
static esp_err_t get_helloworld_handler(httpd_req_t *req)
{
/* Send a simple response */
Serial.println("Ein HTTP Request hat uns erreicht!");
return ESP_OK;
}
- [ ] [Set up project integrations](https://git-ce.rwth-aachen.de/thk_libs/microcontrollers/thk_espcamserver/-/settings/integrations)
Hier erfolgt beim Aufrufen der Internetressource eine Textausgabe durch den ESP32 im Seriellen Monitor.
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
In der Setup Routine wird die Verbindung zum WiFi-Netzwerk aufgebaut
## Test and Deploy
server.connect();
Use the built-in continuous integration in GitLab.
und der Webserver mit einer Referenz auf den benutzerdefinierten Handler (hier unser HelloWorld Beispiel) aufgerufen.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
server.start_webserver(&get_stream_handler);
***
# Editing this README
## CameraWebServer
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
Das Beispiel *cameraserver.ino* streamt das Kamerabild mittels eines lokalen Webservers.
Hierfür ist die Bibliothek thk_EspCamDriver erforderlich!
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
https://git-ce.rwth-aachen.de/thk_libs/microcontrollers/thk_espcamdriver.git
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
Zum Verwenden des Skriptes muss das Netzwerk vorab angepasst werden
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
const char* ssid = "iPhone von Vladislav";
const char* password = "qqqqqqqq";
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
Im Anschluss den Sketch auf den ESP32 One hochladen. Hierbei als Board "ESP32 DEV MODULE(esp32)" wählen. Nun kann mit einem im Netzwerk befindlichen Gerät über die Https-Adresse das Bild im Webserver angezeigt und gespeichert werden.
Im Seriellen Monitor wird hier durch das Neustarten des ESP (Reset-Button) die Adresse ausgegeben.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
[OK] WiFi verbunden: 172.20.10.2
[OK] HTTP_Get-Server bereit ( Port 80 ) HTTP: 172.20.10.2/stream
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
### Erläuterung des Skripts
Zunächst wird die erforderliche Bibliothek zum Interagieren mit der Kamera und Starten des Servers inkludiert
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
#include "thk_EspCamDriver.h" // ESP32 Kamera
#include "thk_EspCamServer.h" // WIFI und HTTP-Server
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
Im Anschluss wird das Netzwerk eingerichtet
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
const char *ssid = "iPhone von Vladislav";
const char *password = "qqqqqqqq";
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
Optional kann auch die Internetressource unbenannt werden. Diese wird beim Aufruf des Servers benötigt.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
const char *uri = "/stream";
## License
For open source projects, say how it is licensed.
Die folgenden Objekte sind für den Datenaustausch mit der Kamera notwendig
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
camera_config_t cameraconfig; // Konfig
esp_err_t cameraerror; // Fehler
camera_fb_t *fb = NULL; // Framebuffer
Um sowohl die Kamera als auch den Server möglichst kompakt für den Anwender nutzbar zu machen, sind zwei benutzerdefinierten Klassen vorhanden
thk_EspCamDriver camera(&cameraconfig, &cameraerror, fb);
thk_EspCamServer server(ssid, password, uri);
Anschließend kann in der Setup-Routine die Kamera initialisiert
camera.init();
Und mit dem WiFi-Netzwerk verbunden werden
server.connect();
Abschließend wird der Webserver gestartet. Dafür ist ein sogenannter Handler erforderlich. Dieser bildet die Antwort auf den Zugriff über HTTP. Hier kann neben dem Stream-Handler für das Kamerabild
server.start_webserver(&get_stream_handler);
auch stattdessen das HelloWorld Beispiel ausprobiert werden. Hierzu die Referenz entsprechend anpassen.
server.start_webserver(&get_helloworld_handler);
Das Kamerabild wird hier als Buffer gespeichert. Die Länge und der Inhalt (Pixel) können über die Server-Bibliothek bezogen werden.
camera.getBufLen()
camera.getJpgBuf()
// Beschreibung:
// Beispiel Sketch für das Auslesen der ESP32One Waveshare Kamera
// und lokales Streamen des Kamerabildes per HTTP
// Abhängigkeiten:
// thk_EspCamDriver.h, thk_EspCamServer.h
// Autor:
// Vladislav Vlasuk (TH Köln, Labor für Assistenzsysteme)
// Datum:
// 05.07.2022
// Bitte ESP32 Kameramodell auskommentieren
#include <thk_EspCamDriver.h> // ESP32 Kamera
#include <thk_EspCamServer.h> // WIFI und HTTP-Server
// Wlan-Netzwerk und Internetressource (URI) festlegen
const char *ssid = "iPhone von Vladislav";
const char *password = "qqqqqqqq";
const char *uri = "/stream";
// ESP32 Kameraspezifisch
esp_image_t image;
camera_config_t cameraconfig; // Konfig
esp_err_t cameraerror; // Fehler
camera_fb_t *fb = NULL; // Framebuffer
// Objekte erzeugen
thk_EspCamDriver camera(&cameraconfig, &cameraerror, fb, &image);
thk_EspCamServer server(ssid, password, uri);
void setup()
{
Serial.begin(115200);
camera.set_hmirror(1);
camera.set_vflip(1);
camera.set_grayscale(1);
camera.init(); // Kamera starten
server.connect(); // Wifi verbinden
server.start_webserver(&get_stream_handler); // Server starten
};
void loop()
{
// Do nothing. Everything is done in another task by the web server
delay(1e4);
}
// Handler für das Auslesen des Kameramoduls am ESP32One Waveshare
esp_err_t get_stream_handler(httpd_req_t *req)
{
Serial.println("Starte Kamera Handler");
esp_err_t res = ESP_OK;
size_t _jpg_buf_len = 0;
uint8_t *_jpg_buf = NULL;
char *part_buf[128];
res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE);
if (res != ESP_OK)
return res;
while (true)
{
// Schieße Bild
camera.take_picture();
_jpg_buf_len = camera.get_fb()->len;
_jpg_buf = camera.get_fb()->buf;
// This API will send the data as an HTTP response to the request in the form of chunks with chunked-encoding
if (res == ESP_OK)
{
res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));
}
if (res == ESP_OK)
{
size_t hlen = snprintf((char *)part_buf, 128, _STREAM_PART, _jpg_buf_len);
res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen);
}
if (res == ESP_OK)
{
res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len);
}
// close stream
if (camera.get_fb())
{
camera.close_stream();
_jpg_buf = NULL;
}
else if (_jpg_buf)
{
free(_jpg_buf);
_jpg_buf = NULL;
}
if (res != ESP_OK)
{
Serial.println("send frame failed failed");
break;
}
}
return res;
}
// Bare Minimum Handler
static esp_err_t get_helloworld_handler(httpd_req_t *req)
{
/* Send a simple response */
Serial.println("Ein HTTP Request hat uns erreicht!");
return ESP_OK;
}
#include "esp_http_server.h"
#include <WiFi.h>
// Von Espresif Systems (Shanghei) PTE LTD für Stream vorgegeben
#define PART_BOUNDARY "123456789000000000000987654321"
static const char *_STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY;
static const char *_STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n";
static const char *_STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %u\r\nX-Timestamp: %d.%06d\r\n\r\n";
// Ermöglicht die Datenübertragung per WIFI mittels HTTP
class thk_EspCamServer
{
private:
const char *ssid = NULL;
const char *password = NULL;
const char *uri = NULL;
IPAddress address;
public:
// Ein Server benötigt immer eine ssid, pw, uri
thk_EspCamServer(const char *a_ssid, const char *a_pw, const char *a_uri) : ssid(a_ssid), password(a_pw), uri(a_uri)
{
}
// Startet die Verbindung zum Netzwerk.
bool connect()
{
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
WiFi.setSleep(false);
Serial.print("Verbinde mit Netzwerk >");
Serial.print(ssid);
Serial.print("< [");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("]");
Serial.print("[OK] WiFi verbunden: ");
Serial.println(WiFi.localIP());
address = WiFi.localIP();
return true;
}
// Startet für den URI Handler einen Server, der über HTTP erreicht werden kann
// @param func Handler, welcher ausgeführt werden soll
//
httpd_handle_t start_webserver(esp_err_t (*func)(httpd_req_t *req))
{
/* Generate default configuration */
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
/* Empty handle to esp_http_server */
httpd_handle_t server = NULL;
/* URI handler structure for GET /uri */
httpd_uri_t uri_get = {
.uri = this->uri,
.method = HTTP_GET,
.handler = func,
.user_ctx = NULL};
/* Start the httpd server */
if (httpd_start(&server, &config) == ESP_OK)
{
Serial.printf("[OK] HTTP_Get-Server bereit ( Port %d ) HTTP: ", config.server_port);
Serial.print(address);
Serial.println(uri);
/* Register URI handlers */
httpd_register_uri_handler(server, &uri_get);
}
/* If server failed to start, handle will be NULL */
return server;
}
/* Function for stopping the webserver */
void stop_webserver(httpd_handle_t server)
{
/* Stop the httpd server */
Serial.println("Schließe Server");
httpd_stop(server);
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment