Notifications
Clear all

ESP32-CAM Station Connection Issues

8 Posts
4 Users
1 Reactions
1,627 Views
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1903
Topic starter  

I've skimmed through some of the threads dealing with this board, but I've seemed to get past most of those problems, but am having one, I don't know exactly how to deal with...

  1. If I don't do any pre-configuration within the source code, taking all the defaults, the code compiles and uploads just fine.  I've pre-loaded an SD card with the data folder containing config.txt and the MJPEG2SD.htm for the administrative page.
  2. I am able to connect my phone WiFi connection to the ESP32-CAM server and browse to the admin page at 192.168.4.1.  I am able to take a still image and to stream just fine.

The problem occurs when I configure my house's router SSID and password and have the CAM reboot.  It reboots and shows it has a valid configuration, exposes the direct access point again.  Then it appears to successfully connect to my router.  It appears to have some heartbeat mechanism to ping the router to make sure it is still there.  It fails to find it, disconnects and then starts the process over of reconnecting.  

From past experience with ESP8266 controllers, I know that the router connecting process it time and CPU intensive.  This is evident that I can no longer connect to the built-in Access Point and browse to 192.168.4.1.  The browser times out.  My only recourse is to reload the default config.txt file onto the SD card.  Rebooting, I'm back to working through the AP just fine.

I would think that when it connects to my router that DHCP should have given it an IP address, and gateway address that it would then use to Ping the router.  This seems to be where the error is.  I have double checked from my PC that I can ping the router at 192.168.1.1.

Here is the output:

[15:29:26.854 startWifi] Wifi stats for Inqdom - signal strength: -55 dBm; Encryption: WPA2_PSK; channel: 6
[15:29:45.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:29:45.411 setWifiSTA] Wifi Station IP from DHCP
........[15:29:49.118 onWiFiEvent] WiFi Station disconnected
...[15:29:57.349 startWifi] Wifi stats for Inqdom - signal strength: -55 dBm; Encryption: WPA2_PSK; channel: 6
[15:30:15.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:30:15.411 setWifiSTA] Wifi Station IP from DHCP
........[15:30:19.288 onWiFiEvent] WiFi Station disconnected
..[15:30:26.849 startWifi] Wifi stats for Inqdom - signal strength: -55 dBm; Encryption: WPA2_PSK; channel: 6
[15:30:45.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:30:45.411 setWifiSTA] Wifi Station IP from DHCP
.......[15:30:48.630 onWiFiEvent] WiFi Station disconnected
....[15:30:57.349 startWifi] Wifi stats for Inqdom - signal strength: -57 dBm; Encryption: WPA2_PSK; channel: 6
[15:31:15.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:31:15.411 setWifiSTA] Wifi Station IP from DHCP
....[15:31:17.250 onWiFiEvent] WiFi Station connection to Inqdom, using hostname: CAM1
......[15:31:26.851 startWifi] Wifi stats for Inqdom - signal strength: -55 dBm; Encryption: WPA2_PSK; channel: 6
E (666088) ping_sock: send error=0
[15:31:45.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:31:45.411 setWifiSTA] Wifi Station IP from DHCP
[15:31:45.414 onWiFiEvent] WiFi Station disconnected
...[15:31:46.548 onWiFiEvent] WiFi Station disconnected
.......[15:31:56.855 startWifi] Wifi stats for Inqdom - signal strength: -54 dBm; Encryption: WPA2_PSK; channel: 6
[15:32:15.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:32:15.411 setWifiSTA] Wifi Station IP from DHCP
........[15:32:19.061 onWiFiEvent] WiFi Station disconnected
...[15:32:27.349 startWifi] Wifi stats for Inqdom - signal strength: -53 dBm; Encryption: WPA2_PSK; channel: 6
[15:32:45.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:32:45.411 setWifiSTA] Wifi Station IP from DHCP
.....[15:32:47.887 onWiFiEvent] WiFi Station connection to Inqdom, using hostname: CAM1
.....[15:32:56.651 startWifi] Wifi stats for Inqdom - signal strength: -53 dBm; Encryption: WPA2_PSK; channel: 6
E (756088) ping_sock: send error=0
[15:33:15.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:33:15.411 setWifiSTA] Wifi Station IP from DHCP
[15:33:15.414 onWiFiEvent] WiFi Station disconnected
..........[15:33:25.592 onWiFiEvent] WiFi Station disconnected
[15:33:45.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:33:45.411 setWifiSTA] Wifi Station IP from DHCP
.......[15:33:48.663 onWiFiEvent] WiFi Station disconnected
....[15:33:57.349 startWifi] Wifi stats for Inqdom - signal strength: -55 dBm; Encryption: WPA2_PSK; channel: 6
[15:34:15.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:34:15.411 setWifiSTA] Wifi Station IP from DHCP
........[15:34:18.964 onWiFiEvent] WiFi Station disconnected
...[15:34:27.349 startWifi] Wifi stats for Inqdom - signal strength: -62 dBm; Encryption: WPA2_PSK; channel: 6
[15:34:45.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:34:45.411 setWifiSTA] Wifi Station IP from DHCP
..........[15:34:51.695 onWiFiEvent] WiFi Station disconnected
[15:35:15.411 WARN pingTimeout] Failed to ping gateway, restart wifi ... 
[15:35:15.411 setWifiSTA] Wifi Station IP from DHCP

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Quote
(@davee)
Member
Joined: 3 years ago
Posts: 1794
 

Hi @Inq,

re:

The problem occurs when I configure my house's router SSID and password and have the CAM reboot. It reboots and shows it has a valid configuration, exposes the direct access point again.

Sorry, I am definitely losing the plot here ... others might say I lost it a long time ago, but anyway ... 🤔 

