hms11

CoopCommandCamREV2FTP

Jul 7th, 2021 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. #define PHOTOCLICK V5
  2. #define LED 4
  3. #define DOORUP V7
  4. #define DOORDOWN V6
  5. #define BLYNK_HEARTBEAT 30
  6. #define BLYNK_FIRMWARE_VERSION "0.1.0"
  7.  
  8. #include "esp_camera.h"
  9. #include "Arduino.h"
  10. #include <WiFi.h>
  11. #include <WiFiClient.h>
  12. #include <ESP32_FTPClient.h>
  13. #include "soc/soc.h" // Disable brownout problems
  14. #include "soc/rtc_cntl_reg.h" // Disable brownout problems
  15. #include <BlynkSimpleEsp32.h>
  16. WidgetLED led1(V1);
  17. WidgetLED led2(V2);
  18. WidgetLED led3(V3);
  19. WidgetLED led4(V4);
  20.  
  21.  
  22. #define WIFI_SSID "xxxxx"
  23. #define WIFI_PASS "xxxxxx"
  24. // char auth[] = "xxxxxx"; //sent by Blynk 1.0
  25. char auth[] = "xxxxx"; //sent by Blynk 2.0
  26. #define BLYNK_TEMPLATE_ID "xxxxx"
  27. #define BLYNK_DEVICE_NAME "xxxxxx"
  28.  
  29. // Pin definition for CAMERA_MODEL_AI_THINKER
  30. #define PWDN_GPIO_NUM 32
  31. #define RESET_GPIO_NUM -1
  32. #define XCLK_GPIO_NUM 0
  33. #define SIOD_GPIO_NUM 26
  34. #define SIOC_GPIO_NUM 27
  35.  
  36. #define Y9_GPIO_NUM 35
  37. #define Y8_GPIO_NUM 34
  38. #define Y7_GPIO_NUM 39
  39. #define Y6_GPIO_NUM 36
  40. #define Y5_GPIO_NUM 21
  41. #define Y4_GPIO_NUM 19
  42. #define Y3_GPIO_NUM 18
  43. #define Y2_GPIO_NUM 5
  44. #define VSYNC_GPIO_NUM 25
  45. #define HREF_GPIO_NUM 23
  46. #define PCLK_GPIO_NUM 22
  47.  
  48.  
  49. char ftp_server[] = "files.000webhost.com";
  50. char ftp_user[] = "coopcommandimages";
  51. char ftp_pass[] ="Speedway*1";
  52.  
  53. bool takePhoto = false;
  54. bool loading = false;
  55. String displayImage = "https://coopcommandimages.000webhostapp.com/uploads/1.png";
  56. String coopImageURL = "https://coopcommandimages.000webhostapp.com/uploads/1.png";
  57. String coopImage = "coopPic.jpg";
  58. int i = 1;
  59. int ic = 1;
  60. int imageFlip = 1;
  61. char coopRx; // Info received from CoopCommand
  62. bool newDataRx = false; //has CoopCam received new data from CoopCommand
  63.  
  64.  
  65. BlynkTimer timer;
  66. // WidgetLCD lcd(V1);
  67.  
  68. // you can pass a FTP timeout and debbug mode on the last 2 arguments
  69. ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass, 5000, 2);
  70.  
  71. void setup()
  72. {
  73. pinMode(LED, OUTPUT);
  74. timer.setInterval(1000,coopCom);
  75. timer.setInterval(250,loadingImage);
  76. Blynk.setProperty(V0, "url", 1, coopImageURL);
  77. Blynk.virtualWrite(V0, 1);
  78. WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
  79.  
  80. camera_config_t config;
  81. config.ledc_channel = LEDC_CHANNEL_0;
  82. config.ledc_timer = LEDC_TIMER_0;
  83. config.pin_d0 = Y2_GPIO_NUM;
  84. config.pin_d1 = Y3_GPIO_NUM;
  85. config.pin_d2 = Y4_GPIO_NUM;
  86. config.pin_d3 = Y5_GPIO_NUM;
  87. config.pin_d4 = Y6_GPIO_NUM;
  88. config.pin_d5 = Y7_GPIO_NUM;
  89. config.pin_d6 = Y8_GPIO_NUM;
  90. config.pin_d7 = Y9_GPIO_NUM;
  91. config.pin_xclk = XCLK_GPIO_NUM;
  92. config.pin_pclk = PCLK_GPIO_NUM;
  93. config.pin_vsync = VSYNC_GPIO_NUM;
  94. config.pin_href = HREF_GPIO_NUM;
  95. config.pin_sscb_sda = SIOD_GPIO_NUM;
  96. config.pin_sscb_scl = SIOC_GPIO_NUM;
  97. config.pin_pwdn = PWDN_GPIO_NUM;
  98. config.pin_reset = RESET_GPIO_NUM;
  99. config.xclk_freq_hz = 20000000;
  100. config.pixel_format = PIXFORMAT_JPEG;
  101.  
  102. if(psramFound()){
  103. config.frame_size = FRAMESIZE_SVGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
  104. config.jpeg_quality = 20;
  105. config.fb_count = 2;
  106. }
  107. else {
  108. config.frame_size = FRAMESIZE_VGA;
  109. config.jpeg_quality = 20;
  110. config.fb_count = 1;
  111. }
  112.  
  113. // Init Camera
  114. esp_err_t err = esp_camera_init(&config);
  115. if (err != ESP_OK) {
  116. // Serial.printf("Camera init failed with error 0x%x", err);
  117. return;
  118. }
  119.  
  120. Serial.begin( 115200 );
  121.  
  122. // WiFi.begin( WIFI_SSID, WIFI_PASS );
  123. Blynk.begin(auth, WIFI_SSID, WIFI_PASS);
  124. // Serial.println("Connecting Wifi...");
  125. // while (WiFi.status() != WL_CONNECTED) {
  126. // delay(500);
  127. // Serial.print(".");
  128. // }
  129. // Serial.println("");
  130. // Serial.print("IP address: ");
  131. // Serial.println(WiFi.localIP());
  132. }
  133.  
  134. BLYNK_CONNECTED() {
  135. Blynk.syncAll();
  136. }
  137.  
  138.  
  139.  
  140. void loadingImage( void ) {
  141. if (loading) {
  142. displayImage= "https://coopcommandimages.000webhostapp.com/uploads/";
  143. displayImage+= i;
  144. displayImage+= ".png";
  145. Blynk.setProperty(V0, "url", 1, displayImage);
  146. if (i <= 6) {
  147. i ++;
  148. }
  149. else if (i > 6) {
  150. i = 1;
  151. }
  152. }
  153. else if (!loading) {
  154. if (ic == 1) {
  155. coopImageURL = "https://coopcommandimages.000webhostapp.com/uploads/coopPic2.jpg";
  156. }
  157. else if (ic == 2) {
  158. coopImageURL = "https://coopcommandimages.000webhostapp.com/uploads/coopPic3.jpg";
  159. }
  160. else if (ic == 3) {
  161. coopImageURL = "https://coopcommandimages.000webhostapp.com/uploads/coopPic4.jpg";
  162. }
  163. Blynk.setProperty(V0, "url", 1, coopImageURL);
  164. Blynk.virtualWrite(V0, 1);
  165. i = 1;
  166. }
  167.  
  168. }
  169.  
  170.  
  171. void sendPhoto ( void ) {
  172. if (takePhoto) {
  173.  
  174. camera_fb_t * fb = NULL;
  175.  
  176. // Take Picture with Camera
  177. fb = esp_camera_fb_get();
  178. digitalWrite(LED, LOW);
  179. delay (50);
  180. if(!fb) {
  181. // Serial.println("Camera capture failed");
  182. ESP.restart();
  183. return;
  184. }
  185.  
  186. if (imageFlip == 1) {
  187. ftp.OpenConnection();
  188. // Create the new file and send the image
  189. ftp.ChangeWorkDir("/public_html/uploads/");
  190. ftp.InitFile("Type I");
  191. ftp.NewFile("coopPic2.jpg");
  192. ftp.WriteData( fb->buf, fb->len );
  193. ftp.CloseFile();
  194. ftp.CloseConnection();
  195. takePhoto = false;
  196. imageFlip = 2;
  197. ic = 1;
  198. esp_camera_fb_return(fb);
  199. Serial.print('N');
  200. }
  201. else if (imageFlip == 2) {
  202. ftp.OpenConnection();
  203. // Create the new file and send the image
  204. ftp.ChangeWorkDir("/public_html/uploads/");
  205. ftp.InitFile("Type I");
  206. ftp.NewFile("coopPic3.jpg");
  207. ftp.WriteData( fb->buf, fb->len );
  208. ftp.CloseFile();
  209. ftp.CloseConnection();
  210. takePhoto = false;
  211. imageFlip = 3;
  212. ic = 2;
  213. esp_camera_fb_return(fb);
  214. Serial.print('N');
  215. }
  216. else if (imageFlip == 3) {
  217. ftp.OpenConnection();
  218. // Create the new file and send the image
  219. ftp.ChangeWorkDir("/public_html/uploads/");
  220. ftp.InitFile("Type I");
  221. ftp.NewFile("coopPic4.jpg");
  222. ftp.WriteData( fb->buf, fb->len );
  223. ftp.CloseFile();
  224. ftp.CloseConnection();
  225. takePhoto = false;
  226. imageFlip = 1;
  227. ic = 3;
  228. esp_camera_fb_return(fb);
  229. Serial.print('N');
  230. }
  231. }
  232. }
  233.  
  234. void coopCom ( void ) {
  235.  
  236. if (Serial.available() > 0) {
  237. coopRx = Serial.read();
  238. newDataRx = true;
  239. }
  240. if (newDataRx == true) {
  241. if (coopRx == 'O') { //If CoopCommand says the door is up
  242. led1.on();
  243. led2.off();
  244. led3.off();
  245. led4.off();
  246. newDataRx = false;
  247. }
  248. if (coopRx == 'S') { //If CoopCommand says the door is down
  249.  
  250. led1.off();
  251. led2.on();
  252. led3.off();
  253. led4.off();
  254. newDataRx = false;
  255. }
  256. if (coopRx == 'U') { //If CoopCommand says the door is opening
  257. led1.off();
  258. led2.off();
  259. led3.on();
  260. led4.off();
  261. newDataRx = false;
  262. }
  263. if (coopRx == 'D') { //If CoopCommand says the door is closing
  264. led1.off();
  265. led2.off();
  266. led3.off();
  267. led4.on();
  268. newDataRx = false;
  269. }
  270. }
  271. }
  272.  
  273. BLYNK_WRITE(DOORUP) {
  274. Serial.print('U');
  275. }
  276.  
  277. BLYNK_WRITE(DOORDOWN) {
  278. Serial.print('D');
  279. }
  280.  
  281. BLYNK_WRITE(V5) {
  282. digitalWrite(LED, HIGH);
  283. Serial.print('L');
  284. takePhoto = true;
  285. loading = true;
  286. loadingImage();
  287. timer.setTimeout(250, sendPhoto);
  288. timer.setTimeout(3000, []()
  289. {
  290. loading = false;
  291. loadingImage();
  292. });
  293. }
  294.  
  295. void loop()
  296. {
  297. Blynk.run();
  298. timer.run();
  299. }
  300.  
Add Comment
Please, Sign In to add comment