Shop OBEX P1 Docs P2 Docs Learn Events
Creating Text FIle on the fly then emailing it - anyone done this? — Parallax Forums

Creating Text FIle on the fly then emailing it - anyone done this?

xanatosxanatos Posts: 1,120
edited 2013-06-05 16:26 in Accessories
I have a few options to get some data to a remote server, but by far the best would be for me to have the Spinneret create a text file and then email it. I have a system that uses a bunch of 4066 analog switches to select a sensor for A/D conversion. The data needs to be sent to a remote server. The data collection part (uC, 4066's and various stuff) is all set - just the server to server stuff that I'm asking about.

My Spinneret has a 1G SD card in it - and the data collection system can write the collected values from the (nearly 100) sensors to a standalone RAM chip, which can be read by the Spinneret... I'm wondering if anyone has created a text file either on the fly, or written it to the SD Card, and then either mailed or Ftp'd it to some remote location from the Spinneret.

Or would there be a better way to do this? Bearing in mind that I have little, if any, ability to change anything at the remote server (they're expecting basically a CSV file).

Mike G, anyone? :-)

Thanks,

Dave

Comments

  • RforbesRforbes Posts: 281
    edited 2013-06-04 13:37
    Dave,

    Several ways to do this. For making the data use easier to work with I use an abstract data structure (The last method mentioned in this appnote from parallax) http://www.parallaxsemiconductor.com/sites/default/files/appnotes/AN003-AbstractDataStructures-v1.0_1.pdf

    Example object:
    ''This is file SenVal.spin
    CON
      _xinfreq = 5_000_000                     
      _clkmode = xtal1 + pll16x     
    
    Var
    long SensorVal               'Value for attached sensor
    
    Pub Sensor_(Val)                 'Sensor Value: WRITES value to variable. (IO,Val)= IO point and value to put. 
          SensorVal:=Val
    
    Pub _Sensor                     'Sensor Value: READS value of variable. (IO)= IO point value to read.
          return SensorVal
    

    If you have 100 sensors, call 100 copies of this object in your application.
    OBJ
    Node[100]: "SenVal"
    

    Call your SDcard object (I use S35390A_SD-MMC_FATEngineWrapper and SD-MMC_FATEngine.spin")

    Write your sensor values using the appropriate method with whatever interval/condition you need. Example: Node[27].Sensor_(myvalue)

    Create the file with the sd card method SDCard.newFile(fileName)

    Open the file in append mode. Example: SDCard.openFile(filename, "A")

    Append data to the file using the appropriate sd object method and sensor object method. Example: SDCard.WriteDec(Node[27]._Sensor)

    Close the file. Email the file.

    Oh, and ftp can work with the same idea. Once you're done writing the data to the text file, you'll send your login and other commands to the ftp server. This is a little tricky but very doable. You'll probably want to set up your ftp commands in the DAT section so that you can send 1 command, get your response, verify the response and do the next command (or error trapping if the response is bad) and on and on. Something like:
    DAT
      ftp1                  byte    "user my_name",13,10,0
      ftp2                  byte    "pass my_pass",13,10,0
      ftp3                  byte    "OPTS UTF8 ON",13,10,0
      ftp4                  byte    "type A",13,10,0
      ftp5                  byte    "mode S",13,10,0
      ftp6                  byte    "epsv",13,10,0 
      ftp7                  byte    "rest 0",13,10,0  
      ftp8                  byte    "appe ",0     'use stor to overwrite the file on the vps
    
      quitcmd               byte    "quit",13,10,0
      aborcmd               byte    "abor",13,10,0
    


    Hope this gives you some ideas! :)

    Robert
  • Mike GMike G Posts: 2,702
    edited 2013-06-05 07:04
    xanatos,

    Rforbes nailed it... Write to the SD card in the required format then send the file when ready.

    The other thing you can do is request the file from the Spinneret. That is much easier and does not require any extra coding to handle sending. Just HTTP GET the file.
  • xanatosxanatos Posts: 1,120
    edited 2013-06-05 12:06
    RForbes & MikeG - thank you both. I have a LOT to learn on the Spinneret. My SPIN experience is very limited. Very. I understood about 10% of the code above... I am completing the hardware side of the data acquisition section and hope to be into Spinneretting full swing by this weekend... a serious crash course. If the internet fails this weekend, you'll know who to call :-) On the bright side, I hope to emerge on the other side of this project with a truly great understanding of Spin and the Spinneret (and the prop too...) - so far, something that has eluded me fairly well.

    Thanks again,

    Dave
  • RforbesRforbes Posts: 281
    edited 2013-06-05 14:25
    Dave,
    Sounds like you'll have a good time with this project! Ask all the questions you'd like- the folks here are really helpful and willing to lend a hand. If it weren't for Mike G and a few others I'd have thrown my spinneret and quickstarts in the toilet a few months ago. :)

    Mike- Ah dang, I didn't even think about using GET lol... I just focused in on manually doing what he asked. Yeah, you're right. Much easier your way!
  • xanatosxanatos Posts: 1,120
    edited 2013-06-05 15:54
    Yes indeed... it'll be fun.

    The only thing I was wondering about GET - doesn't that require an active request from the remote server? They're an "established company", meaning I expect to have to conform to their requirements and not ask them to make any adjustments to their operations... am I missing anything here?

    Dave
  • RforbesRforbes Posts: 281
    edited 2013-06-05 16:26
    Dave,

    Well, I'm unable to give any advice concerning their policies on IT security or operational needs/restrictions/etc.

    But, I'd imagine they have a static ip for their server. If you don't have a static ip for the spinneret to run on it might be difficult to get their server to contact the spinneret in order communicate. Mike G is most definitely more knowledgeable about this sort of thing than I.

    I would imagine you could write a php file on the remote server. Post to that file with the spinneret. The php file then makes a GET request to the appropriate file on the spinneret, and some other stuff I dunno how to do... and presto! Problem solved. Easy-peasy if you know what you're doing. Not so much if you don't. And I don't. :)

    The good thing about using an ftp server is that if they have a static ip and you don't, there's really no problem unless they require encrypted comms via that method of communication. I have NO idea how to go about incorporating Sftp or other encryption techniques with the spinneret, but I can answer questions for you if you'll be using good ole standard, plain, unsecured comms to upload data via an ftp server.

    I'd highly suggest you try to follow Mikes advice and see if you can get a GET to work for you the way you need it to.

    If that isn't going to work out for you, you'll likely need to look up the RAW ftp commands and become familiar with how to use EPSV command to upload to the ftp server. The only tricky part with using the EPSV command is parsing the response you get. I'll post some code snippets for that when you're ready for it.
Sign In or Register to comment.