Home>

An FTP server using raspberrypi was constructed with reference to the following site, and it was set as an environment to transmit temperature and humidity data from multiple ESP-WROOM-02.
Create an ftp server in just one minute

Previously, it was possible to connect without any problems and get data
Currently, it is impossible to connect to the FTP server.
ESP-WROOM-02 Arduino program is

# include<SoftwareSerial.h>
#include<FS.h>
#include<ESP8266WiFi.h>// Library for ESP8266
#include<WiFiUdp.h>// Library for UDP communication
#define PIN_CAM 13 // Connect Pch-FET to IO 13 (Pin 5)
#define TIMEOUT 2000 // timeout 2 seconds
#include 
#include<Wire.h>
#include<time.h>
#include "Adafruit_SHT31.h"
Adafruit_SHT31 sht31 = Adafruit_SHT31 ();
#define JST 3600 * 9 // Date
#define SSID "*******" // Wireless LAN access point SSID
#define PASS "*******" // Wireless LAN access point password
#define SENDTO "192.168.0.255" // UDP destination IP address (no need to change)
#define PORT 1024 // UDP transmission port number (no need to change)
// Settings for connecting to an FTP server
#define FTP_TO "192.168. ******" // FTP destination IP address (This is an example, please change to your own IP)
#define FTP_USER "uploader" // FTP username
#define FTP_PASS "raspberrypi" // FTP password
#define FTP_DIR "" // FTP directory

#define FILENAME "/SHT31-1.txt" // File name to send to FTP server (file name to save)
File file;
WiFiUDP udpFtp;// define instance for UDP communication
WiFiServer server (80);// Wi-Fi server (port 80 = HTTP) definition
void setup () {
  SPIFFS.begin ();
  Serial.begin (115200);// Start serial output for operation check
  WiFi.mode (WIFI_STA);// Set wireless LAN to STA mode
  WiFi.begin (SSID, PASS);// Connect to a wireless LAN access point
  while (WiFi.status ()! = WL_CONNECTED) {// Wait until the connection is successful
    Serial.print (".");
    delay (500);// wait time processing
  }
  if (! sht31.begin (0x45))
  {
    Serial.println ("Couldn't find SHT31");
    while (1) delay (1);
   configTime (JST, 0, "ntp.nict.jp", "ntp.jst.mfeed.ad.jp");
  }

  server.begin ();// start the server
  File file = SPIFFS.open (FILENAME, "r");// open the file for saving
  if (file == 0) sleep ();// return if file cannot be opened
  file.seek (1, SeekSet);
  char c = file.read ();
  Serial.println ("");
  Serial.print ("spiffs:");
  Serial.println (c);
  file.close ();
}
void loop () {
  configTime (JST, 0, "ntp.nict.jp", "ntp.jst.mfeed.ad.jp");
  float tem = sht31.readTemperature ();
  float hum = sht31.readHumidity ();
  Serial.println (tem);
  Serial.println (hum);
  time_t t;
  struct tm * tm;
  t = time (NULL);
  tm = localtime (&t);
  server.begin ();// start the server
  File file = SPIFFS.open (FILENAME, "r");// open the file for saving
  if (file == 0) sleep ();// return if file cannot be openedfile.seek (1, SeekSet);
  char c = file.read ();
  Serial.println ("");
  Serial.print ("spiffs:");
  Serial.println (c);
  file.close ();
  File f = SPIFFS.open (FILENAME, "a");// open the file for saving (open in append mode)
  f.print (tm->tm_hour);
  f.print (":");
  f.print (tm->tm_min);
  f.print (":");
  f.print (tm->tm_sec);
  f.print (",");
  f.print (tem);
  f.print (",");// Write a string (make the character I want to write)
  f.println (hum);
  f.close ();// Close the file
  byte ret = doFTP (FILENAME);// send by FTP
  if (ret) {
    Serial.print ("FTP Err:");
    Serial.println (ret);
    delay (3000);
  }
  Serial.print ("http: //");// Display device name serially
  Serial.print (WiFi.localIP ());// Display the IP address of this machine serially
  Serial.println (FILENAME);// display file name serially
  udpFtp.beginPacket (SENDTO, PORT);// Set UDP destination
  udpFtp.print (", http: //");// send device name
  udpFtp.print (WiFi.localIP ());// Send the IP address of this machine
  udpFtp.println (FILENAME);// send file name
  udpFtp.endPacket ();// End UDP transmission (actual transmission)
  delay (3 * 60 * 1000);
}
void sleep () {
  Serial.println ("F Err");// Error display when the file could not be called
}

What has been confirmed so far
・ On Arduino serial monitor

spiffs: ⸮
SPIFFS open fail
FTP Err: 11
http: //192.168******/1-today.csv
24.26
64.93


-You can connect with the same address, host name, and password with FFFTP of Win
・ You can also connect on Ubuntu File Zilla

Thank you.

Additional
The following code corresponds to the error

