Skip to content

Commit

Permalink
recover from online and goes to error when offline
Browse files Browse the repository at this point in the history
  • Loading branch information
ldab committed Aug 11, 2019
1 parent bd6cf40 commit 0ddad8a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion examples/upload_image/upload_image.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ char ftp_server[] = "";
char ftp_user[] = "";
char ftp_pass[] = "";

ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass);
// you can pass a FTP timeout and debbug mode on the last 2 arguments
ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass, 5000, 2);

void setup()
{
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esp32_ftpclient",
"version": "0.0.4",
"version": "0.1.0",
"description": "A FTP-Client for the ESP32",
"keywords": "sensors, low power, mobile, ftp, web, cloud, iot, esp32, espressif",
"authors":
Expand Down
18 changes: 14 additions & 4 deletions src/ESP32_FTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bool ESP32_FTPClient::isConnected(){
{
FTPerr("FTP error: ");
FTPerr(outBuf);
FTPerr("\n");
}

return _isConnected;
Expand Down Expand Up @@ -56,6 +57,15 @@ void ESP32_FTPClient::GetFTPAnswer (char* result, int offsetStart) {
unsigned long _m = millis();
while (!client.available() && millis() < _m + timeout) delay(1);

if( !client.available()){
memset( outBuf, 0, sizeof(outBuf) );
strcpy( outBuf, "Offline");

_isConnected = false;
isConnected();
return;
}

while (client.available()) {
thisByte = client.read();
if (outCount < sizeof(outBuf)) {
Expand All @@ -64,8 +74,8 @@ void ESP32_FTPClient::GetFTPAnswer (char* result, int offsetStart) {
outBuf[outCount] = 0;
}
}
if(outBuf[0] == '4' || outBuf[0] == '5'){

if(outBuf[0] == '4' || outBuf[0] == '5' ){
_isConnected = false;
isConnected();
return;
Expand All @@ -74,9 +84,10 @@ void ESP32_FTPClient::GetFTPAnswer (char* result, int offsetStart) {
{
_isConnected = true;
}

if(result != NULL){
FTPdbgn("Result start");
// Deprecated
for(int i = offsetStart; i<sizeof(outBuf); i++){
result[i] = outBuf[i - offsetStart];
}
Expand Down Expand Up @@ -160,7 +171,6 @@ void ESP32_FTPClient::NewFile (const char* fileName) {
}

void ESP32_FTPClient::InitFile(const char* type){
FTPdbg("Send ");
if(!isConnected()) return;
FTPdbgn(type);
client.println(F(type));
Expand Down
2 changes: 1 addition & 1 deletion src/ESP32_FTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ESP32_FTPClient

template<typename T>
void FTPerr(T msg) {
if(verbose == 1 || verbose == 2) Serial.println(msg);
if(verbose == 1 || verbose == 2) Serial.print(msg);
}

char* userName;
Expand Down

0 comments on commit 0ddad8a

Please sign in to comment.