On-board WiFi, Ethernet, a microSD slot for storage, and a version of OpenWRT Linux called Linino. What more could I want on an Arduino which is the same size as one of the simpler USB-only models I have? As a sucker for small gadgets, I ordered an Arduino Yún to see what it’s all about.
The device is two-in one: an Arduino and an OpenWRT machine on a single board. By default the Yun powers up with the WiFi in AP mode. Plugging in Ethernet gives the device an address from your network via DHCP. Sketches can be uploaded to the Arduino portion of the Yun via USB serial or via WiFi / Ethernet after entering the device’s password. (I dread the thought of finding environments with Yuns on default or no passwords in near future …) Be that as it may, the Yun is the first Arduino we can SSH into:
The Arduino has no access to the Ethernet or Wifi interfaces, which means sketches for, say, Ethernet or Wifi shields need re-designing. The Arduino bit of the Yun can speak to the outside world via a so-called “bridge”. Documentation for the Bridge library exists, but it’s pretty minimal, and it doesn’t (yet) answer the questions I have, so I attempted to figure out what’s going on behind the scenes.
The bridge library offers the following interfaces:
- Process can launch processes (e.g. shell scripts) on the Linux processor and read their output.
- Console replaces Serial in as much as I can telnet to the console to see debugging output from my sketch or interact with it over the network.
- FileIO is an interface to the Linux file system and can be used to read/write files on the microSD card.
- HTTPClient creates an HTTP client on Linux.
- Mailbox is a sessionless interface to a volatile key/value store.
- YunClient emulates a TCP connection to an arbitrary host/port via the bridge.
- YunServer is an Arduino-based HTTP server
As soon as your Arduino sketch uses one of the Bridge classes, the board invokes
run-bridge via serial on the Linux side. Console also uses bridge, as do FileIO, etc. For example, FileIO instructs bridge to create a file by sending an
Fx command, where x is the mode with which to open the file (
g performs a write() via the bridge,
s does a seek(2),
f a close(2), etc. The Mailbox class also uses bridge with different commands (
m is readMessage(),
M is writeMessage(),
J is writeJSON()).
run-bridge is a shell script which invokes
python bridge.py from
/usr/lib/python2.7/bridge. On the one hand, that is good news because we can modify how it works. On the other hand that’s bad news for the same reason – imagine not being able to rely on how a sketch communicates with the outside world.
Be that as it may, the following small sketch (Arduino side) sends a bit of data to Linino (the OpenWRT/Linux portion of the board) every 200ms:
This sketch uses the Mailbox class to “put” two values into a volatile key/value store held within
bridge.py; this is a dict in
mailbox.py, imported into
bridge.py. This dict is made available to the Arduino on the one side, and to a so-called TCPJSONServer at 127.0.0.1:5700 on the Linino side. The latter is gatewayed to via uhttpd, the micro HTTP server running on Linino:
When the sketch is restarted (on Arduino), the bridge is restarted, and the key/value store is reset.
A simple HTTP interface to the key/value store is provided as a Web page on Linino, and I can choose to have authentication-free access to the REST interface on the Yun’s configuration page.
The Yun isn’t cheap, but the EUR 65.00 include everything I mentioned above. Considering what the Ethernet shield costs or a Wifi shield would cost, this is probably pretty good value for money. On the other hand, there are Arduinos with on-board Ethernet which are considerably cheaper than the Yun.