#define FTP_WAIT 1
#define BUFFER_SIZE 128
byte doFTP (char * filename) {
    char ftpBuf [BUFFER_SIZE];
    WiFiClient client;
    WiFiClient dclient;
    int i;
    File file = SPIFFS.open (filename, "r");
    if (! file) {
        Serial.println ("SPIFFS open fail");
        return 11;
    }
    Serial.println ("SPIFFS opened");
    if (client.connect (FTP_TO, 21)) {
        Serial.println ("Command connected");
    }
    if (eRcv (client, ftpBuf)) return 21;
    sprintf (ftpBuf, "USER% s \ r \ n", FTP_USER);
    client.print (ftpBuf);
    delay (FTP_WAIT);Serial.print (ftpBuf);
    if (eRcv (client, ftpBuf)) return 22;
    sprintf (ftpBuf, "PASS% s \ r \ n", FTP_PASS);
    client.print (ftpBuf);
    delay (FTP_WAIT);
    Serial.println ("PASS");
    if (eRcv (client, ftpBuf)) return 23;
    client.print ("Type I \ r \ n");
    delay (FTP_WAIT);
    Serial.println ("Type i");
    if (eRcv (client, ftpBuf)) return 25;
    client.print ("PASV \ r \ n");
    delay (FTP_WAIT);
    Serial.println ("PASV");
    delay (100);
    if (eRcv (client, ftpBuf)) return 26;
    char * tStr = strtok (ftpBuf, "(,");
    if (tStr == NULL) return 27;
    int array_pasv [6];
    for (i = 0;i<6;i ++) {
        tStr = strtok (NULL, "(,");
        array_pasv [i] = atoi (tStr);
        if (tStr == NULL) {
            Serial.println ("Bad PASV Answer");
            return 28;
        }
    }
    unsigned int hiPort, loPort;
    hiPort = array_pasv [4]<<8;
    loPort = array_pasv [5]&255;
    Serial.print ("Data port:");
    hiPort = hiPort | loPort;
    Serial.println (hiPort);
    if (dclient.connect (FTP_TO, hiPort)) {
        Serial.println ("Data connected");
    } else {
        Serial.println ("Data connection failed");
        client.stop ();
        file.close ();
        return 31;
    }
    sprintf (ftpBuf, "STOR% s% s \ r \ n", FTP_DIR, filename);
    client.print (ftpBuf);
    delay (FTP_WAIT);
    Serial.print (ftpBuf);
    if (eRcv (client, ftpBuf)) {
        dclient.stop ();
        file.close ();
        return 32;
    }
    Serial.println ("Writing");
    i = 0;
    while (file.available ()) {
        ftpBuf [i] = file.read ();
        i ++;
        if (i>= BUFFER_SIZE) {
            if (! dclient.connected ()) break;
            dclient.write ((byte *) ftpBuf, BUFFER_SIZE);
            i = 0;
            Serial.print (".");
            delay (1);
        }
    }
    if (i>0) {
        if (dclient.connected ()) {
            dclient.write ((byte *) ftpBuf, i);
        }
    }
    dclient.stop ();
    Serial.println ("Data disconnected");if (eRcv (client, ftpBuf)) return 33;
    client.print ("QUIT \ r \ n");
    delay (FTP_WAIT);
    Serial.println ("QUIT");
    if (eRcv (client, ftpBuf)) return 91;
    client.stop ();
    Serial.println ("Command disconnected");
    file.close ();
    Serial.println ("SPIFFS closed");
    return 0;
}
byte eRcv (WiFiClient&client, char * ftpBuf) {
    byte thisByte, i = 0, len = 0;
    while (! client.available ()) {
        delay (FTP_WAIT);
        if (! client.connected ()) {
            Serial.println ("FTP: eRcv: disC");
            return 11;
        }
        i ++;
        if (i>1000) {// 200ms or more is required
            Serial.println ("FTP: eRcv: noRes");
            return 12;
        }
    }
    while (client.connected ()) {
        if (! client.available ()) {
            delay (FTP_WAIT);
            if (! client.available ()) break;
        }
        thisByte = client.read ();
        if (thisByte == (byte) '\ r');
        else if (thisByte == (byte) '\ n') {
            Serial.write ('>');
            Serial.println (ftpBuf);
            if (ftpBuf [0]>= '4') {
                client.print ("QUIT \ r \ n");
                delay (FTP_WAIT);
                Serial.println ("QUIT");
                return 1;
            }
            if (len>3&&ftpBuf [3] == '') {
                return 0;
            }
            len = 0;
        } else if (len<BUFFER_SIZE-1) {
            ftpBuf [len] = thisByte;
            len ++;
            ftpBuf [len] = 0;
        }
    }
    return 0;
}
void efail (WiFiClient&client) {
    byte thisByte = 0;
    client.print ("QUIT \ r \ n");
    delay (FTP_WAIT);
    while (! client.available ()) {
        if (! client.connected ()) return;
        delay (1);
    }
    while (client.available ()) {
        thisByte = client.read ();
        Serial.write (thisByte);
    }
    client.stop ();
    Serial.println ("Command disconnected");
}
  • Answer # 1

      

    SPIFFS open fail

    Are you moss when opening files?

  • Answer # 2

    It was an elementary mistake
    Is build option reset when Arduino UNO is connected separately from ESP-WROOM-02? Has been
    The part which should be set originally was skipped. . .

    The option change may be because the file size is too small