Advertisement
pleasedontcode

**Camera Streaming** rev_01

Mar 8th, 2025
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **Camera Streaming**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-03-09 05:01:51
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* include esp cam streaming using web socket to the */
  21.     /* code */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <ESPAsyncWebSrv.h>    // https://github.com/dvarrel/ESPAsyncWebSrv
  28. #include <AsyncTCP.h>          // https://github.com/dvarrel/AsyncTCP
  29. #include <WiFi.h>             // WiFi library for ESP32
  30. #include "esp_camera.h"       // Camera library for ESP32
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void startCameraServer();    // Function to start the camera server
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38.  
  39. AsyncWebServer server(80);    // Create an AsyncWebServer object on port 80
  40.  
  41. void setup(void)
  42. {
  43.     // Initialize Serial Monitor
  44.     Serial.begin(115200);
  45.    
  46.     // Connect to Wi-Fi
  47.     WiFi.begin("YOUR_SSID", "YOUR_PASSWORD"); // Replace with your network credentials
  48.     while (WiFi.status() != WL_CONNECTED) {
  49.         delay(1000);
  50.         Serial.println("Connecting to WiFi...");
  51.     }
  52.     Serial.println("Connected to WiFi!");
  53.  
  54.     // Start the camera server
  55.     startCameraServer();
  56. }
  57.  
  58. void loop(void)
  59. {
  60.     // put your main code here, to run repeatedly:
  61. }
  62.  
  63. /****** FUNCTION IMPLEMENTATIONS *****/
  64. void startCameraServer() {
  65.     // Start the camera
  66.     camera_config_t config;
  67.     config.ledc_channel = LEDC_CHANNEL_0;
  68.     config.ledc_timer = LEDC_TIMER_0;
  69.     config.pin_d0 = 5;   // GPIO 5
  70.     config.pin_d1 = 18;  // GPIO 18
  71.     config.pin_d2 = 19;  // GPIO 19
  72.     config.pin_d3 = 21;  // GPIO 21
  73.     config.pin_d4 = 36;  // GPIO 36 (SVP)
  74.     config.pin_d5 = 39;  // GPIO 39 (SVN)
  75.     config.pin_d6 = 34;  // GPIO 34
  76.     config.pin_d7 = 35;  // GPIO 35
  77.     config.pin_xclk = 0; // GPIO 0
  78.     config.pin_pclk = 22; // GPIO 22
  79.     config.pin_vsync = 25; // GPIO 25
  80.     config.pin_href = 23; // GPIO 23
  81.     config.pin_sscb_sda = 26; // GPIO 26
  82.     config.pin_sscb_scl = 27; // GPIO 27
  83.     config.pin_pwdn = 32; // GPIO 32
  84.     config.pin_reset = -1; // GPIO -1 (no reset)
  85.     config.xclk_freq_hz = 20000000;
  86.     config.pixel_format = PIXFORMAT_JPEG; // Choose JPEG format
  87.  
  88.     // Initialize the camera
  89.     if (esp_camera_init(&config) != ESP_OK) {
  90.         Serial.println("Camera init failed");
  91.         return;
  92.     }
  93.  
  94.     // Define the WebSocket endpoint
  95.     server.on("/stream", HTTP_GET, [](AsyncWebServerRequest *request){
  96.         request->send(200, "text/html", "<html><body><h1>Camera Stream</h1><img src='stream'></body></html>");
  97.     });
  98.  
  99.     // Start the streaming
  100.     server.begin();
  101.     Serial.println("Camera Stream Ready! Connect to http://<your_ip_address>/stream");
  102. }
  103.  
  104. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement