ESP32-CAM + Blynk: Device won't connect

Hello there!

For my first time trying Blynk out, I am trying to make a project that has been done by a handful of people: a PIR sensor hooked to an ESP32-CAM that should alert my Blynk app whenever it goes HIGH and take pictures that are also displayed in the app.

I set-up the quickstart device and it worked perfectly. Went through the docs a bit and learned to use the digital pins of the ESP32, as well as read values in the Blynk app. Perfect.

However, when I tried to use the ESP32-CAM webserver alongside the Blynk app, the camera webserver will work just fine but my device will not connect. I was under the impression that, since what changed was that I am setting up the camera webserver on top of trying to connect to Blynk, perhaps both Blynk and the ESP32-CAM are trying to connect to the same address or something?

I am not very knowleadgable when it comes to IP Addresses, Ports, HTTP and whatnot, so I appologize for that. Do you guys recommend any possible solutions? By the way, this is a link to the code I am running

Thanks in advance!

Blynk legacy or IOT ?

There are so many things wrong with the sketch that you are trying to use that I’d suggest you look elsewhere for a solution.

Pete.

IoT, I believe? The newest one

The sketch does look outdated. I have found the same one or variations of the same one all over, I suspect somebody made this a while ago and it was shared over and over again, but at some point stopped working.

Is it even possible to use Blynk and run the camera web server at the same time, or should I give up on this approach altogether? When you say there are many things wrong with it, does it not follow the latest documentation?

Yes, it’s possible. You’d need to be careful with ports though, and it doesn’t seem to make sense to use a web browser on the phone to view the live images rather than a video stream widget.
To view the images or video stream on your phone when you are away from home then this code wont work without quite a bit of extra work handle dynamic public IP addresses and port forwarding within your router, but that isn’t a Blynk specific issue.

It’s a good indication of tings to come when the author leaves their SSID, Password and Blynk Auth Token in the sketch!

This will only work if the mobile device and the camera are attached to the same network…
Blynk.setProperty(V1, "urls", "http://"+local_IP+"/capture?_cb="+(String)randomNum);

Don’t use delays with Blynk…
delay(1000);

The code is setting-up a WiFi connection…

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

but then Blynk.begin is used rather than Blynk.config and Blynk.connect

Blynk.begin(auth, ssid, password);

The void loop is a cluttered disaster zone with delays and potentially rapidly repeated notifications with no flag to prevent repeats …

void loop() {
  // put your main code here, to run repeatedly:
  Blynk.run();
  if(digitalRead(PIR) == LOW){
  Serial.println("Send Notification");
  Blynk.notify("Alert:Some one has been here.");
  Serial.println("Capture Photo");
  takePhoto();
  delay(3000);
  }
  if(digitalRead(PHOTO) == HIGH){
  Serial.println("Capture Photo");
  takePhoto();
  }  
}

The author clearly doesn’t know how to write Blynk code using a timer instead of blocking delays. I also assume from this:
if(digitalRead(PHOTO) == HIGH){
that digital pins are being used in the app rather than virtual pins.

I’ve not delved any deeper than this, as I’ve already seen enough to tell me what I need to know.

Pete.

It’s a good indication of tings to come when the author leaves their SSID, Password and Blynk Auth Token in the sketch!

Haha I see your point, that is very much true.

You’d need to be careful with ports though, and it doesn’t seem to make sense to use a web browser on the phone to view the live images rather than a video stream widget.

Got it, thanks. For a first prototype, I was thinking of using an Image Gallery widget to solely display images taken every second for five seconds after the PIR is triggered. From what I’ve looked around, the camera seems to be using ports 80 and 81. Can I use any other HTTP port for Blynk?

And thank you so much for the pointers regarding WiFi config issues, delays, and whatnot. I will try to code my own thing up from scratch following the docs and see how it functions.

Here’s another useful tips :

1- when you use blynk IOT, make sure that you are using the latest version of blynk library which is 1.0.1.

2- you should add " BLYNK_TEMPLATE_ID " and " BLYNK_DEVICE_NAME " on top of your sketch, above anything.

3- blynk.notify, blynk.email, and blynk.sms has been replaced with blynk.logEvent.

4- you should always keep your void loop as clean as possible, read this article

5-

I recommend you to read this article

The connection to the Blynk server uses port 80, or port 443 for ssl

Pete.