My simplistic understanding, is there are two possible arrangements:

 

If you are using a router, then the ESP32-CAM is acting as a client to the router ... so there is no "access point" other than the router itself, and your PC will also be connected to router.

To make this work, if your router normally used the subnet 192.168.1.x, then you would be pointing both the ESP32-CAM (with its software tweaked to be a subnet client), and the PC to login in to the  192.18.1.x subnet, and expect the router to assign them different 192.168.1.x type addresses. This configuration minimises the changes to local WiFi net, as it only adds another client, the ESP32-CAM, but it means the ESP32-CAM has the same priviledges, passwords, etc as the rest of your network.

-------

Alternately, if you do not have a router or wish to leave it undisturbed with its 192.168.1.x subnet, then the ESP32 can become an access point, using the subnet 192.168.4.x, when the ESP32-CAM is using the default software settings. Then the ESP32-CAM software must be tweaked to be an access point, and your PC can be disconnected from your router and connect to the access point, in which case it will be allocated an 192.168.4.x address.

-----

I have the impression you are attempting a kind of impossible cross-breed between these choices, but that is probably just me losing the plot.

Sorry, I haven't looked at your output listing, as without being clear about the software, router and PC configurations, I am not sure what is supposed to be happening.

Best wishes, Dave


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1903
Topic starter  

Nah Dave, not having messed with these ESP8266/ESP32, you wouldn't necessarily know that they can do both at the same time.  That is how many IoT type devices get setup.  The ESP's and IoT devices will expose an Access Point.  You'll see it when you open the WiFi apelet on any computer/mobile device and see a new SSID in the list.  i.e... my vacuum cleaner exposes one and frustratingly there is no way to turn it off.  So I always see it. 

Anyway... you connect to this ESP32 SSID and browse to some page on the ESP32 network (in this case 192.168.4.1) get a webpage and can configure stuff including connecting to your home WiFi router, camera settings and motion detection, etc.  BTW, it also has a switch to use both networks or just one.  Once you reboot, it opens up its network (192.168.4.x) you can still connect to it.  It also is suppose to connect to the router.  In this case, my router is Inqdom and it works on the 192.168.1.x network.  I have seen it from my router's admin page that it has successfully connected and the router's DHCP gives it an IP address.  In this case 192.168.1.128. 

However, in the problem I'm having, the ESP32 tries to ping something and doesn't get a response and forcibly disconnects this 192.168.1.128 connection.  It then repeats the steps over and over ad-nauseum.  And because it ties up the CPU, it's near impossible to re-configure through the UI.

I've yet to find some way of stopping the heartbeat ping or to configure which IP address it's trying to ping.

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1903
Topic starter  

Started digging into the code and found where it does the ping every 30 seconds.  Did a printf and it is trying to ping 0.0.0.0.  Still don't know why its not storing my router's gateway as it does receive the DHCP address the router gave it.  

I then totally disabled the pinging heartbeat.  That kind of works... I can now reach the admin page via my router, but it is terribly slow and is getting other errors now.  

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1794
 

Hi @inq,

  I do have, and did a quick play with an ESP32-CAM quite some time ago ... I was only curious to get a rough idea of what a $5 processor completes with camera could do.

I didn't go much further than Bill does in video on the ESP32-CAM where it acts as a webserver, but I did get it working as both a client to my router, and as access point independent of the router, but only as one or the other at any one time. Admittedly, I haven't looked back at it since, but I thought it was a case of enabling and disabling a line or two of code, depending on which arrangement you wanted.

Overall, whilst the camera obviously has it limits, including sometimes showing a random line with all pixels set to the same colour, overall it did seem to work pretty much as claimed.

-----------------------------------------------------------------------------------------------

I doubt if it is of the slightest use, to you, but for the record, I have listed my recollections ... please feel free to ignore them!

For the client to my router, I think I used Bill's instructions, which are basically use Arduino webserver sketch, modify script to select camera, fill in router login name and password. Plus I changed the to set the webserver IP address to make use the same subnet as my router, probably based on Random Nerd instructions at:

https://randomnerdtutorials.com/esp32-cam-static-fixed-ip-address-arduino/

-----

Then later I changed to access point ...

I am pretty sure I used the Random Nerd instructions at

https://randomnerdtutorials.com/esp32-cam-access-point-ap-web-server/

to change it from the webserver sketch default of router client to access point mode

--------------------------------------------------------------------------------------------------

I don't recall seeing any evidence of being both modes at the same time, but of course that doesn't preclude the possibility of a slightly different software configuration which does have both enabled .. just that I never considered such an arrangement.

So apologies if I didn't follow what you were trying to do ... I realised you had infinitely more experience than I have in this field, and I had the horrible feeling I was wasting your time.

-------------------

As a random thought, I presume you have made sure all of the code files are updated ... quite some time ago, the library code underwent a fairly drastic rewrite, and it was quite easy to get a hybrid mix of of and new code that didn't compile.

--------

Good luck with your search .. sorry I haven't been much help.

Best wishes, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7399
 

@davee There are 3 Modes, Access Point, Station, and Both. Thanks to the Nerds

 

Screenshot 2023 05 12 at 20.36.48

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
DaveE reacted
ReplyQuote
(@jassim-talal)
Member
Joined: 5 years ago
Posts: 5
 

Hi friends;

When I've used esp32 cam with HC-RS501 to take a photo with any motion in the area, the camera continued to take photos continuously nevertheless there is no any motion ... any body has idea to solve such defect.

Thanking you,

Jassim


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7399
 

@jassim-talal Hi, first you need to start your own topic as opposed to jumping on someone else's. Second, look up Bill's video/blog re the  HC-RS501. You will find there is a setting or two that will affect how it operates. 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote