Thursday, December 26, 2013

ftp using Linino CPU and Python

I started with ftp-ing directly from the MCU using Curl.
Obviously this isn't very optimal given the Yun architecture.

I changed this so that the Linino gets the Temperature (or other measurements) from the MCU and then the Linino CPU will do the ftp-ing. Using Python this is very straightforward.

The only tricky part is that the ftp expects a file, but I don't want to put the data in a file. Luckily there exists a StringIO class that can take care of that. The code becomes something like:
import StringIO
from ftplib import FTP

myFileIO = StringIO.StringIO()

myFileIO.write(now_str)
myFileIO.write(",")
myFileIO.write(temp)
myFileIO.seek(0)
ftp=FTP("ftp.homebrew.be")
ftp.login(User,Pass)
ftp.cwd("www.homebrew.be/Yafa")
ftp.storlines("STOR dat.csv",myFileIO)
ftp.close()
myFileIO.close()

Use APPE instead of STOR if you want to append to the file.

No comments:

Post a Comment