Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Camera Streaming**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-03-09 05:01:51
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* include esp cam streaming using web socket to the */
- /* code */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <ESPAsyncWebSrv.h> // https://github.com/dvarrel/ESPAsyncWebSrv
- #include <AsyncTCP.h> // https://github.com/dvarrel/AsyncTCP
- #include <WiFi.h> // WiFi library for ESP32
- #include "esp_camera.h" // Camera library for ESP32
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void startCameraServer(); // Function to start the camera server
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- AsyncWebServer server(80); // Create an AsyncWebServer object on port 80
- void setup(void)
- {
- // Initialize Serial Monitor
- Serial.begin(115200);
- // Connect to Wi-Fi
- WiFi.begin("YOUR_SSID", "YOUR_PASSWORD"); // Replace with your network credentials
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.println("Connecting to WiFi...");
- }
- Serial.println("Connected to WiFi!");
- // Start the camera server
- startCameraServer();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- }
- /****** FUNCTION IMPLEMENTATIONS *****/
- void startCameraServer() {
- // Start the camera
- camera_config_t config;
- config.ledc_channel = LEDC_CHANNEL_0;
- config.ledc_timer = LEDC_TIMER_0;
- config.pin_d0 = 5; // GPIO 5
- config.pin_d1 = 18; // GPIO 18
- config.pin_d2 = 19; // GPIO 19
- config.pin_d3 = 21; // GPIO 21
- config.pin_d4 = 36; // GPIO 36 (SVP)
- config.pin_d5 = 39; // GPIO 39 (SVN)
- config.pin_d6 = 34; // GPIO 34
- config.pin_d7 = 35; // GPIO 35
- config.pin_xclk = 0; // GPIO 0
- config.pin_pclk = 22; // GPIO 22
- config.pin_vsync = 25; // GPIO 25
- config.pin_href = 23; // GPIO 23
- config.pin_sscb_sda = 26; // GPIO 26
- config.pin_sscb_scl = 27; // GPIO 27
- config.pin_pwdn = 32; // GPIO 32
- config.pin_reset = -1; // GPIO -1 (no reset)
- config.xclk_freq_hz = 20000000;
- config.pixel_format = PIXFORMAT_JPEG; // Choose JPEG format
- // Initialize the camera
- if (esp_camera_init(&config) != ESP_OK) {
- Serial.println("Camera init failed");
- return;
- }
- // Define the WebSocket endpoint
- server.on("/stream", HTTP_GET, [](AsyncWebServerRequest *request){
- request->send(200, "text/html", "<html><body><h1>Camera Stream</h1><img src='stream'></body></html>");
- });
- // Start the streaming
- server.begin();
- Serial.println("Camera Stream Ready! Connect to http://<your_ip_address>/stream");
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement