Creating Text FIle on the fly then emailing it - anyone done this?
xanatos
Posts: 1,120
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
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
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:
If you have 100 sensors, call 100 copies of this object in your application.
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:
Hope this gives you some ideas!
Robert
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.
Thanks again,
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!
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
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.