To delay or not to delay....
Posted: Sat Nov 19, 2016 6:11 am
First look att this code:
This produces this output: (Notice the gibberish output from the first Serial.printf lines)
So I added a delay after Serial.begin, Everything else the same.
AndI get this output.
Only problem, the wifi never connects. And yes, this is repeatable over and over again with just adding or deleting that 1 second delay.
What is really happening here?
Why do I get gibberish output in the first case?
And why won't the wifi connect if I add a delay?
Code: Select all
void setup() {
Serial.begin(74880);
Serial.println("Booting\n");
Serial.printf("Reset reason: %s\n",ESP.getResetReason().c_str());
Serial.printf("Vcc: %d\n", ESP.getVcc());
Serial.printf("ESP8266 ID: %08X\n", ESP.getChipId());
Serial.printf("Flash ID: %08X\n", ESP.getFlashChipId());
Serial.printf("Flash size: %u\n\n", ESP.getFlashChipRealSize());
Serial.printf("\nConnecting");
WiFi.mode(WIFI_STA);
WiFi.config(wifi_ip, wifi_gateway, wifi_subnet);
WiFi.begin(wifi_ssid, wifi_password, wifi_channel, wifi_bssid);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.printf(".");
}
Serial.printf("\n");
Serial.printf("\nSSID: %s\n", WiFi.SSID().c_str());
Serial.printf("IP: %s\n",WiFi.localIP().toString().c_str());
Serial.printf("Mac-addr: %s\n", WiFi.BSSIDstr().c_str());
Serial.printf("RSSI: %d dBm\n", WiFi.RSSI());
}
This produces this output: (Notice the gibberish output from the first Serial.printf lines)
Code: Select all
ets Jan 8 2013,rst cause:2, boot mode:(3,0)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld
½½Ñ¥¹�)jR$Uk•Ñ�’•…ͽ¹é*…ѕɹ…±�šåÍÑ•µ)²��éšÂ‚ªRT5…’²²JE¥‚‚‚*Â2•RdÅ+kRŠ”‚‚Š¢¢‚*RdÅ+kÒW-¯Y'HHL˜š8576
Connecting....
SSID: heeke
IP: 192.168.0.51
Mac-addr: 10:C3:7B:44:5C:BA
RSSI: -60 dBm
So I added a delay after Serial.begin, Everything else the same.
Code: Select all
void setup() {
Serial.begin(74880);
delay(1000);
Serial.println("Booting\n");
...
AndI get this output.
Code: Select all
ets Jan 8 2013,rst cause:2, boot mode:(3,0)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld
ÿBooting
Reset reason: External System
Vcc: 3797
ESP8266 ID: 000E08F9
Flash ID: 001440E0
Flash size: 1048576
Connecting....................................................................................
Only problem, the wifi never connects. And yes, this is repeatable over and over again with just adding or deleting that 1 second delay.
What is really happening here?
Why do I get gibberish output in the first case?
And why won't the wifi connect if I add a delay?