I have a Lolin NodeMCU monitoring my network via pings and using 8 digital outputs to drive LEDs (active LOW).
A second identical NODE is configured the same with all LEDs connected. (test system)
I developed a program on the test system to log the averaged responses to SPIFFS and access the file via FTP. It all works fine, except that sometimes the ftp server closes for a short time when I try to download the file.
I load the SAME program to an identical board
FTP does not work (connection timed out) and the LED on D0 - which should be continuous on, showing an active wifi connection gets turned off.
I cant see why two identical circuits programmed the same should behave so differently - I'll need to strip down the program to bare essentials. Does anyone know of any hardware issues that might cause the issue?
On the NodeMCU I found that after uploading my program this line
if (WiFi.status() == WL_CONNECTED)
reported the wifi was down , and turned off the LED indicating wifi status.
I pressed the reset button - and it worked fine.
I wrote a short program (MRE ) to test it; same issue. Upload the program and the wifi test fails; press reset and it works as it should.
Yet the IDE tells me its hard reset via the rts pin - so why should it behave differently?
Press reset button again - and it fails!
/*****************************************************************************
sketch to test wifi reporting issue on NodeMCU
D0-D7 all configured as outputs and each connected via an LED & resistor to V+
Dpin0 = GPIO16 used to indicate wifi status Dpin0 LOW LED on showing Wifi on.
****************************************************************************
*/
#include <ESP8266WiFi.h>
// to do the pin mapping for the Lolin NodeMCU pins D0 - D8
const int dPin[] = {16, 5, 4, 0, 2, 14, 12, 13, 15};
const char* ssid = "my ssid";
const char* password = "my password";
void flashLeds() { //short flash to test leds all working
for (int i = 0; i <= 8; i++) {digitalWrite(dPin[i], 0); }
delay(200);
for (int i = 0; i <= 8; i++) {digitalWrite(dPin[i], 1); }
delay(200);
}
void setup()
{
// Begin serial connection at 74880 baud
Serial.begin(74880);
delay(1000); // serial comms is disturbed during a restart
//set up LED pins as outputs & test them
for (int i = 0; i <= 8; i++) { pinMode(dPin[i], OUTPUT); }
flashLeds();
flashLeds();
// Connect to WiFi access point
bool stationConnected = WiFi.begin(ssid, password);
delay(200); //allow time to connect
// Check if connection errors
if (!stationConnected)
{
Serial.println("Error, unable to connect specified WiFi network.");
digitalWrite(dPin[0], 1); //indicate wifi not connected
}
Serial.print("Connecting to AP...");
while (WiFi.status() != WL_CONNECTED) // Wait until connection completed
{
delay(200);
Serial.print(".");
}
Serial.print("Ok\n");
digitalWrite(dPin[0], 0); //indicate wifi connected
}
void loop()
{
if (WiFi.status() == WL_CONNECTED) digitalWrite(dPin[0], 0); else {
digitalWrite(dPin[0], 1);
Serial.print("WiFI down!!!");
Serial.println(WiFi.status());
}
Serial.println("*****once more around the loop*****");
}//loop
Your code runs flawlessly on my NodeMCU with my wifi. I can hit the reset button as often as I like and it always reconnects at startup. It could be an issue with your wifi router?