captainj56

Untitled

Mar 25th, 2020
273
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ArduinoWebsockets.h>
  2. #include <WiFi.h>
  3. #include <ESPAsyncWebServer.h>
  4. #include "esp_camera.h"
  5. #include "soc/soc.h"
  6. #include "soc/rtc_cntl_reg.h"
  7.  
  8. int index_html_gz_len = 1744;
  9. const uint8_t index_html_gz[] = {
  10. 0x1f,0x8b,0x08,0x08,0x70,0x3b,0x7b,0x5e,0x00,0xff,0x69,0x6e,0x64,0x65,0x78,0x5f,0x68,0x74,0x6d,0x6c,0x5f,0x67,0x7a,0x00,0x95,0x58,0x7b,0x6f,0x1a,0x3b,0x16,0xff,0x3b,0x7c,0x0a,0x97,0x68,0x0b,0x6c,0x61,0x86,0x84,0xb4,0x9b,0x50,0xc8,0xd5,0xb6,0x89,0xd4,0x4a,0xad,0x5a,0xdd,0xe4,0x6e,0x13,0xad,0x56,0x91,0x99,0x31,0xe0,0xd6,0x63,0xcf,0xda,0x1e,0x1e,0xbb,0xcd,0x77,0xef,0x39,0x1e,0xcf,0x8b,0x90,0x28,0xe5,0x0f,0x18,0xdb,0xe7,0x77,0x9e,0x0f,0x9f,0x61,0xb2,0xb4,0x89,0x38,0x6f,0x4d,0x96,0x8c,0xc6,0xf0,0x93,0x30,0x4b,0x89,0xa4,0x09,0x9b,0x76,0x56,0x9c,0xad,0x53,0xa5,0x6d,0x87,0x14,0x9f,0x48,0x49,0xcb,0xa4,0x9d,0x76,0xd6,0x3c,0xb6,0xcb,0x69,0xcc,0x56,0x3c,0x62,0x03,0xb7,0xe8,0x97,0x44,0x5c,0x72,0xcb,0xa9,0x18,0x98,0x88,0x0a,0x36,0x3d,0x0a,0x86,0xd5,0x51,0x66,0x98,0x76,0xfb,0x74,0x06,0x47,0x52,0x75,0x48,0x08,0x22,0x2d,0xb7,0x82,0x9d,0x7f,0xa5,0x92,0x50,0x19,0x93,0x6b,0x2e,0x2c,0xb9,0xbc,0xfa,0x3a,0x3a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0x9e,0xa2,0xbd,0xeb,0xa9,0x36,0x89,0x04,0x35,0x66,0xda,0xe6,0x09,0x5d,0xb0,0xda,0xbe,0xe3,0x3c,0x01,0x3f,0xd6,0x60,0x6d,0x62,0x74,0x34,0x6d,0xbb,0x33,0xcf,0xba,0xf8,0x31,0x91,0xe6,0xa9,0x3d,0x6f,0x01,0x03,0x63,0x09,0x76,0x55,0x32,0x25,0xb1,0x8a,0xb2,0x04,0x9a,0x46,0xb0,0x60,0xf6,0x52,0x30,0x7c,0x7c,0xb7,0xfd,0x18,0x77,0x3b,0x39,0xbb,0x0e,0x64,0x7a,0x4e,0xff,0xed,0xea,0xee,0xaf,0x3f,0x3f,0x01,0xa2,0xbd,0x36,0xe3,0x30,0x6c,0x93,0x57,0xd0,0x0c,0x64,0xac,0xd6,0x01,0x44,0x8d,0x62,0xee,0x06,0x4b,0x05,0x74,0xaf,0x48,0x7b,0x7c,0x3a,0x3c,0x3d,0x69,0x17,0xc0,0xb5,0x01,0x90,0x04,0x61,0xdf,0xd8,0xec,0x0a,0x02,0xcc,0x6c,0x37,0xe7,0x05,0xac,0x0f,0x0e,0x5a,0x6b,0x13,0x28,0x99,0x30,0x63,0xc0,0x36,0x20,0x2c,0x9f,0xce,0xa1,0x34,0x0e,0xf8,0x9c,0x74,0xfd,0x4e,0x10,0x53,0xb8,0x11,0x38,0x70,0xa4,0x32,0x62,0x6a,0x4e,0xde,0x09,0x35,0xeb,0x21,0x11,0x21,0x2b,0xaa,0x49,0xa6,0xc5,0x97,0xd9,0x77,0xa8,0x71,0x60,0x02,0xcc,0x83,0x08,0xd4,0xb7,0x2c,0xdf,0x82,0x75,0x83,0x0d,0x4a,0x06,0x14,0x78,0x20,0x00,0x6f,0x01,0xa0,0x04,0xc3,0xc1,0x7d,0xeb,0xfe,0x6d,0xab,0x85,0x2c,0x63,0x4d,0x17,0x1f,0xb1,0xf9,0xd5,0xdc,0xf4,0xdf,0x8c,0xe9,0xed,0x95,0x6b,0x26,0x4a,0x77,0x3b,0xae,0x07,0xa0,0x93,0x90,0xbe,0xca,0xed,0x27,0x00,0x55,0x62,0xec,0xa2,0xbe,0x61,0xba,0x03,0xb4,0xdc,0x08,0xd4,0x7c,0x6e,0x98,0x75,0xfb,0x3b,0xb4,0x1f,0x5c,0x15,0xec,0x21,0xce,0x0f,0x72,0x6a,0xa8,0xa1,0x0b,0x30,0xe1,0x83,0xd2,0xfc,0x7f,0x48,0x26,0xea,0xf4,0xb9,0xb4,0x90,0x1c,0x37,0x68,0xff,0xc5,0xb4,0xe5,0x70,0x31,0xd6,0x29,0xbd,0x2c,0x47,0xfa,0x68,0xba,0xb8,0x32,0xe9,0x05,0x2b,0x2a,0x32,0x0c,0x63,0x7e,0x33,0x8f,0x49,0x07,0xf2,0xe1,0xa1,0x1a,0xaf,0x60,0xbf,0xe8,0x54,0x35,0x8a,0x42,0x78,0xae,0x91,0xef,0xcd,0x53,0x32,0xa7,0xc2,0x40,0xcf,0x76,0xf6,0x67,0x5a,0x83,0xc8,0x9b,0xc6,0xea,0x36,0x5f,0xf9,0xfb,0xde,0x9f,0xf9,0x95,0x3f,0xdb,0x7c,0x71,0xce,0x01,0x66,0xd0,0xa6,0x70,0x63,0xbb,0xbb,0x01,0x15,0x66,0xaf,0xa1,0xf0,0xfb,0xee,0xe9,0x0a,0xfa,0x56,0x9f,0x18,0xf8,0xbe,0xe6,0x09,0x83,0x3a,0x77,0xc9,0xec,0x1d,0x0d,0xfd,0xf4,0x72,0x05,0x72,0x3f,0x71,0x03,0x97,0x2e,0x83,0xa0,0xba,0xab,0xc7,0xb5,0xc1,0x4e,0xdf,0x65,0xcd,0x15,0x3e,0xf7,0x73,0xcd,0xf3,0x0a,0x7a,0x1a,0x0b,0x82,0x3c,0xf2,0x12,0x05,0x3f,0x1b,0x97,0xc0,0xe5,0xe3,0x81,0xcf,0x43,0x25,0x0a,0x6e,0x43,0x28,0x5a,0xf9,0xfb,0x8a,0x3a,0x68,0x96,0xfe,0xae,0x9e,0x0e,0xb6,0x57,0xcf,0xd6,0x3c,0x93,0xee,0xb6,0xae,0x34,0xe9,0x32,0xac,0x68,0x37,0xbd,0x41,0xe5,0xb3,0x00,0x1b,0x32,0x99,0x4e,0x21,0x9f,0x6a,0x2e,0x2e,0x48,0x6a,0x43,0xde,0x0d,0x04,0x12,0xa8,0x9d,0x2b,0xcd,0xbf,0x87,0xff,0x09,0x22,0xc1,0x31,0x4f,0xc8,0xa0,0x08,0xbd,0xbf,0x13,0x2a,0xc8,0xed,0x7e,0xc8,0x2d,0x40,0x7c,0x72,0xe4,0x90,0x7b,0xc2,0x40,0xdd,0xc7,0x44,0x3e,0x57,0xce,0x63,0xcc,0xeb,0xb6,0xc2,0x75,0x85,0x19,0x09,0xd6,0x16,0x8d,0xa7,0x6e,0x69,0x59,0x0e,0x56,0x67,0x7e,0xb2,0x81,0x4e,0xb5,0xe3,0x44,0x88,0x4a,0xcd,0x85,0x95,0xa2,0x55,0xdd,0xec,0x68,0x56,0x95,0x50,0x43,0x86,0x2f,0xb9,0x5d,0xf6,0xcd,0xf0,0xe4,0xd4,0x75,0x1d,0x59,0x90,0x6a,0x86,0xe1,0xbf,0x60,0x73,0x9a,0x09,0xdb,0x2d,0x86,0xb6,0xc7,0x02,0xea,0xf2,0xa2,0xce,0xc1,0x0f,0x51,0x4e,0xd9,0xc7,0x63,0x5a,0x95,0xfa,0x1e,0xdc,0x13,0x81,0xad,0x9a,0x42,0x81,0x79,0x10,0xdd,0x07,0x0a,0xfc,0x96,0xd4,0x27,0x45,0x95,0x4f,0x55,0x37,0x6a,0xc6,0x05,0x3f,0x55,0x63,0x6a,0x86,0xa6,0x70,0xe1,0x67,0x6a,0x97,0x01,0x9d,0x99,0x6e,0x71,0xdc,0x23,0x93,0x07,0xcd,0xfb,0xe5,0x4b,0xb2,0x4b,0x77,0x53,0xa3,0xab,0x3a,0xf1,0xae,0xeb,0x41,0xf2,0xb5,0xa6,0xd2,0x08,0xb8,0x3a,0x4b,0x64,0xbf,0x54,0x25,0xaf,0x60,0x97,0x99,0xfb,0xec,0x7a,0xf6,0xe5,0x70,0x93,0xb7,0xfd,0xd2,0xcf,0x78,0x1f,0xdc,0x36,0xf6,0xbc,0xd5,0x2e,0xc3,0xc3,0x90,0x08,0x9e,0x70,0xeb,0xfa,0x31,0x4c,0xb2,0x30,0x07,0x13,0x98,0xe2,0xcb,0x51,0x01,0x32,0x4e,0x6f,0xc9,0x68,0x48,0x12,0x83,0xb4,0x4b,0x6b,0x53,0x9c,0x50,0x16,0xdc,0x2e,0xb3,0x59,0x10,0xa9,0x24,0x94,0x4c,0x49,0x0e,0x7d,0x28,0x84,0x97,0xa1,0xef,0xe6,0x8e,0x99,0x74,0x74,0x7c,0xc7,0x36,0x34,0x49,0x05,0x33,0x21,0x8c,0x9d,0xb3,0x30,0x81,0xae,0xcf,0x74,0x49,0x79,0x07,0x02,0xc2,0x88,0x09,0x91,0x2e,0xe1,0xe9,0x0e,0x1b,0x9c,0x56,0x02,0x06,0xc0,0x3b,0x1d,0xdd,0x45,0x54,0x87,0xeb,0xf5,0x3a,0x84,0xf1,0x87,0x6d,0x02,0x7c,0x6f,0xad,0xca,0x04,0x75,0xec,0xda,0x8d,0x2d,0x3c,0x8b,0x77,0x8b,0x54,0x38,0x69,0xe1,0x08,0x74,0x81,0x7e,0xed,0xa1,0x7f,0xf0,0x5e,0x29,0xca,0x83,0xcf,0xbb,0xc5,0xa5,0xe3,0x6a,0x03,0x5e,0x40,0xd8,0x1c,0xda,0x69,0x4c,0x7e,0xfe,0x74,0xe0,0x41,0x79,0x29,0x91,0xf3,0x29,0x58,0x5a,0x0f,0x9b,0x05,0xdb,0x9b,0x41,0x84,0x89,0xaa,0xd4,0xa2,0x99,0xab,0x95,0x94,0x27,0xb4,0x29,0x3e,0x9a,0xd9,0x4c,0x17,0xef,0x8c,0xae,0x54,0x60,0xcc,0x8b,0x96,0x55,0x0f,0xa8,0xbd,0x8d,0xc3,0x8b,0x1b,0x83,0x39,0x10,0x1b,0xc4,0x6e,0x62,0xe4,0xdf,0xc5,0xf5,0x8a,0xfd,0x6b,0xe3,0x9b,0x1f,0x98,0xfd,0xa2,0x76,0xc5,0xd6,0xd9,0xba,0x89,0x04,0xe7,0xc6,0x52,0xe3,0x17,0x0d,0xbf,0xfc,0x81,0xe1,0x1e,0x90,0x6e,0xd3,0x39,0x3d,0x32,0x86,0xfd,0x7a,0xbd,0x74,0x81,0xc9,0x84,0x0c,0x7b,0x0d,0x7d,0x1d,0xe3,0x1a,0x59,0x4d,0x07,0x38,0xc0,0x12,0xc8,0x17,0xdd,0x6e,0x2f,0x1f,0x43,0x9b,0x15,0x52,0x27,0x96,0x99,0x80,0x69,0x65,0xf7,0xdc,0x45,0x13,0xad,0xad,0x3b,0xa3,0x0f,0x72,0xfd,0xba,0xd9,0xb7,0x1b,0x35,0xb7,0xf9,0xaa,0x4c,0x9f,0x6c,0xdd,0x37,0x2b,0xcb,0x93,0x89,0xc0,0xbd,0xb7,0x04,0x16,0x09,0xe7,0x4a,0xe3,0x48,0xda,0x71,0x0b,0x44,0x8d,0xa0,0xc4,0xa0,0x74,0x10,0x8b,0xa5,0x94,0x6e,0xfa,0xae,0x94,0x90,0x4b,0xb1,0x1e,0xf6,0x3a,0xb9,0x6c,0xf4,0x6c,0x4a,0xe5,0x05,0x5b,0x68,0xc6,0xd0,0x11,0x0e,0xf5,0x77,0x72,0x36,0x84,0x01,0xef,0x41,0x7f,0xa8,0x30,0x16,0xfe,0x0e,0xa9,0x40,0x8e,0x75,0x13,0x54,0x0d,0x6f,0x07,0xce,0x07,0x35,0x21,0xa0,0x43,0x1f,0x15,0xaa,0xf1,0x70,0x2f,0xd0,0xf0,0x36,0xe6,0x5f,0x49,0x26,0xa1,0x7f,0x0f,0x0b,0xdd,0xbf,0x40,0xbf,0x00,0x72,0xf6,0x25,0xdc,0x0c,0x12,0x00,0x00
  11. };
  12.  
  13. // ROUTER ALIMOU
  14. const char* ssid = "MYROUTER";
  15. const char* password = "MYPASS";
  16.  
  17. #define PWDN_GPIO_NUM 32
  18. #define RESET_GPIO_NUM -1
  19. #define XCLK_GPIO_NUM 0
  20. #define SIOD_GPIO_NUM 26
  21. #define SIOC_GPIO_NUM 27
  22. #define Y9_GPIO_NUM 35
  23. #define Y8_GPIO_NUM 34
  24. #define Y7_GPIO_NUM 39
  25. #define Y6_GPIO_NUM 36
  26. #define Y5_GPIO_NUM 21
  27. #define Y4_GPIO_NUM 19
  28. #define Y3_GPIO_NUM 18
  29. #define Y2_GPIO_NUM 5
  30. #define VSYNC_GPIO_NUM 25
  31. #define HREF_GPIO_NUM 23
  32. #define PCLK_GPIO_NUM 22
  33.  
  34. camera_fb_t * fb = NULL;
  35.  
  36. using namespace websockets;
  37. WebsocketsServer WSserver;
  38. AsyncWebServer webserver(8082);
  39.  
  40. // Arduino like analogWrite
  41. // value has to be between 0 and valueMax
  42. void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 180) {
  43. // calculate duty, 8191 from 2 ^ 13 - 1
  44. uint32_t duty = (8191 / valueMax) * min(value, valueMax);
  45. ledcWrite(channel, duty);
  46. }
  47.  
  48. void setup() {
  49. WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
  50. Serial.begin(115200);
  51. // Ai-Thinker: pins 2 and 12
  52. ledcSetup(2, 50, 16); //channel, freq, resolution
  53. ledcAttachPin(2, 2); // pin, channel
  54. ledcSetup(4, 50, 16);
  55. ledcAttachPin(12, 4);
  56.  
  57. camera_config_t config;
  58. config.ledc_channel = LEDC_CHANNEL_0;
  59. config.ledc_timer = LEDC_TIMER_0;
  60. config.pin_d0 = Y2_GPIO_NUM;
  61. config.pin_d1 = Y3_GPIO_NUM;
  62. config.pin_d2 = Y4_GPIO_NUM;
  63. config.pin_d3 = Y5_GPIO_NUM;
  64. config.pin_d4 = Y6_GPIO_NUM;
  65. config.pin_d5 = Y7_GPIO_NUM;
  66. config.pin_d6 = Y8_GPIO_NUM;
  67. config.pin_d7 = Y9_GPIO_NUM;
  68. config.pin_xclk = XCLK_GPIO_NUM;
  69. config.pin_pclk = PCLK_GPIO_NUM;
  70. config.pin_vsync = VSYNC_GPIO_NUM;
  71. config.pin_href = HREF_GPIO_NUM;
  72. config.pin_sscb_sda = SIOD_GPIO_NUM;
  73. config.pin_sscb_scl = SIOC_GPIO_NUM;
  74. config.pin_pwdn = PWDN_GPIO_NUM;
  75. config.pin_reset = RESET_GPIO_NUM;
  76. config.xclk_freq_hz = 20000000;
  77. config.pixel_format = PIXFORMAT_JPEG;
  78. //init with high specs to pre-allocate larger buffers
  79. if (psramFound()) {
  80. config.frame_size = FRAMESIZE_UXGA;
  81. config.jpeg_quality = 10;
  82. config.fb_count = 2;
  83. } else {
  84. config.frame_size = FRAMESIZE_SVGA;
  85. config.jpeg_quality = 12;
  86. config.fb_count = 1;
  87. }
  88.  
  89. // camera init
  90. esp_err_t err = esp_camera_init(&config);
  91. if (err != ESP_OK) {
  92. Serial.printf("Camera init failed with error 0x%x", err);
  93. return;
  94. }
  95.  
  96. sensor_t * s = esp_camera_sensor_get();
  97. s->set_framesize(s, FRAMESIZE_QVGA);
  98.  
  99. WiFi.mode(WIFI_STA);
  100. WiFi.begin(ssid, password);
  101.  
  102. // Wait for connection
  103. while (WiFi.status() != WL_CONNECTED) {
  104. delay(500);
  105. Serial.print(".");
  106. }
  107.  
  108. Serial.println("");
  109. Serial.print("Connected to ");
  110. Serial.print("IP address: ");
  111. Serial.println(WiFi.localIP());
  112.  
  113. webserver.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
  114. AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", index_html_gz, sizeof(index_html_gz));
  115. response->addHeader("Content-Encoding", "gzip");
  116. request->send(response);
  117. });
  118.  
  119. webserver.begin();
  120. WSserver.listen(8084);
  121. }
  122.  
  123.  
  124. void handle_message(WebsocketsMessage msg) {
  125. int commaIndex = msg.data().indexOf(',');
  126. int panValue = msg.data().substring(0, commaIndex).toInt();
  127. int tiltValue = msg.data().substring(commaIndex + 1).toInt();
  128.  
  129. panValue = map(panValue, -90, 90, 0, 180); // 0-180
  130. tiltValue = map(tiltValue, -90, 90, 180, 0); // 0-180 reversed
  131.  
  132. ledcAnalogWrite(2, panValue); // channel, value
  133. ledcAnalogWrite(4, tiltValue);
  134. }
  135.  
  136. void loop() {
  137. auto client = WSserver.accept();
  138. client.onMessage(handle_message);
  139. while (client.available()) {
  140. client.poll();
  141. fb = esp_camera_fb_get();
  142. client.sendBinary((const char *)fb->buf, fb->len);
  143. esp_camera_fb_return(fb);
  144. fb = NULL;
  145. }
  146. }
RAW Paste Data