Remote control of Arduino with Flash

Posted on: 14.01.09

As part of my on going development of a Arduino controlled model railway I have been investigating methods of controlling it over networks.

I decided to use Flash to build the interface as I have more experience using it and I could prototype quickly.

My first investigations led me to the AS3 Glue Library. Which used in conjunction with Serproxy (which is bundled with the library download) I managed to get flash to control the Arduino connected to my machine. Then loading serproxy on my laptop on my local network and controlling from my main PC this was working also. serproxy however is quite hard to use and it did take me a while to configure.

But that when I found a brilliant tutorial by Bjoern Hartmann over at Stanford. It can be found here.

This tutorial uses a new custom Arduino IDE which incorporates a Serial Proxy. This is much easier than serporxy! The only issue I then had was allowing files ran in a standalone flash player to connect. As flash player since version 7 (i think) won’t allow socket connections by default unless the file is trusted or a policy file states that it is allowed. Information on that can be found here..

I have now managed to get a Policy file server working on port 843 as suggested above which will allow connections to port 11100 where the Arduino socket to serial proxy is listening. I also forwarded ports 843 and 11100 on my router to my laptop where the server is. This means by specifying my router IP flash files ran on someones local machine can connect to my local server and in turn connect to my Arduino. I have only tested this with one connection so far so its early days. But it means that I can create a flash interface and upload it to my hosting. Where another user on the internet can connect and use it to control my Arduino locally.

For reference here is my code:

First the Flash Policy File server which is running the standalone perl version from http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html.

Using this command line
sudo perl flashpolicyd.pl --file=../flashpolicy.xml --port=843

The flashpolicy.xml contents:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">

<!– Policy file for xmlsocket://socks.example.com –>
<cross-domain-policy>

<!– This is a master socket policy file –>
<!– No other socket policies on the host will be permitted –>
<site-control permitted-cross-domain-policies=”master-only”/>

<!– Instead of setting to-ports=”*”, administrator’s can use ranges and com$
<!– This will allow access to ports 123, 456, 457 and 458 –>
<allow-access-from domain=”*” to-ports=”*” />

</cross-domain-policy>

Then loading the standard firmata and running a serial proxy using the new Arduino IDE (013) and using this AS3 code to connect.

var arduino:Arduino = new Arduino("000.000.000.000", 11100);
arduino.addEventListener(Event.CONNECT,onSocketConnect);
arduino.addEventListener(Event.CLOSE,onSocketClose);
arduino.addEventListener(ArduinoEvent.FIRMWARE_VERSION, onReceiveFirmwareVersion);
arduino.addEventListener(ArduinoEvent.DIGITAL_DATA, onReceiveDigitalData);
arduino.addEventListener(ArduinoEvent.ANALOG_DATA, onReceiveAnalogData);

This connect code taken from AS3 Glue Examples test_arduino.as. Replacing the 000.000.000.000 with your routers IP will then allow it to be used outside your home network or if using it internally the local IP for your other machine.

I have posted all of this here along with other peoples comments http://protolab.pbwiki.com/TutorialFlashSetup2009

One comment on “Remote control of Arduino with Flash”

Comment.

You must be logged in to post a comment.