Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 7 1 2 3 ... LastLast
Results 1 to 25 of 172

Thread: Teensy 4.1 - Adafruit Airlift Featherwing Co-Processor FTP Server not opening Port 21

  1. #1
    Junior Member
    Join Date
    Mar 2021
    Location
    Easley, SC USA
    Posts
    17

    Teensy 4.1 - Adafruit Airlift Featherwing Co-Processor FTP Server not opening Port 21

    Please excuse newbie to Arduinos and programming. I have been working on this project for over a year and have been stuck on the FTP portion for over 6 months. The overall project is an audio recorder that stores audio files in raw format on the SD Card and then opens an FTP server allowing my computer to connect on a schedule and download the audio files. The audio recording is handled by the Audio Adapter board for Teensy 4.x and works flawlessly. WiFi is handled by the Adafruit Airlift Featherwing Co-Processor and the Adafruit Teensy adapter board. The WiFi works perfectly. I am using the SimpleFTPServer.h library for FTP and as far as the serial monitor shows, it is working and reports that it is listening on port 21 but not only am I unable to connect to it, a port scanner doesn't show any open ports at all. For example of my problem I have created a scaled down sketch that exhibits the issue I am dealing with (just WiFi, SD Card and FTP).

    I have tried numerous different FTP libraries, numerous WiFi libraries (WiFi.h, WiFiNINA.h, WiFiNINA_Generic.h) The current WiFiNINA.h library I am using in this example is the Adafruit WiFiNINA library.

    Any assistance that anyone can offer would be greatly appreciated.

    The code compiles clean and the Serial Output is below.

    ********* Serial Output ***********
    Firmware Version is 1.2.2
    Wifi Begin
    Attempting to connect to WPA SSID: MATRIX
    ...Connecting
    You're connected to the network.SSID: MATRIX
    BSSID: B0:A7:B9:13:A5:6B
    signal strength (RSSI):-60
    Encryption Type:4

    IP Address: 192.168.1.127
    192.168.1.127
    MAC address: C4D:57:B8:AFC
    Preparing to initialize SD Card
    SD Card Initialized

    Initializing FTP Server...
    NOT ANONYMOUS
    esp8266
    Ftp server waiting for connection on port 21

    ********** End Serial Output *************





    Code:
    #include <SimpleFTPServer.h>
    #include <SdFat.h>
    #include <SdFatConfig.h>
    #include <sdios.h>
    #include <WiFiNINA.h>
    #include <SPI.h>
    
        //Define WiFi Connections
        #define SPIWIFI       SPI
        #define SPIWIFI_SS    5
        #define ESP32_RESET   6
        #define SPIWIFI_ACK   9
        #define ESP32_GPIO0  -1
        
        
        //Define WiFi Credentials
        const char* ssid = "MATRIX";
        const char* pass = "rpentagon845psilly417";
        int status = WL_IDLE_STATUS;     // the Wifi radio's status
    
        //Define SD Card Object
        SdFat sd;
    
        //Define FTP Server Object
        FtpServer ftpSrv;
    
        // Use these with the Teensy 3.5 & 3.6 SD card
        #define SDCARD_CS_PIN    BUILTIN_SDCARD
        #define SDCARD_MOSI_PIN  11  // not actually used
        #define SDCARD_SCK_PIN   13  // not actually used
    
        // IP address of FTP server
        // if set to 0, use DHCP for the routeur to assign IP
        // IPAddress serverIp( 192, 168, 1, 40 );
        IPAddress serverIp( 192, 168, 1, 127 );  //This IP is the same IP given to Teensy by DHCP
    
        
    
    
    
    void setup() {
    
      
        //Initialize serial and wait for port to open:
        Serial.begin(115200);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }
    
        // Set up the pins!
        WiFi.setPins(SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESET, ESP32_GPIO0, &SPIWIFI);
        
        SPI.begin();
        
              
        String fv = WiFi.firmwareVersion();
     
        Serial.print("Firmware Version is ");
        Serial.println(fv);
        
      // attempt to connect to Wifi network:
        Serial.println("Wifi Begin");
      while (status != WL_CONNECTED) {
        Serial.print("Attempting to connect to WPA SSID: ");
        Serial.println(ssid);
        // Connect to WPA/WPA2 network:
        status = WiFi.begin(ssid, pass);
        Serial.println("...Connecting");
        
       
      }
    
        // you're connected now, so print out the data:
        Serial.print("You're connected to the network.");
        printCurrentNet();
        printWifiData();
    
      // Initialize the SD card
        SPI.setMOSI(SDCARD_MOSI_PIN);
        SPI.setSCK(SDCARD_SCK_PIN);
        Serial.println("Preparing to initialize SD Card");
      while (!(SD.begin(SDCARD_CS_PIN))) {
        // stop here if no SD card, but print a message
        Serial.println("SD Card Not Initialized");
        delay(500);
        }
        
        Serial.println("SD Card Initialized");
    
    
        //Initialize FTP Server
        Serial.println();
        Serial.println("Initializing FTP Server...");
        ftpSrv.begin("esp8266","esp8266");
        // ftpSrv.init( externalIp );
        //ftpSrv.init( IPAddress( 192, 168, 1, 195 ));
    }
    
    void loop() {
        ftpSrv.handleFTP();
    }
    
    
    
    void printMacAddress(byte mac[]) {
      for (int i = 5; i >= 0; i--) {
        if (mac[i] < 16) {
          Serial.print("0");
        }
        Serial.print(mac[i], HEX);
        if (i > 0) {
          Serial.print(":");
        }
      }
        Serial.println();
    }
    
    void printWifiData() {
        // print your board's IP address:
        IPAddress ip = WiFi.localIP();
        Serial.print("IP Address: ");
        Serial.println(ip);
        Serial.println(ip);
      
        // print your MAC address:
        byte mac[6];
        WiFi.macAddress(mac);
        Serial.print("MAC address: ");
        printMacAddress(mac);
    }
    
    void printCurrentNet() {
        // print the SSID of the network you're attached to:
        Serial.print("SSID: ");
        Serial.println(WiFi.SSID());
      
        // print the MAC address of the router you're attached to:
        byte bssid[6];
        WiFi.BSSID(bssid);
        Serial.print("BSSID: ");
        printMacAddress(bssid);
      
        // print the received signal strength:
        long rssi = WiFi.RSSI();
        Serial.print("signal strength (RSSI):");
        Serial.println(rssi);
      
        // print the encryption type:
        byte encryption = WiFi.encryptionType();
        Serial.print("Encryption Type:");
        Serial.println(encryption, HEX);
        Serial.println();
    }

  2. #2
    Junior Member
    Join Date
    Mar 2021
    Location
    Easley, SC USA
    Posts
    17
    51 views and no replies...guess I'm not one of the inner circle cool kids.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,401
    I'm not familiar with these particular Adafruit products.

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,025
    Quote Originally Posted by jhall0326 View Post
    51 views and no replies...guess I'm not one of the inner circle cool kids.
    Not personal - It isn't about being a cool kid - but having a topic or problem presented that is recognized as something where usable help can be offered.

    Only 11 unique folks (jhall0326+10) have viewed the thread - so some of them have popped in multiple times perhaps trying to find a way to get a grasp on the problem as presented.

    Also only Paul is paid to be here (among a few other hats he wears) - others come and go as time allows - and requires the thread to be seen and grab attention.

    This is a unique issue. Though there is this current thread AsyncWebServer_Teensy41-for-QNEthernet that maybe be similar where file transfer over network seems to be the showing up.

  5. #5
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    8,240
    This is a follow on to my response in your other post same subject basically.

    Reading the message a bit closer sounds like you are creating the server on the airlift. If thats the case then it would listening for the pc or something else to connect to it - that may be why you are gettting that error msg

  6. #6
    I've not personally done anything like your project, but this github repository has a project combining Teensy 3.1 with Airlift. Might be relevant?

    https://github.com/j3nsykes/OSC_propShield

  7. #7
    Junior Member
    Join Date
    Mar 2021
    Location
    Easley, SC USA
    Posts
    17
    Thanks for the replies. I actually removed FTP and added the WiFiNINA Webserver example and it opened port 80 with no problems. Then as a test, I changed the port that the webserver was using to port 21 to ensure that there wasn't something blocking that port number and the webserver had no problem opening port 21 as verified by my port scanner. It's really odd in that it seems that all the FTP libraries are unable to open port 21 even though I am connecting to my WiFi flawlessly as verified from my router. There just seems to be something about the FTP protocol that doesn't wish to operate in this environment. I didn't bother with Adafruit for help since the teensy is the device that is executing all the code but I will head down that path now.

    I haven't installed anything on the airlift featherwing. Straight out of the box and plug it in. The teensy runs all the code.

    Here is the exact hardware configuration I am using.
    https://forum.pjrc.com/threads/61297...1-WiFi-(Howto) . This project doesn't use FTP but the WiFi portion is straight forward.

    Thanks for your time.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,401
    As a really blind guess, maybe try setting Tools > CPU Speed to 150 MHz or even 24 MHz (and of course upload again for the change to take effect), just in case the problem is speed related.

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,401
    Is this the Adafruit product you're using?

    https://www.adafruit.com/product/4264

  10. #10
    Junior Member
    Join Date
    Mar 2021
    Location
    Easley, SC USA
    Posts
    17
    Paul, Yes! That is it. Along with the Feather - Teensy adapter https://www.adafruit.com/product/3200 and the Featherwing Doubler https://www.adafruit.com/product/2890. They connect to WiFi flawlessly but just no FTP port opened.

    Thanks for the reply. I know your time is valuable.

  11. #11
    Can you also please provide a link to the FTP library you are using? There are several libraries named SimpleFTPServer.

  12. #12
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,401
    Did you try reducing Tools > CPU Speed to the slowest speeds? (and upload again for code compiled with the slower speed setting to take effect)

    I know it's a long shot, but in at least 2 other cases we've seen Adafruit libraries which failed at the highest speed but worked fine when running slower. None of Adafruit's Arduino compatible products run anywhere near as fast as Teensy 4.1, so while their libraries in theory should work at any speed because they use libraries like SPI & Wire, they don't get tested on hardware as fast as Teensy 4.1. Checking whether Teensy's much higher speed matters is really easy, just click that menu and upload again. Let's check this before more guessing, before pouring a lot of engineering work into this, ok?

  13. #13
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,401
    FWIW, it's not only Adafruit. My own optimization work with the Wiznet chips needed a 10ns delay added when using the oldest W5100 chip....

    https://github.com/PaulStoffregen/Et...7bf2799642910d

  14. #14
    Junior Member
    Join Date
    Mar 2021
    Location
    Easley, SC USA
    Posts
    17
    The CPU speed change down to 24 MHz didn't have any effect.

    The simpleFTPServer library came by searching Library Manager for SimpleFTP. IT is the only result.

    My Ethernet kit is on order. I'm anxious to see if the port will open without using the Airlift featherwing. I guess if it works, I'm still left not knowing if the problem is with the WiFiNINA library or the Airlift but it will help to eliminate anything Teensy related. I'm certain you are tired of screwing around with my issue.

  15. #15
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,401
    I ordered this Adafruit product, plus the feather adapter for Teensy, and triple featherwing prototype board, and their SAMD51 board for the sake of comparison.

    Estimated delivery is Thursday, April 28.

    Sounds like all I have to do to replicate the problem is put a Teensy 4.1 onto that adaptor and plug it into the prototype board together with this shield, rigtht? Or is there anything else needed?

    Could I talk you into sharing a couple photos of exactly how you have the hardware set up, and a screenshot showing exactly which library you installed from the Arduino library manager? Let's not leave any detail to chance when it comes to how to reproduce this problem....

  16. #16
    Junior Member
    Join Date
    Mar 2021
    Location
    Easley, SC USA
    Posts
    17
    I certainly will! Give me a bit to put it all together. Thanks a ton for the extra effort. In an effort to not have to wait for the Ethernet kit, I even tried to connect CAT5 cable directly to the Ethernet pin locations and as you well know, the Ethernet library didn't like that at all.

  17. #17
    Junior Member
    Join Date
    Mar 2021
    Location
    Easley, SC USA
    Posts
    17
    Is there a more reliable way to implement WiFi on the teensy 4.1? I'm certainly not married to the Airlift Featherwing.

  18. #18
    Junior Member
    Join Date
    Mar 2021
    Location
    Easley, SC USA
    Posts
    17
    Paul,
    I was able to install the Ethernet Shield and the FTP library opened port 21 with no issue. When I reconnected the Airlift Featherwing and using the WiFiNINA library, no port opened. I'm not certain what that tells us. Here are pics of my hardware. Click image for larger version. 

