Skip to main content

Arduino Life 5: Arduino Yun and ftp client/server

One of the main reasons I purchased an Arduino Yun as my first Arduino board was it’s inclusion of WiFi right out of the box. This means you can start making Internet of Things projects immediately. As I have introduced myself to Arduino, I have also looked to learn more about the Linux side of the Yun, how it bridges to the Arduino side and how I can interact with it using standard Internet tools, like SSH and FTP.

Arduino yun

An Arduino with SSH

Once the Arduino Yun is connected to a network, it is possible to use the Macintosh Terminal or other SSH client to log into the Yun and use it as you would any Linux computer.

You’ll need an SD Card on the Arduino Yun to do much with SSH or ftp access, though, as you need a place to store the files you will be uploading or creating.

Arduino ssh 1

This is fine if you just want to view files on the SD Card or other basic terminal operations, but as I was playing around, I realized i wanted to do more than use the built-in vi editor. I use a Mac OS X text editor program called, TextWrangler for a lot of things, including coding. My first thought was to use an ftp client on the Yun to connect to my local computer, so that I could push data over to the Mac from projects like my temperature, humidity and light level sensor. After many searches, it looked like there wasn’t an ftp client for the Yun, but you could install an ftp server and then access that from the Mac. I also had another user for this ftp server, which I’ll show in a moment,

Textwrangler icon

TextWrangler for Mac OS X

An ftp server for the Arduino Yun

Installing an ftp server on the Arduino Yun is actually quite simple. SSH into the Yun and execute these two commands:

opkg update
opkg install openssh-sftp-server

You may need to reset the Yun using the reset button or by cycling the power in order to get the server started. After that, it will be automatically started on each boot. You’’ll now be able to use your favorite ftp client to connect to the Yun. 

Here’s a view of the Yun’s ftp server using Cyberduck on the Mac.

Ftp screen 1

One of the reasons I was so keen to have direct file access to the Yun was that I was trying to develop a short Python program to run on the Yun, but using my ancient (i.e. 30+ year old) knowledge of vi was quite limiting. TextWrangler supports direct reading and writing of text files to any FTP server, and I have used that when editing files on my web server, so I figured there had to be a way to install an ftp server on the Yun and then use Textwrangler to write code directly onto the Arduino.

Textwrangler 1

I can read and write directly to the server using TextWrangler. This means I can write my code, click Save and then immediately switch to my Terminal window and execute the code to test it. That makes it very convenient.

Going Further - Pushing files to ftp server using Python

Of course, once you find one use for the ftp server, more are sure to follow. One of the common beginner projects for the Arduino Yun is a motion-activated security camera. You an find complete instructions in this post from Adafruit.

Wireless Security Camera with the Arduino Yun
Build your own wireless security camera using the Arduino Yun & a USB webcam!

This example using the Temboo service to forward the photos and stream video from the Yun directly to the Internet. When I was looking at the project, though, I was thinking that, since I have my own web server available, I would rather forward the photos to a directory on the server where I could view them at my leisure. This, in fact, is what sent me on the original search for an ftp client for the Yun. While I didn’t find a full-blown client, though, I did find a programatic way to ftp files to the server of your choice using a Python program. This was a little more manual, but it got the job done.

Here is my test code — with no error checking or any other niceties — but I figured you might find the example useful. Many thanks for the folks at EFFBot that provided the great — and easily modified — code which I could build on.

import datetime
import ftplib
import os
# Function to provide easy uploads of appropriate type (Text/Binary)
# Taken from http://effbot.org/librarybook/ftplib.htm
def upload(ftp, file):
ext = os.path.splitext(file)[1]
if ext in (".txt", ".htm", ".html"):
ftp.storlines("STOR " + file, open(file))
else:
ftp.storbinary("STOR " + file, open(file, "rb"), 1024)
# Get Date
today = datetime.date.today()
# Get Time
now = datetime.datetime.now()
# Build webcam capture filename in YYYYMMDDHHMMSS format
fname="cam-"+now.strftime("%Y%m%d%H%M%S")+".jpg"
# Call fswebcam capture with resolution parameter
from subprocess import call
call(["fswebcam","-r 1280x720",fname])
# Open FTP session and change directory
ftp = ftplib.FTP(“yourserver.com")
ftp.login(“user", “password")
ftp.cwd(“/yourserver.com/cam/")
# Upload picture file
upload(ftp, fname)
# End FTP session
ftp.quit()

You might have noticed in the ftp screen shot above, this code does work. It snaps a picture from the webcam, stores it locally on the SD Card with a unique date and time--stamped name and  then uploads it to my web site. I plan on setting up this security camera as a test in one of my upcoming learning sessions and replacing the Temboo calls with this ftp script (or perhaps an improved version of it.) I’ll report back on how well it works in an upcoming post.

There is so much to learn about the Arduino world and the Arduino Yun especially. It’s obvious now that many people have wanted a board like the Yun, as Arduino has now introduced a shield that can turn an Arduino Uno — one of the most popular boards — into a functionally equivalent Arduino Yun.

Arduino Yun Shield on eBay

Arduino Yun Shield on Amazon.com

I hope you’ve found this edition of Arduino Life useful. Please send along your questions and comments.

Comments

Popular posts from this blog

Microsoft release Outlook.com email services to replace Hotmail

Today Microsoft released its new email service Outlook.com to replace its Hotmail brand. This new streamlined Metro interface design looks good and functions well so far. You can use your existing Microsoft account to log in and then choose an email alias (i.e. douglaswelch@outlook.com) for your new email address. Here are several articles that discuss Outlook.com... Goodbye, Hotmail; Hello, Outlook.com [REVIEW]  Outlook Is a Completely New, Feature-Filled Webmail Service from Microsoft Go Get Your @Outlook Email Address Quick Before Someone Else Does I will post links to more articles and reviews as they appear.

Shared calendars are one part of an organized family

by Douglas E. Welch , techiq@welchwrite.com 206-338-5832 Reader/Listener Line As a parent with a school-age child, I often hear other parents bemoaning their disorganized existence. Along with the busy schedules of two working parents you might have art classes, karate classes, Little League, soccer and more. Add in more than one kid and organizing your life can quickly become a nightmare. This is exactly why one of my most important organizing devices is a shared calendar that reflects all the activities and events for everyone in the household...and I do mean everything. If someone -- is required to be somewhere -- at sometime, it goes into the calendar. If we are given a calendar that reflects all the events for a particular activity (say, Little League), all these events immediately go into the calendar, along with notations on whether we are providing the team snack, working in the snack bar, etc. Even events that occur anytime during the day, like family birthdays, and other rem...

Google Docs adds templates

I have started to move away from using Microsoft Office (Word, Excel, Powerpoint, etc) in favor of online tools like Google Docs . Even as a computer consultant, I find that I use probably less than 10% of the features in any of these projects. One feature I really like in Google Docs is the easy, online file sharing that also allows you to edit simultaneously with someone else. Today, Google Docs added some templates including business cards, brochures and more. At the moment, it looks like they are rolling out this feature over time, so you might not yet see the templates on your account. When available, you will find the templates under the New... menu item. From Open Loops ... Today, Google quietly rolled out a new feature for their Google Docs Applications: Templates! It's so new that it isn't even listed on the new features page at this time. When one opens their Google Docs account and chooses to start a new document, a new "From Template..." command is pre...