Using an example for the esp32-cam, on restarts via power cycle, I alternately get brownout detected, almost immediate connect or never connect stuck in the while (WiFi.status() check.
I have put in a counter to see how long it goes and currently am at 1,500 seconds or checks on that loop.
What should I do? Can I close WiFi.begin and try again? Should I reset via code? (how?)
Help is appreciated.
Below is the adjusted code.
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
delay(100);
WiFi.begin(ssid, password);
delay(100);
int I=0;
int N;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
I++;
Serial.print(I); //Serial.print(" \r"); This did not work to overprint value in place
N=I/10; //eg 11/10=1
N=N10; // 110=10
if(I==N){// and 10 is not 11
Serial.print("\n");
}
delay(500);
}
To my understanding a brownout does mean that the power supply did not supply enough power BUT it is when the wifi circuit is first turned on. Startup has a big draw. It likely will run fine once the startup drain is over.
As I said as well, the brownout is intermittent on startup - again implying that the condition is borderline.
The code strangely only checks the condition repeatedly without doing anything to correct it.
To me that is bad code.
Currently the loop has tested an unchanging condition 13,000 times. Again to me that is bad code.
I would like to fix the code before I fix the power issue as I won't be able to duplicate this situation.
If you don't want an adjusted answer, then you need to post your code. Please read "Read this before posting a programming question" at the top of the forum and post your sketch- all of it- using code tags.
To my understanding a brownout does mean that the power supply did not supply enough power BUT it is when the wifi circuit is first turned on. Startup has a big draw. It likely will run fine once the startup drain is over.
In fact it gets it's name for the effect it can have on electro-motors, causing them to overheat, and turn visibly brown thereafter.
Anyway the peak when the wifi is connecting (up to 280mA) You could add a fairly big capacitor (1000uF) and see if that helps.
I would like to fix the code before I fix the power issue as I won't be able to duplicate this situation.
Well yeah, but really the code may not be broken, it is just the wifi not connecting or even the unit losing sync with the CPU due to lack of power.
really the code may not be broken, it is just the wifi not connecting or even the unit losing sync with the CPU due to lack of power.
In truth it is great code for its purpose which is an example. Keep it simple. Very useful that way. Helps you get started. Didn't mean to offend.
By bad, I was meaning that it would be bad for release code not to handle this situation.
I note that the esp32 docs show the possibility of powering off the wifi and repowering it back on.
Other options are blink a warning light, Reset the device, Send an warning email, shut down and try again later.
Given that thousands of retries seem to make no difference and the problem is intermittent on power cycling, this is the time to get attention.
Thanks, I keep trying and delve deeper into the library.
Deva_Rishi:
In fact it gets it's name for the effect it can have on electro-motors, causing them to overheat, and turn visibly brown thereafter.
Ummm, citation needed for that I'm afraid.
Wikipedia says it's from the lights dimming. Google dictionary says it is derived form blackout implying the same derivation. Plus that was what I had assumed before even looking it up.
They don't give sources either, but both sound far more plausible.
They don't give sources either, but both sound far more plausible.
My father was working as an electrician, and explained the phenomena to me (he was a physics teacher before he was an electrician.) If you want to argue with my father... go ahead !
I inserted a network scan before trying to connect to verify the wifi module was working.
It scans and only finds one network when there are two but the module does seen to work.
Then it tries to connect but after 90 seconds it still has not connected.
#include <WiFi.h>
const char* ssid = "EVANOFFNET24G";
const char* password = "xxxxxx";
WiFiServer server(80) ;
#define CAMERA_MODEL_AI_THINKER
#include "camera_pins.h"
//CJP
// camera_pins.h contains the following defines
//#define BUILTIN_FLASH 04 //builtin flash led - too bright
//#define BUILTIN_LED 33 //builtin red led on bottom of board
//camera_pins was modified to include the above defines and copied into the
//same folder as the .ino file = Arduino/SimpleWiFiServer
//If necessary just uncomment the defines used
//Be warned that BUILTIN_LED is used for the SD card - you can't use both the LED and the SD
#define BUILTIN_LED_ON LOW //usual gpi pins come up low - the built in is wired to be on
#define BUILTIN_LED_OFF HIGH
void setup()
{
Serial.begin(115200);
pinMode(BUILTIN_LED, OUTPUT); // set the LED pin mode
delay(10); // not sure what the delay is for - either the serial setup or the pin setup?
digitalWrite(BUILTIN_LED, BUILTIN_LED_OFF); //on power outage come up off
//testing scan first instead of connect right at start up
Serial.println();
Serial.print("Starting wifi station ");
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(1000);
Serial.println();
Serial.print("Scanning networks ");
int n = WiFi.scanNetworks();
Serial.println();
Serial.print("Done. Printing network list ");
for (int i = 0; i < n; i++)
{
Serial.println(WiFi.SSID(i));
}
// original code starts here
// We start by connecting to a WiFi networkSerial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
delay(1000);
WiFi.begin(ssid, password);
delay(1000);
int I=0;
int N;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
I++;
Serial.print(I);
Serial.print(" ");
//Serial.print(" \r"); This did not work to overprint value in place
N=I/10; //eg 11/10=1
N=N*10; // 1*10=10
if(I==N){// and 10 is not 11
Serial.print("\n");
}
delay(500);
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}
I also removed the sunfounder breadboard power module and 9V 2.2A power wart. Then used just the USB over FTDI and the brownouts went away so far.
The device will connect within 4 seconds or not at all.
Unplugging USB and plugging back in is being used to toggle power now.
Only every 4th or 5th reset works.
Will redo hardware with new module and power setup.
Ping results aren't good. 59 packets and 3 replies
The server worked and I could toggle the onboard led but it is very unresponsive. It took many many transmits for each toggle.
--- 192.168.1.10 ping statistics ---
59 packets transmitted, 3 received, 94% packet loss, time 59294ms
rtt min/avg/max/mdev = 32.877/160.675/236.072/90.853 ms
The module reports that the router is -90db.
Using wifi analyzer on my phone shows -40db.
-100 is no signal. Works above -75 but above -50 is reliable.
Explains a lot... Thought the RSSI example might be useful to others.