Name:	IMG_2769.jpg 
Views:	8 
Size:	182.3 KB 
ID:	28186Click image for larger version. 

Name:	IMG_2771.jpg 
Views:	5 
Size:	200.3 KB 
ID:	28187Click image for larger version. 

Name:	IMG_2770.jpg 
Views:	7 
Size:	210.8 KB 
ID:	28188

  19. #19
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,401
    I'm still waiting for the hardware to arrive. Adafruit shipped it last week, but it takes 1 week to go from New York to Oregon.

    In the meantime, can you confirm if this is the FTP library you're using?

    Click image for larger version. 

Name:	screenshot.png 
Views:	11 
Size:	26.1 KB 
ID:	28189

    Could you also please turn on verbose output during compilation in File > Preferences. Then click Verify, and copy the info about exactly which libraries Arduino used.

  20. #20
    Junior Member
    Join Date
    Mar 2021
    Location
    Easley, SC USA
    Posts
    17
    That is the exact library I am attempting to use along with the WiFiNINA library from Adafruit and the SdFat library from Teensyduino. I was actually able to contact Renzo asking him for assistance as well but have not gotten a reply as of yet.

    Thanks again for your time helping me with this issue.

  21. #21
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    8,240
    I not much on using this stuff but figured maybe I would play along and maybe learn something. Ran your sketch (just change wifi credentials and IP address) and not even getting as far as you.:
    Code:
    Wifi Begin
    Attempting to connect to WPA SSID: CyberPalin
    ...Connecting
    You're connected to the network.SSID: CyberPalin
    BSSID: 48:5D:36:7D:5D:50
    signal strength (RSSI):-28
    Encryption Type:4
    
    IP Address: 192.168.1.28
    192.168.1.28
    MAC address: E8:9F:6D:D3:0B:E4
    Preparing to initialize SD Card
    SD Card Initialized
    
    Initializing FTP Server...
    seems to hang at this point.

  22. #22
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    8,240
    Now that I woke up I added an extra println after ftpserv.begin just to make sure and the server appeared to start up:
    Code:
    SD Card Initialized
    
    Initializing FTP Server...
    FtpServer Started
    but if I try to connect with filezilla client:
    Code:
    Status:	Connecting to 192.168.1.239:21...
    Status:	Connection attempt failed with "ECONNREFUSED - Connection refused by server".
    Error:	Could not connect to server
    going to investigate

  23. #23
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,556
    Sorry, I can not help on this one as I don't have the Airlift featherwing... I do have one of the
    Adafruit AirLift – ESP32 WiFi Co-Processor Breakout Board

    Which may work the same? Although I don't think I ever tried it out.

  24. #24
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    8,240
    Quote Originally Posted by KurtE View Post
    Sorry, I can not help on this one as I don't have the Airlift featherwing... I do have one of the
    Adafruit AirLift – ESP32 WiFi Co-Processor Breakout Board

    Which may work the same? Although I don't think I ever tried it out.
    Probably would work as well just have to hook it up. Looks like it uses the same library WifiNINA from adafruit

  25. #25
    Senior Member wwatson's Avatar
    Join Date
    Aug 2017
    Posts
    725
    Got my Airlift Featherwing last Thursday. After connecting it to a T4.1 I was able to successfully run all of the example sketches I tried. Downloaded SimpleFTPServer from here:
    https://github.com/xreef/SimpleFTPServer

    This library has an amazing amount of defines it FtpServerKey.h and FtpServer.h. One device I noticed was SAMD that was using WiFiNINA. I created defines for Teensy based on the defines for SAMD board.

    In FtpServerKey.h I added:
    Code:
    // Teensy T4.x with TEENSYDUINO
    #ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_TEENSY
    // Teensy T4.x
    	#define DEFAULT_FTP_SERVER_NETWORK_TYPE_TEENSY	NETWORK_WiFiNINA
    	#define DEFAULT_STORAGE_TYPE_TEENSY				STORAGE_SD
    #endif
    And in FTPServer.h I added:
    Code:
    	#elif defined(TEENSYDUINO)
    		#define FTP_SERVER_NETWORK_TYPE DEFAULT_FTP_SERVER_NETWORK_TYPE_TEENSY
    		#define STORAGE_TYPE DEFAULT_STORAGE_TYPE_TEENSY
    This is the sketch I am using for testing:
    Code:
    /*
     * FtpServer Adafruit Airlift Featherwing with SD
     *
     * AUTHOR:  Renzo Mischianti
     *
     * https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
     *
     * Modified for use with Adafruit Airlift Featherwing and Teensy 4.x
     * 04-30-2022
     * By: Warren Watson.
     */
    
    #include "SD.h"
    #include <SimpleFTPServer.h>
    
    #define SPIWIFI       SPI  // The SPI port
    #define SPIWIFI_SS     5   // Chip select pin
    #define ESP32_RESETN   6   // Reset pin
    #define SPIWIFI_ACK    9   // a.k.a BUSY or READY pin
    #define ESP32_GPIO0   -1
    
    #include "arduino_secrets.h" 
    ///////please enter your sensitive data in the Secret tab/arduino_secrets.h
    char ssid[] = SECRET_SSID;        // your network SSID (name)
    char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
    
    FtpServer ftpSrv;   //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
    
    void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
    	Serial.print(">>>>>>>>>>>>>>> _callback " );
    	Serial.print(ftpOperation);
    	/* FTP_CONNECT,
    	 * FTP_DISCONNECT,
    	 * FTP_FREE_SPACE_CHANGE
    	 */
    	Serial.print(" ");
    	Serial.print(freeSpace);
    	Serial.print(" ");
    	Serial.println(totalSpace);
    
    	// freeSpace : totalSpace = x : 360
    
    	if (ftpOperation == FTP_CONNECT) Serial.println(F("CONNECTED"));
    	if (ftpOperation == FTP_DISCONNECT) Serial.println(F("DISCONNECTED"));
    };
    
    void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
    	Serial.print(">>>>>>>>>>>>>>> _transferCallback " );
    	Serial.print(ftpOperation);
    	/* FTP_UPLOAD_START = 0,
    	 * FTP_UPLOAD = 1,
    	 *
    	 * FTP_DOWNLOAD_START = 2,
    	 * FTP_DOWNLOAD = 3,
    	 *
    	 * FTP_TRANSFER_STOP = 4,
    	 * FTP_DOWNLOAD_STOP = 4,
    	 * FTP_UPLOAD_STOP = 4,
    	 *
    	 * FTP_TRANSFER_ERROR = 5,
    	 * FTP_DOWNLOAD_ERROR = 5,
    	 * FTP_UPLOAD_ERROR = 5
    	 */
    	Serial.print(" ");
    	Serial.print(name);
    	Serial.print(" ");
    	Serial.println(transferredSize);
    };
    
    void setup(void){
      Serial.begin(115200);
    
      // check for the WiFi module:
      WiFi.setPins(SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
      if (WiFi.status() == WL_NO_MODULE) {
        Serial.println("Communication with WiFi module failed!");
        // don't continue
        while (true);
      }
    
      WiFi.begin(ssid, pass);
      Serial.println("");
    
      // Wait for connection
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("");
      Serial.print("Connected to ");
      Serial.println(ssid);
      Serial.print("IP address: ");
      Serial.println(WiFi.localIP());
    
      if (SD.begin(BUILTIN_SDCARD)) {
          Serial.println("SD opened!");
    
          ftpSrv.setCallback(_callback);
          ftpSrv.setTransferCallback(_transferCallback);
    
          ftpSrv.begin("esp8266","esp8266");    //username, password for ftp.   (default 21, 50009 for PASV)
      }
    }
    void loop(void){
      ftpSrv.handleFTP();        //make sure in loop you call handleFTP()!!
     // server.handleClient();   //example if running a webserver you still need to call .handleClient();
    
    }
    Note: I added arduino_secrets.h file to the sketch folder which looks like this:
    Code:
    #define SECRET_SSID "your SSID"
    #define SECRET_PASS "your password"
    At this point Filezilla will connect with this message:
    Code:
    Status:	Connecting to 192.168.0.113:21...
    Status:	Connection established, waiting for welcome message...
    Error:	Connection timed out after 20 seconds of inactivity
    Error:	Could not connect to server
    The connection is made but there does not seem to be communication between the server and client. It goes into an endless loop in ftpSrv.handleFTP();.

    This section shows status always returning 0:
    Code:
    #if (FTP_SERVER_NETWORK_TYPE == NETWORK_WiFiNINA)
    //			if (client && !client.connected()) {
    //				client.stop();
    //				DEBUG_PRINTLN(F("CLIENT STOP!!"));
    //			}
    			byte status;
    			client = ftpServer.available(&status);
    			/*
    			 *   CLOSED      = 0,
      LISTEN      = 1,
      SYN_SENT    = 2,
      SYN_RCVD    = 3,
      ESTABLISHED = 4,
      FIN_WAIT_1  = 5,
      FIN_WAIT_2  = 6,
      CLOSE_WAIT  = 7,
      CLOSING     = 8,
      LAST_ACK    = 9,
      TIME_WAIT   = 10
    			 *
    			 */
    //			DEBUG_PRINTLN(status);
    More debugging needed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •