Good morning gentlemen i hope we are all well in these trying times, i have been observing this forum from a far and i must admit there are some very clever people in this forum, and your discussions here have helped me so much with the issues in my projects as the have arisen, without the need to ask any questions... until today, i hope you Honorable gentlemen and ladies could spare the time to help me with my conundrum,
Bellow of my code and here is the purpose of my project and the why it has been done this way ,thus far. my current project is a simple iot camera stream with a time lapse function that is all controlled on the blynk app. its designed to be placed in my green house, and show a live feed to my blink app,(where my current environmental sensors and controllers live) i will also add time lapse function, that will take a nice time lapse of my garden growing and then dieing through the year, the time laps code works great on its own and i can take an image any time by commanding virtual pin 2 high via the blynk app switch widget.
how ever it has been a nightmare trying to get an image from that camera on to the blynk app. i had tried HTTP , rtsp and web server codes with no successes, however i did find a doorbell code that takes a single image and sends it to blynk, and this works, when i drive v3 high , and image is captured and sent to blynk
and this is where i am at the moment, if i hold v3 high only one image is taken. however if i repeatedly tap the button in the app, i can get about 5 frames a second, which would be fine for my purpose. of looking at a green house, for the last few days i have been trying to write the piece of code that represents me tapping the button, i started with delays, but blynk doesn't like them, i am now trying simpletimer. i can get the capture function to loop when V3 is high but when v2 is low, it does not stop looping,
once this issue is resolved i can simple add the capture and save to sd card function to V3 if low and capture and send to blynk if high. and ill use the eventor widget in app to toggle the state at a timed interval
i hope i have explain my issue enough, i would like to simply start and stop a function that loops at a certain interval. via Virtual pin 3 HIGH/LOW state change. Please enlighten me with your wisdom.
#define BLYNK_PRINT Serial
#include <SimpleTimer.h>
#include "esp_camera.h"
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define CAMERA_MODEL_AI_THINKER
#include "camera_pins.h"
SimpleTimer timer;
const char* ssid = "SKY4ED26";
const char* password = "QDLMCXBMRT";
char auth[] = "1noR_elPy_pkZivlLlkX7HCtXUi-pbD3";
String my_Local_IP;
void startCameraServer();
void capture()
{
uint32_t number = random(40000000);
//Blynk.notify("Someone is at the door..");
Serial.println("http://"+my_Local_IP+"/capture?_cb="+ (String)number);
Blynk.setProperty(V1, "urls", "http://"+my_Local_IP+"/capture?_cb="+(String)number);
}
//this is where i am having issues--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BLYNK_WRITE(V2)
{
int pinValue = param.asInt();
if (pinValue == 1) {
timer.setInterval(250L, capture);
}
//this is where i am having issues--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
}
}
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
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;
//init with high specs to pre-allocate larger buffers
if (psramFound()) {
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 10;
config.fb_count = 2;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 12;
config.fb_count = 1;
}
#if defined(CAMERA_MODEL_ESP_EYE)
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
#endif
// 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;
}
sensor_t * s = esp_camera_sensor_get();
//initial sensors are flipped vertically and colors are a bit saturated
if (s->id.PID == OV3660_PID) {
s->set_vflip(s, 1);//flip it back
s->set_brightness(s, 1);//up the blightness just a bit
s->set_saturation(s, -2);//lower the saturation
}
//drop down frame size for higher initial frame rate
s->set_framesize(s, FRAMESIZE_QVGA);
#if defined(CAMERA_MODEL_M5STACK_WIDE)
s->set_vflip(s, 1);
s->set_hmirror(s, 1);
#endif
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
startCameraServer();
Serial.print("Camera Ready! Use 'http://");
Serial.print(WiFi.localIP());
my_Local_IP = WiFi.localIP().toString();
Serial.println("' to connect");
Blynk.begin(auth, ssid, password);
Blynk.virtualWrite(5, 0);
}
void loop() {
// put your main code here, to run repeatedly:
Blynk.run();
timer.run();
}