Thanks for all your answers, I will read them carfully and try to learn
I the meantime some updates:
My current setup is:
ESP32-Cam_Board1: (master)
Pin 2: output 500ms on/off signal
Pin 14: Input for on/off signal
connected external WIFI antenna (changed jumper R)
connected FTDI Adpater
ESP32-Cam_Board2: (slave)
Pin 2: output 500ms on/off signal (not connected)
Pin 14: Input for on/off signal
connected external WIFI antenna (changed jumper R)
Board1_Pin2 is connected to Board1_Pin14 and Board2_Pin14
-> Goal is, that both boards take a picture at the same time.
I tried to attach an interrupt to Pin2, but I always got a panic (LoadProhibited)
So I added the following line to the server thread:
Code: Select all
while (digitalRead(trigger_in_pin) == pin_toggle_in) { }
pin_toggle_in = !pin_toggle_in;
Code is working, but delay is terrible, both received pictures do not match
Timing with only one ESP:
struggles at beginning, but than it runs quite accurate
pc (picture taken) is between ***192 and ***281, don't know if this is accurate enough.
Code: Select all
ets Jun 8 2016 00:22:57
20:47:33.188 ->
20:47:33.188 -> rst:0x1 (POWERON_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
20:47:33.188 -> configsip: 0, SPIWP:0xee
20:47:33.188 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
20:47:33.188 -> mode:DIO, clock div:1
20:47:33.188 -> load:0x3fff0018,len:4
20:47:33.188 -> load:0x3fff001c,len:1100
20:47:33.188 -> load:0x40078000,len:10088
20:47:33.188 -> load:0x40080400,len:6380
20:47:33.188 -> entry 0x400806a4
20:47:36.109 -> ....
20:47:37.618 -> WiFi connected
20:47:37.618 -> Camera Stream Ready! Go to: http://192.168.1.166a
20:47:37.618 -> b
20:47:38.126 ->
20:47:38.126 -> tt 4701158
20:47:38.630 -> tt 5201154
20:47:39.098 -> tt 5701154
20:47:39.603 -> tt 6201154
20:47:40.111 -> tt 6701154
20:47:40.618 -> tt 7201154
20:47:41.119 -> tt 7701154
20:47:41.619 -> tt 8201154
20:47:42.125 -> tt 8701154
20:47:42.600 -> tt 9201154
20:47:43.109 -> tt 9701154
20:47:43.613 -> tt 10201154
20:47:44.112 -> tt 10701154
20:47:44.612 -> tt 11201154
20:47:45.112 -> tt 11701154
20:47:45.612 -> tt 12201154
20:47:46.113 -> tt 12701154 | pd 13127796
20:47:46.610 -> tt 13201172
20:47:47.108 -> tt 13701154
20:47:47.613 -> tt 14201154
20:47:48.115 -> tt 14701154
20:47:48.619 -> tt 15201154
20:47:49.120 -> tt 15701154 | se 15703006
20:47:49.591 -> tt 16201155 | ps 16201210 | pc 16201281 | pd 16201319 | se 16536059
20:47:50.133 -> tt 16701155 | ps 16701211 | pc 16701283 | pd 16701321
20:47:50.601 -> tt 17201154 | se 17295268 | ps 17295287 | pc 17295312 | pd 17295339
20:47:51.104 -> tt 17701158 | se 17770073 | ps 17770092 | pc 17770110 | pd 17770128 | se 18194480
20:47:51.607 -> tt 18201154 | ps 18201173 | pc 18201192 | pd 18201210
20:47:52.107 -> tt 18701158
20:47:52.612 -> tt 19201154 | se 19553159
20:47:53.115 -> tt 19701154 | ps 19701173 | pc 19701192 | pd 19701210
20:47:53.618 -> tt 20201158 | se 20298224 | ps 20298243 | pc 20298261 | pd 20298280 | se 20608384
20:47:54.118 -> tt 20701155 | ps 20701212 | pc 20701282 | pd 20701320 | se 21058077
20:47:54.624 -> tt 21201155 | ps 21201211 | pc 21201281 | pd 21201319
20:47:55.128 -> tt 21701154 | se 21916275 | ps 21916348 | pc 21916379 | pd 21916418
20:47:55.597 -> tt 22201154 | se 22601985 | ps 22602003 | pc 22602022 | pd 22602040
20:47:56.135 -> tt 22701158
20:47:56.604 -> tt 23201154 | se 23235166
20:47:57.103 -> tt 23701155 | ps 23701211 | pc 23701281 | pd 23701319
20:47:57.606 -> tt 24201154 | se 24643718 | ps 24643737 | pc 24643755 | pd 24643778
20:47:58.106 -> tt 24701158 | se 25063657 | ps 25063676 | pc 25063694 | pd 25063712
20:47:58.607 -> tt 25201164 | se 25605617 | ps 25605636 | pc 25605654 | pd 25605673
20:47:59.109 -> tt 25701158 | se 26063450 | ps 26063518 | pc 26063550 | pd 26063588
20:47:59.613 -> tt 26201154 | se 26455889 | ps 26455907 | pc 26455926 | pd 26455944
20:48:00.118 -> tt 26701158 | se 26924327 | ps 26924345 | pc 26924364 | pd 26924382
20:48:00.683 -> tt 27201162 | se 27372388 | ps 27372407 | pc 27372425 | pd 27372444
20:48:01.117 -> tt 27701158 | se 27745281 | ps 27745300 | pc 27745318 | pd 27745336 | se 28088722
20:48:01.620 -> tt 28201154 | ps 28201174 | pc 28201192 | pd 28201210
20:48:02.125 -> tt 28701158 | se 28919327 | ps 28919398 | pc 28919430 | pd 28919468
20:48:02.627 -> tt 29201154 | se 29260012 | ps 29260031 | pc 29260049 | pd 29260068
20:48:03.126 -> tt 29701158 | se 29824112 | ps 29824130 | pc 29824149 | pd 29824167
20:48:03.593 -> tt 30201158 | se 30233957 | ps 30233986 | pc 30234004 | pd 30234023
20:48:04.131 -> tt 30701158 | se 31059424 | ps 31059443 | pc 31059461 | pd 31059480
20:48:04.604 -> tt 31201158
20:48:05.110 -> tt 31701154 | se 31798560
20:48:05.615 -> tt 32201155 | ps 32201208 | pc 32201276 | pd 32201315 | se 32515782
20:48:06.115 -> tt 32701155 | ps 32701211 | pc 32701283 | pd 32701321 | se 33038717
20:48:06.620 -> tt 33201155 | ps 33201211 | pc 33201281 | pd 33201319
20:48:07.122 -> tt 33701154 | se 33841245 | ps 33841263 | pc 33841282 | pd 33841300
20:48:07.592 -> tt 34201158 | se 34542489 | ps 34542508 | pc 34542526 | pd 34542544
20:48:08.128 -> tt 34701158 | se 34846038 | ps 34846057 | pc 34846075 | pd 34846093
20:48:08.629 -> tt 35201158 | se 35318750 | ps 35318769 | pc 35318791 | pd 35318810 | se 35601899
20:48:09.102 -> tt 35701157 | ps 35701178 | pc 35701197 | pd 35701215 | se 36160949
20:48:09.604 -> tt 36201154 | ps 36201173 | pc 36201192 | pd 36201210 | se 36527453
20:48:10.135 -> tt 36701155 | ps 36701212 | pc 36701282 | pd 36701321 | se 37057160
20:48:10.607 -> tt 37201154 | ps 37201210 | pc 37201281 | pd 37201319 | se 37527759
20:48:11.110 -> tt 37701155 | ps 37701211 | pc 37701286 | pd 37701325 | se 37942758
20:48:11.611 -> tt 38201154 | ps 38201174 | pc 38201192 | pd 38201210 | se 38540239
20:48:12.110 -> tt 38701155 | ps 38701214 | pc 38701293 | pd 38701331 | se 38935499
20:48:12.615 -> tt 39201155 | ps 39201211 | pc 39201283 | pd 39201321 | se 39549983
20:48:13.118 -> tt 39701154 | ps 39701174 | pc 39701192 | pd 39701210 | se 40109853
20:48:13.621 -> tt 40201154 | ps 40201173 | pc 40201192 | pd 40201210 | se 40617563
20:48:14.119 -> tt 40701154 | ps 40701173 | pc 40701192 | pd 40701210 | se 40949433
20:48:14.620 -> tt 41201154 | ps 41201173 | pc 41201192 | pd 41201210 | se 41625085
20:48:15.126 -> tt 41701155 | ps 41701211 | pc 41701281 | pd 41701319 | se 41947639
20:48:15.596 -> tt 42201154 | ps 42201174 | pc 42201192 | pd 42201210 | se 42476039
20:48:16.103 -> tt 42701154 | ps 42701174 | pc 42701192 | pd 42701210 | se 42981356
20:48:16.604 -> tt 43201155 | ps 43201211 | pc 43201281 | pd 43201319 | se 43448524
20:48:17.109 -> tt 43701155 | ps 43701213 | pc 43701285 | pd 43701325 | se 43937224
20:48:17.613 -> tt 44201154 | ps 44201174 | pc 44201192 | pd 44201210 | se 44551234
20:48:18.113 -> tt 44701155 | ps 44701211 | pc 44701281 | pd 44701319 | se 44981864
20:48:18.612 -> tt 45201155 | ps 45201213 | pc 45201285 | pd 45201323 | se 45452893
20:48:19.113 -> tt 45701155 | ps 45701211 | pc 45701283 | pd 45701321 | se 45978720
20:48:19.614 -> tt 46201155 | ps 46201211 | pc 46201281 | pd 46201319 | se 46496186
20:48:20.114 -> tt 46701155 | ps 46701211 | pc 46701281 | pd 46701319 | se 46941761
20:48:20.618 -> tt 47201155 | ps 47201211 | pc 47201281 | pd 47201319 | se 47578445
20:48:21.122 -> tt 47701154 | ps 47701174 | pc 47701192 | pd 47701210 | se 48040545
20:48:21.592 -> tt 48201154 | ps 48201173 | pc 48201192 | pd 48201210 | se 48558969
20:48:22.129 -> tt 48701158 | ps 48701178 | pc 48701196 | pd 48701215 | se 49085881
20:48:22.599 -> tt 49201154 | ps 49201173 | pc 49201192 | pd 49201210 | se 49629599
20:48:23.103 -> tt 49701154 | ps 49701173 | pc 49701192 | pd 49701210 | se 50000865
20:48:23.607 -> tt 50201155 | ps 50201211 | pc 50201281 | pd 50201319 | se 50460546
20:48:24.107 -> tt 50701153 | ps 50701209 | pc 50701280 | pd 50701318 | se 51024843
20:48:24.612 -> tt 51201153 | ps 51201173 | pc 51201191 | pd 51201209 | se 51537020
20:48:25.112 -> tt 51701158 | ps 51701209 | pc 51701268 | pd 51701307 | se 52077294
20:48:25.622 -> tt 52201153 | ps 52201173 | pc 52201191 | pd 52201209 | se 52578533
20:48:26.130 -> tt 52701153 | ps 52701209 | pc 52701280 | pd 52701318 | se 53076743
20:48:26.603 -> tt 53201152 | ps 53201172 | pc 53201191 | pd 53201209 | se 53587590
20:48:27.104 -> tt 53701152 | ps 53701172 | pc 53701191 | pd 53701209 | se 53976094
20:48:27.607 -> tt 54201153 | ps 54201209 | pc 54201280 | pd 54201320 | se 54487047
20:48:28.114 -> tt 54701152 | ps 54701172 | pc 54701191 | pd 54701209 | se 55056499
20:48:28.617 -> tt 55201157 | ps 55201193 | pc 55201211 | pd 55201229 | se 55535478
20:48:29.118 -> tt 55701153 | ps 55701209 | pc 55701282 | pd 55701320 | se 55905039
20:48:29.620 -> tt 56201156 | ps 56201218 | pc 56201291 | pd 56201331 | se 56576375
20:48:30.120 -> tt 56701153 | ps 56701209 | pc 56701280 | pd 56701318 | se 56943346
20:48:30.626 -> tt 57201153 | ps 57201173 | pc 57201191 | pd 57201209 | se 57572715
20:48:31.098 -> tt 57701152 | ps 57701172 | pc 57701191 | pd 57701209 | se 58096635
Timing with both ESP active:
You can see, that timing of the server routine se is printed directly after trigger, looks like it is ~500ms delayed.
Code: Select all
20:59:30.072 -> tt 11755165
20:59:30.574 -> tt 12255165
20:59:31.076 -> tt 12755165
20:59:31.581 -> tt 13255165
20:59:32.079 -> tt 13755180 | pd 13928319
20:59:32.583 -> tt 14255167 | se 14563217 | ps 14563238 | pc 14563263 | pd 14563291 | se 14654807 | ps 14702941 | pc 14703012 | pd 14736270
20:59:33.084 -> tt 14755165 | se 14851103 | ps 15202899 | pc 15202917 | pd 15202935
20:59:33.587 -> tt 15255172 | se 15304066 | ps 15702935 | pc 15703008 | pd 15703049
20:59:34.089 -> tt 15755168 | se 15805884 | ps 16202937 | pc 16203013 | pd 16203053
20:59:34.589 -> tt 16255165 | se 16290817 | ps 16702889 | pc 16702907 | pd 16702926
20:59:35.088 -> tt 16755170 | se 16794487 | ps 17202887 | pc 17202906 | pd 17202924
20:59:35.593 -> tt 17255172 | se 17301098 | ps 17702926 | pc 17703001 | pd 17703040
20:59:36.063 -> tt 17755167 | se 17844896 | ps 18202879 | pc 18202898 | pd 18202916
20:59:36.560 -> tt 18255172 | se 18380561 | ps 18702921 | pc 18702996 | pd 18703035
20:59:37.101 -> tt 18755167 | se 18886039 | ps 19202878 | pc 19202896 | pd 19202914
20:59:37.568 -> tt 19255173 | se 19384545 | ps 19702910 | pc 19702983 | pd 19703022
20:59:38.067 -> tt 19755167 | se 19880184 | ps 20202913 | pc 20202992 | pd 20203033
20:59:38.570 -> tt 20255165 | se 20287538 | ps 20702863 | pc 20702881 | pd 20702900
20:59:39.072 -> tt 20755169 | se 20790233 | ps 21202913 | pc 21202992 | pd 21203033
20:59:39.575 -> tt 21255167 | se 21294388 | ps 21702899 | pc 21702976 | pd 21703021
20:59:40.079 -> tt 21755165 | se 21801682 | ps 22202854 | pc 22202872 | pd 22202890
20:59:40.582 -> tt 22255172 | se 22300583 | ps 22702891 | pc 22702965 | pd 22703005
20:59:41.081 -> tt 22755165 | se 22800160 | ps 23202891 | pc 23202966 | pd 23203008
20:59:41.580 -> tt 23255166 | se 23298388 | ps 23702914 | pc 23703030 | pd 23703086
20:59:42.084 -> tt 23755165 | se 23793842 | ps 24202883 | pc 24202959 | pd 24203000
20:59:42.589 -> tt 24255168 | se 24302013 | ps 24702838 | pc 24702856 | pd 24702874
20:59:43.096 -> tt 24755169 | se 24797716 | ps 25202876 | pc 25202946 | pd 25202989
20:59:43.567 -> tt 25255165 | se 25333917 | ps 25702875 | pc 25702951 | pd 25702992
20:59:44.071 -> tt 25755165 | se 25862551 | ps 26202828 | pc 26202846 | pd 26202865
20:59:44.576 -> tt 26255171 | se 26412536 | ps 26702865 | pc 26702938 | pd 26702980
20:59:45.079 -> tt 26755165 | se 26905678 | ps 27202862 | pc 27202932 | pd 27202971
20:59:45.581 -> tt 27255165 | se 27396961 | ps 27702891 | pc 27703010 | pd 27703066
20:59:46.080 -> tt 27755166 | se 27878512 | ps 28202861 | pc 28202938 | pd 28202980
20:59:46.582 -> tt 28255165 | se 28286290 | ps 28702854 | pc 28702930 | pd 28702971
20:59:47.079 -> tt 28755165 | se 28783443 | ps 29202853 | pc 29202937 | pd 29202982
20:59:47.584 -> tt 29255165 | se 29289408 | ps 29702847 | pc 29702924 | pd 29702964
20:59:48.092 -> tt 29755166 | se 29797051 | ps 30202802 | pc 30202820 | pd 30202839
20:59:48.565 -> tt 30255170 | se 30297965 | ps 30702841 | pc 30702913 | pd 30702951
20:59:49.098 -> tt 30755166 | se 30798257 | ps 31202796 | pc 31202814 | pd 31202833
20:59:49.568 -> tt 31255172 | se 31288826 | ps 31702864 | pc 31702981 | pd 31703042
20:59:50.072 -> tt 31755165 | se 31795681 | ps 32202831 | pc 32202908 | pd 32202948
20:59:50.572 -> tt 32255165 | se 32292408 | ps 32702830 | pc 32702904 | pd 32702942
20:59:51.074 -> tt 32755165 | se 32787911 | ps 33202783 | pc 33202801 | pd 33202820
20:59:51.575 -> tt 33255173 | se 33290345 | ps 33702781 | pc 33702800 | pd 33702818
20:59:52.073 -> tt 33755171 | se 33799841 | ps 34202782 | pc 34202800 | pd 34202818
20:59:52.571 -> tt 34255169 | se 34316207 | ps 34702818 | pc 34702890 | pd 34702928
20:59:53.073 -> tt 34755165 | se 34824995 | ps 35202817 | pc 35202889 | pd 35202930
20:59:53.576 -> tt 35255165 | se 35336020 | ps 35702767 | pc 35702787 | pd 35702806
20:59:54.075 -> tt 35755172 | se 35801241 | ps 36202815 | pc 36202891 | pd 36202931
20:59:54.578 -> tt 36255165 | se 36314716 | ps 36702808 | pc 36702886 | pd 36702926
20:59:55.078 -> tt 36755167 | se 36821669 | ps 37202799 | pc 37202878 | pd 37202918
20:59:55.585 -> tt 37255166 | se 37328601 | ps 37702758 | pc 37702782 | pd 37702801
20:59:56.086 -> tt 37755171 | se 37840446 | ps 38202758 | pc 38202778 | pd 38202797
20:59:56.558 -> tt 38255169 | se 38341147 | ps 38702752 | pc 38702771 | pd 38702791
20:59:57.095 -> tt 38755171 | se 38807446 | ps 39202744 | pc 39202763 | pd 39202788
20:59:57.597 -> tt 39255172 | se 39330338 | ps 39702741 | pc 39702759 | pd 39702782
20:59:58.064 -> tt 39755172 | se 39811314 | ps 40202837 | pc 40202913 | pd 40202954
20:59:58.564 -> tt 40255165 | se 40335772 | ps 40702739 | pc 40702757 | pd 40702777
20:59:59.100 -> tt 40755171 | se 40810687 | ps 41202741 | pc 41202760 | pd 41202782
20:59:59.571 -> tt 41255173 | se 41352240 | ps 41702733 | pc 41702751 | pd 41702772
21:00:00.074 -> tt 41755169 | se 41802066 | ps 42202725 | pc 42202743 | pd 42202762
21:00:00.581 -> tt 42255173 | se 42332156 | ps 42702723 | pc 42702742 | pd 42702760
21:00:01.081 -> tt 42755169 | se 42835222 | ps 43202758 | pc 43202889 | pd 43202931
21:00:01.581 -> tt 43255165 | se 43329169 | ps 43702738 | pc 43702756 | pd 43702777
21:00:02.081 -> tt 43755169 | se 43819667 | ps 44202759 | pc 44202886 | pd 44202927
21:00:02.580 -> tt 44255165 | se 44325933 | ps 44702756 | pc 44702839 | pd 44702879
21:00:03.081 -> tt 44755165 | se 44800700 | ps 45202752 | pc 45202830 | pd 45202869
21:00:03.583 -> tt 45255167 | se 45330316 | ps 45702747 | pc 45702826 | pd 45702866
21:00:04.088 -> tt 45755165 | se 45817833 | ps 46202741 | pc 46202817 | pd 46202858
21:00:04.591 -> tt 46255165 | se 46316351 | ps 46702738 | pc 46702814 | pd 46702853
21:00:05.097 -> tt 46755167 | se 46816611 | ps 47202719 | pc 47202737 | pd 47202755
21:00:05.568 -> tt 47255169 | se 47354503 | ps 47702694 | pc 47702712 | pd 47702731
21:00:06.069 -> tt 47755169 | se 47826374 | ps 48202728 | pc 48202807 | pd 48202848
21:00:06.573 -> tt 48255165 | se 48325709 | ps 48702683 | pc 48702701 | pd 48702720
21:00:07.078 -> tt 48755169 | se 48812898 | ps 49202718 | pc 49202807 | pd 49202848
21:00:07.578 -> tt 49255165 | se 49318084 | ps 49702681 | pc 49702699 | pd 49702718
21:00:08.079 -> tt 49755170 | se 49857605 | ps 50202673 | pc 50202692 | pd 50202710
21:00:08.578 -> tt 50255172 | se 50387991 | ps 50702701 | pc 50702759 | pd 50702804
21:00:09.081 -> tt 50755163 | se 50999787 | ps 51202702 | pc 51202778 | pd 51202818
21:00:09.586 -> tt 51255163 | se 51481676 | ps 51702663 | pc 51702681 | pd 51702699
21:00:10.088 -> tt 51755168 | se 51905158 | ps 52202707 | pc 52202787 | pd 52202827
21:00:10.559 -> tt 52255163 | se 52428234 | ps 52702694 | pc 52702773 | pd 52702813
21:00:11.098 -> tt 52755163 | se 52951617 | ps 53202689 | pc 53202759 | pd 53202804
21:00:11.597 -> tt 53255163 | se 53390871 | ps 53702650 | pc 53702668 | pd 53702686
21:00:12.064 -> tt 53755171 | se 53797474 | ps 54202646 | pc 54202665 | pd 54202710
Attached you can find my latest code.
Code: Select all
#include "esp_camera.h"
#include <WiFi.h>
#include "esp_timer.h"
#include "img_converters.h"
#include "Arduino.h"
#include "fb_gfx.h"
#include "soc/soc.h" //disable brownout problems
#include "soc/rtc_cntl_reg.h" //disable brownout problems
#include "dl_lib.h"
#include "esp_http_server.h"
//Replace with your network credentials
const char* ssid = "xx";
const char* password = "xx";
#define PART_BOUNDARY "123456789000000000000987654321"
#define CAMERA_MODEL_AI_THINKER
#if defined(CAMERA_MODEL_AI_THINKER)
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
#else
#error "Camera model not selected"
#endif
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\n\r\n";
httpd_handle_t stream_httpd = NULL;
volatile bool pic = false;
volatile bool pic_done = false;
uint32_t low;
boolean pin_toggle_out = false;
boolean pin_toggle_in = false;
const int trigger_out_pin = 2;
const int trigger_in_pin = 14;
hw_timer_t * timer0 = NULL;
camera_fb_t * fb = NULL;
esp_err_t res = ESP_OK;
size_t _jpg_buf_len = 0;
uint8_t * _jpg_buf = NULL;
char * part_buf[64];
static esp_err_t stream_handler(httpd_req_t *req) {
res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE);
if (res != ESP_OK) {
return res;
}
while (true) {
/* while (!pic)
{
}
*/
while (digitalRead(trigger_in_pin) == pin_toggle_in)
{
}
pin_toggle_in = !pin_toggle_in;
//pic = false;
if (fb) {
Serial.print(" | ps ");
low = esp_timer_get_time() % 0xFFFFFFFF;
Serial.print(low);
esp_camera_fb_return(fb);
Serial.print(" | pc ");
low = esp_timer_get_time() % 0xFFFFFFFF;
Serial.print(low);
fb = NULL;
_jpg_buf = NULL;
} else if (_jpg_buf) {
free(_jpg_buf);
_jpg_buf = NULL;
}
fb = esp_camera_fb_get();
if (!fb) {
Serial.println("Camera capture failed");
res = ESP_FAIL;
} else {
if (fb->width > 400) {
if (fb->format != PIXFORMAT_JPEG) {
bool jpeg_converted = frame2jpg(fb, 80, &_jpg_buf, &_jpg_buf_len);
esp_camera_fb_return(fb);
fb = NULL;
if (!jpeg_converted) {
Serial.println("JPEG compression failed");
res = ESP_FAIL;
}
} else {
_jpg_buf_len = fb->len;
_jpg_buf = fb->buf;
}
}
}
Serial.print(" | pd ");
low = esp_timer_get_time() % 0xFFFFFFFF;
Serial.print(low);
pic_done = true;
//Serial.println("pic!");
if (res == ESP_OK) {
size_t hlen = snprintf((char *)part_buf, 64, _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);
}
if (res == ESP_OK) {
res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));
}
if (fb) {
//esp_camera_fb_return(fb);
//fb = NULL;
//_jpg_buf = NULL;
} else if (_jpg_buf) {
//free(_jpg_buf);
//_jpg_buf = NULL;
}
if (res != ESP_OK) {
break;
}
Serial.print(" | se ");
low = esp_timer_get_time() % 0xFFFFFFFF;
Serial.print(low);
//Serial.printf(" MJPG: %uB\n", (uint32_t)(_jpg_buf_len));
}
return res;
}
void startCameraServer() {
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
config.server_port = 80;
httpd_uri_t index_uri = {
.uri = "/",
.method = HTTP_GET,
.handler = stream_handler,
.user_ctx = NULL
};
//Serial.printf("Starting web server on port: '%d'\n", config.server_port);
if (httpd_start(&stream_httpd, &config) == ESP_OK) {
httpd_register_uri_handler(stream_httpd, &index_uri);
}
}
void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
Serial.begin(115200);
Serial.setDebugOutput(false);
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
if (psramFound()) {
config.frame_size = FRAMESIZE_UXGA; //UXGA
config.jpeg_quality = 10;
config.fb_count = 2;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 12;
config.fb_count = 1;
}
// Camera init
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x", err);
return;
}
// Wi-Fi connection
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("Camera Stream Ready! Go to: http://");
Serial.print(WiFi.localIP());
// Start streaming web server
startCameraServer();
pinMode(trigger_out_pin, OUTPUT);
pinMode(trigger_in_pin, INPUT);
Serial.println("a");
//attachInterrupt(digitalPinToInterrupt(14), triggerin2, CHANGE); //DOes not work
Serial.println("b");
timer0 = timerBegin(0, 80, true);
timerAttachInterrupt(timer0, &ontimer0, true);
timerAlarmWrite(timer0, 500000, true);
timerAlarmEnable(timer0);
}
void loop() {
delay(1);
}
void triggerin()
{
//Interrupt does not work!
Serial.println();
Serial.print("ti ");
low = esp_timer_get_time() % 0xFFFFFFFF;
Serial.print(low);
pic = true;
}
void ontimer0() {
Serial.println();
Serial.print("tt ");
low = esp_timer_get_time() % 0xFFFFFFFF;
Serial.print(low);
if (pin_toggle_out) {
pin_toggle_out = false;
} else {
pin_toggle_out = true;
}
digitalWrite(trigger_out_pin, pin_toggle_out);
}