I've built a datalogger to monitor the connections on my local area network.
All details here if anyone is interested.
My problem is that I use FTP to download data from the Node to my PC; however after running for a while (maybe months) the FTP refuses to connect.
I've shown the relevant bits of FTP handling here, but I've also attached the full code for context. The program is a state machine driven by millis(), and the only code I can see that could block is the "PerformPing" routine - which is only active for 7 seconds in every 60.
#include <ESP8266FtpServer.h> //ftp server library
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
void setup()
{
//monitor Wifi connection and handle D0
gotIpEventHandler = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP & event)
{
//Serial.print("Station connected, IP: ");
//Serial.println(WiFi.localIP());
WiFiState = 1;
digitalWrite(dPin[0], 0); //blue LED is active LOW
});
disconnectedEventHandler = WiFi.onStationModeDisconnected([](const WiFiEventStationModeDisconnected & event)
{
Serial.println("Station disconnected");
WiFiState = 0;
digitalWrite(dPin[0], 1); //blue LED OFF
});
connectWiFi();
//FTP Setup, ensure SPIFFS is started before ftp;
if (SPIFFS.begin()) {
Serial.println("SPIFFS opened!");
ftpSrv.begin("esp8266", "esp8266"); //username, password for ftp. set ports in ESP8266FtpServer.h (default 21, 50009 for PASV)
}
void loop() {
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
PerformPing
/* code for pinging and led display */
bool PerformPing()
{
if (roundComplete) //ready for next set of pings
{
isFinished = false;
int url = target;
bool pingOK = pinger.Ping(IPAddress(host1[url].IP), pingNumber, pingTime);
roundComplete = false;
}
else if (isFinished) // one set of pings to a single target complete and results in
{
isFinished = false;
//correct data: average is only correct if no pings lost; otherwise its the sum of the valid ping times
if (pingsLost == 0) {
host1[target].tPing = pingAvg;
}
else {
host1[target].tPing = int((pingAvg + pingsLost * pingTime) / pingNumber);
}
host1[target].nLost = pingsLost;
checkFailedPings();
roundComplete = true;
}
return roundComplete;
}
netmonitor.ino (20.5 KB)