Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

WiFly FTP

wifly wifi ftp. netduino plus 2 rn-xv

  • Please log in to reply
20 replies to this topic

#1 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 16 January 2013 - 03:00 PM

Hi there,

 

I have managed to modify Jair's (Thanks Jair :D ) FTP socket code (from here: http://forums.netdui...-client-socket/) so that I am now able to use it with a wifi connection (Netduino Plus 2 and RN-XV module).

 

The question I have is how to upload a file from the SD card? At the moment the code simply creates a blank .txt file on the FTP server, how do upload a whole file?

 

Code below:

 

using System;using System.IO;using System.Net;using System.Net.Sockets;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.IO;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using SecretLabs.NETMF.Hardware.NetduinoPlus;using SecretLabs.NETMF.IO;using Toolbox.NETMF.Hardware;using Toolbox.NETMF.NET;using System.Text;namespace ftpTest{    public class Program    {        static WiFlyGSX WifiModule;        static string strSSID = "mySSID";        static string strPassword = "myPassword";        static string remoteHost = "FTP Server IP address";        static string remoteUser = "userName";        static string remotePass = "password";        private static SimpleSocket clientSocket;                public static void Main()        {            // write your code here                        connectToWifi();            Thread.Sleep(10000);            clientSocket = new WiFlySocket(remoteHost, 21, WifiModule);                        try            {                SimpleSocket.SocketProtocol Protocol = SimpleSocket.SocketProtocol.TcpStream;                clientSocket.Connect(Protocol);            }            catch (Exception e)            {                throw new IOException("Couldn't connect to remote server" + e);            }            sendCommand("USER " + remoteUser);            sendCommand("PASS " + remotePass);                        sendCommand("TYPE I");            sendCommand("PASV");            sendCommand("CWD www");            sendCommand("CWD other");            sendCommand("STOR testFile.txt");                        close();            clientSocket.Close();        }        private static void sendCommand(String command)        {            Byte[] cmdBytes = Encoding.UTF8.GetBytes((command + "rn"));            clientSocket.SendBinary(cmdBytes);        }        private static void close()        {            if (clientSocket != null)            {                sendCommand("QUIT");            }        }        public static void connectToWifi()        {            WifiModule = new WiFlyGSX();            WifiModule.EnableDHCP();            WifiModule.JoinNetwork(strSSID, 0, WiFlyGSX.AuthMode.MixedWPA1_WPA2, strPassword);            Thread.Sleep(3500);            // Showing some interesting output            Debug.Print("Local IP: " + WifiModule.LocalIP);            Debug.Print("MAC address: " + WifiModule.MacAddress);        }    }}

 

 

Thanks,

Donovan



#2 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 17 January 2013 - 02:57 AM

Have you tried to reference a file already on your SD card? with something like

 string file = @"/SD/myfile.txt";            if(File.Exists(file)            {                 sendCommand("STOR " + file);            }


#3 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 17 January 2013 - 06:15 AM

Hi skobyjay,

 

Thanks for the suggestion... I didn't think it would be that simple so I'll give it a try and let you know if it works.

 

Cheers,

Donovan



#4 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 17 January 2013 - 06:38 AM

nope... that didn't work  -_-

 

I guess the file is going to have to be broken up into binary and sent as bytes or something?



#5 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 17 January 2013 - 10:07 AM

I think FTP would be a problem with the wifly solution; FTP requires a command and data connection; the wifly module can only support 1 connection at the time


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#6 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 17 January 2013 - 12:00 PM

Stefan is right on the mark.  You'll need both a client and upload socket for FTP to work so WiFly will be hard to do.  I've just started looking into FTP for Pandora's Box as a means for getting the files of the SD card without removing the card but I haven't started programming yet as the Prototype is out for field tests this week.  If I make any progress on it over the weekend I'll post up.



#7 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 17 January 2013 - 12:34 PM

I suppose the reason I was able to see an empty test text file on my FTP server was a result of the CMD connection working fine but obviously without the second connection there's no way to move the SD card's file to the server.

 

This was one of my last hopes to get this project off the ground as using an HTTP request for my live data logger isn't ideal either (As detailed here: http://forums.netdui...75-memory-leak/).

 

I've been working on this project for months now and am out of ideas about how to make it work  :(

 

Thanks for taking a look guys!



#8 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 17 January 2013 - 01:54 PM

Since I'm not sure what exactly you are doing with your project and how you are triggering the FTP transaction, this suggestion may be worthless, but how about using the single connection as the upload only and have the ND FTP the files to a file server with another type of trigger (ie: Menu system on the ND, or Timer, or Schedule, etc.)?  I think I read somewhere you can do this with WiFly you just can't do an full FTP server implementation.



#9 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 17 January 2013 - 02:23 PM

Hi Dave,

 

I'm trying to build a data logger which uses a photo sensor to count actions (I've already got this working as well as writing the count to an LCD).

 

Basically every time the sensor beam is broken I have an On_interrupt increase a counter variable by one and then write the count and datetime stamp to a new line in a text file on the SD card.

 

I was then going to have a timer upload that file to my server every 5 minutes(for example). Once the file is uploaded I'll send an HTTP request to a .NET page which will in turn read the text file (on the server) and write the count values into an SQL DB.

 

So simply:

 

Main function{    connect to wifi    wait for interrupt}On_interrupt{    increase counter by 1    write count/dateTime to the SD card text file    trigger 5 minute timer to start upload (if timer not already running)}Upload{    upload file to FTP server    empty file for new values    send HTTP request to read file on server    reset timer}

 

Because I'm only looking to send the file up to the FTP server (no download or anything else from the server) I thought that a single connection wold be fine? The Wifi isn't doing anything else at the same time.

 

And the reason we'd like to use wifi is so that we can place the sensor/netduino anywhere without having to worry about cabling back to a router. We'd like to use it in a factory on a press to count components as they come out of the machine.

 

Thanks for any help!

 

Regards,

Donovan

 

P.S. I did originally have it setup so that on the interrupt an HTTP request was sent with the count and datetime (as querystring variables) but this caused issues with timeouts and such and also was a problem if the wifi connection was dropped. The other issue is that, depending on the press tool which is running, the machine can churn out over 60 items a minute... that's FAR too many HTTP requests to try and send and would result in the whole thing falling over.


Edited by don664, 17 January 2013 - 03:06 PM.


#10 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 17 January 2013 - 03:50 PM

Sorry if I'm over simplifying this. I'm new to hardware development, but have built lots of sftp applications in the past as console apps, why don't you have one thread logging the data into various files on the sd card, and have another watching that directory for new files to process every 5 minutes. use the method you used or originally but have it parse and upload the file contents, when successful delete or rename the file so it isn't processed again and set a time out for the http request about 10 secs, this way if the timeout occurs the time out doesn't hold up data logging. Then when you have no Wifi, nothing is lost and will be uploaded as the Wifi connection is reestablished.

#11 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 17 January 2013 - 03:54 PM

Correction : If you are using 2 threads the http request, shouldn't block the data logging.

#12 ericcox

ericcox

    Member

  • Members
  • PipPip
  • 19 posts

Posted 17 January 2013 - 10:49 PM

According to the WiFly User Manual, the WiFly module supports FTP out of the box.  Is that not the case?

 

Looks like you basically set up an ftp connection using the "set ftp *" commands, and then wait for a connection. They probably use PASV transfers so they only need one connection.

 

I'm going to be needing this functionality for my project so I had planned on adding support for it to the WiFlyGSX class at some point.  If I'm wrong and it doesn't support it, I'm really screwed...

 

 

 

 

 

 

 

 



#13 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 18 January 2013 - 02:44 AM

nah, y

 

According to the WiFly User Manual, the WiFly module supports FTP out of the box.  Is that not the case?

 

Looks like you basically set up an ftp connection using the "set ftp *" commands, and then wait for a connection. They probably use PASV transfers so they only need one connection.

 

I'm going to be needing this functionality for my project so I had planned on adding support for it to the WiFlyGSX class at some point.  If I'm wrong and it doesn't support it, I'm really screwed...

 

 

 

 

 

 

 

 

nah, you can always code around that FTP limitation using HTTP



#14 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 18 January 2013 - 08:51 AM

Hi skobyjay,

 

and upload the file contents

 

 

The problem is I don't know how to get the wifi SimpleSocket to upload the file via FTP. I already have a routine which alternates between two files so that one file is the "live" file which is having the counts stored on it and the other is the "upload" file. Once the "upload" file has been uploaded it's emptied and becomes the "live" file and the old "live" file waits in the queue for it's turn to be uploaded.
 
The problem is getting the files FTP'd up to the server. And HTTP is not an option because of the memory leak issue I detailed here: http://forums.netdui...75-memory-leak/
 
And as I mentioned there could be as many as 60 counts a minute, which would mean 60 HTTP requests a minute and these machines run in 8 hour shifts... so that's 28 800 HTTP requests per machine and we're hoping to have about 20 machines using these Netduino counters. This is why I'd like to use FTP to get the data to the server and then simply have a script on the server process the text file.
 
Hi Eric,

 

According to the WiFly User Manual, the WiFly module supports FTP out of the box.  Is that not the case?

 

This is true and I have used CoolTerm to connect to the wifi module via a UartBee sheild and in CMD mode I have been able to contact the Roving Networks FTP server and download a firmware update for the RN-XV.

 

The problem is that I don't know how you'd go about accessing CMD mode with the wifi module on the netduino board or even if the two will even talk to each other then.

 

There has to be a way to use simpleSocket to upload a file via FTP? I have been able to successfully connect to my FTP server and create an empty text file on the server (using the code in my first post on this thread) so surely that's half the battle won?

 

I'm hoping that Dave is onto something and we can simply use the single connection as the data connection and have one way FTP. I have no need for a full FTP server implementation at this stage and simply want to get those data files off the netduino and onto the server.



#15 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 18 January 2013 - 02:19 PM

I don't have a WiFly Module to test this for you and don't have a WiFly help guide but I agree you are half way there. I responded on your memory leak thread post. Just throwing a few ideas out there. Let me know if it helps.

#16 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 18 January 2013 - 02:24 PM

http://msdn.microsof...e/hh852591.aspx

What you are trying to accomplish reminded me of an MSDN Magazine article I read. They are doing something similar with regular HTTP request and response objects each second. I found the article online (the link above. )

#17 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 23 January 2013 - 07:41 AM

how about using the single connection as the upload only and have the ND FTP the files to a file server with another type of trigger (ie: Menu system on the ND, or Timer, or Schedule, etc.)?  I think I read somewhere you can do this with WiFly you just can't do an full FTP server implementation.

 

Hi Dave,

 

Any luck with the wifi FTP?



#18 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 23 January 2013 - 11:39 AM

Hi Dave,

 

Any luck with the wifi FTP?

 

Unfortunately it's not something I have time to play with.  I don't use WiFly in any of my projects and most of the products I'm designing now use an HTTP server for file transfer since there are other HTTP functions that I need also.



#19 don664

don664

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationHillcrest, KZN, South Africa

Posted 23 January 2013 - 11:50 AM

Hi Dave,

 

I never knew you could use HTTP for file transfer; I'll look into this over wifi and report back any findings.

 

Thanks for the lead!



#20 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 23 January 2013 - 11:57 AM

Hi Dave,

 

I never knew you could use HTTP for file transfer; I'll look into this over wifi and report back any findings.

 

Thanks for the lead!

 

It's just like uploading and downloading files from a website.  I'm using the NeonMika Webserver running on my Netduino+ because I'm also transferring data using JSON and allowing some web access to Pandora's Box for easy configuration.







Also tagged with one or more of these keywords: wifly, wifi, ftp. netduino plus 2, rn-xv

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.