IoT Cookbook > Arduino Yun > Serial-to-WAMP Bridge

Yun Serial-to-WAMP Bridge

This page describes how to install the necessary software on a Yun to enable remote control of the Yun's Arduino pins via WAMP. For an overview of all materials we have concerning the Yun, see

Arduino Yun GPIO Remoting

The big picture

The GPIO pins are managed by the Arduino MCU part of the Yun, while all network communcation is managed by the MIPS part. To get remote control, we need to pass data from the MUC to the MIPS/Linux part, and the send this over the network. We use WAMP for the remote communication. For the MCU-MIPS bridge we use the Firmata protocol.

There is an Arduino implementation of Firmata, which the MCU part runs. There are various implementations which we could run on the Linux side. In the end, using Node.js with arduino-firmata and Autobahn|JS to provide WAMP connectivity proved easiest.

This does not mean that you have to use JavaScript for your application: we provide access via WAMP to all the pins, so that you can write your actual control code in any language with a WAMP implementation. (You may at some point move control code onto the Yun itself, at which point the implementation languages become important again.)



We offer Quick Setup instructions which use an image you can write to SD card, and which already has all the preparations for the serial-to-WAMP bridge installed for the Linux side. Otherwise you need to get AutobahnJS working on the Yun for the following.

The bridge code

Get the bridge code onto the Yun. If you've mounted the Yun's file system on your PC, just copy it over. Otherwise you can do

scp serial_to_wamp.js root@

from the directory the code is in (and where you replace the above IP with that of your Yun).

The MCU code

For the MCU, you need to install Firmata.

Running things

To run the bridge, just do

node serial_to_wamp.js

Configuring the connection to

The code for the access to the GPIO pins can be kept generic, but you need to configure the connection to a instance.

This is done via a config file in the same directory as the serial bridge code. This is a simple text file (config), with one config option per line.

The provided example config file is

realm: iot_cookbook
deviceId: my_yun

which means that the serial-to-WAMP bridge will attempt to establish a WAMP connection to a instance at and to the realm iot_cookbook on that instance.

For all events and registrations it uses the deviceID. (This means that the deviceID needs to conform to the rules for WAMP URIs.)


The API exposes procedures in the format<device_ID>.firmata.<procedure_name>

The procedures are:

For pins which have been set to watch, value changes are published to the topics<device_ID>.firmata.on_analog_changed

and (presently unimplemented)<device_ID>.firmata.on_digital_changed

Note: It is possible to read from a pin which is watched - so you can combine automatic notifications for value changes with e.g. getting the current value on component startup without having to wait for the next value change.

Testing and usage examples

The code for this in the Crossbarexamples repository allows you to start a instance to which the bridge can connect for development purposes.

This also serves an HTML page which attempts to read from an analog input and write to a digital output. This is mainly for illustrative purposes, to give you some examples for how the API can be used.


For examples of how remote GPIO can be used see e.g.