Saturday, 28 July 2012 18:43

Control Arduino with TP-Link TL-WR1043ND Router

The Arduino is plug into the USB port of TP-LINK TL-WR1043ND allow the router to control the Arduino.

After upgrade router firmware to Openwrt, Login to it & change the password in order to enable SSH.

SSH to the Router

  1. Run PuTTy
  2. Enter for Host Name (this is the default IP for Openwrt set in TL-WR1043ND)
  3. Change connection type to SSH
  4. Click on Open button
  5. Enter your router username (username is root if you didn't change it)
  6. Enter your password

PuTTy after Login


Install FTDI USB Serial
opkg update
opkg install kmod-usb-serial-ftdi
It should like this:

Install FTDI USB Serial

If you are using Teensy or Arduino Uno
opkg install kmod-usb-acm
If you are using PL2303 based USB/serial adapters
opkg install kmod-usb-serial-pl2303
If you are using CP201x based USB/serial adapters
opkg install kmod-usb-serial-cp210x

Verify USB Serial driver

After install the FTDI usb serial driver, it is advise to verify the driver is installed properly. Plug in Arduino to the USB port of router and execute the following command.

dmesg | grep -i usb


FTDI USB Serial Device converter is attached to ttyUSB0 as shown in figure below. Unplug the Arduino from the router will display disconnected from ttyUSB0

Verify USB Serial Driver



Install Serial to Net (ser2net)
Here I show you 2 different methods to control the Arduino, ser2net and socat.
To install ser2net, execute this code:

opkg install ser2net

Install Serial to Net


Edit ser2net Configuration
To make ser2net listen on TCP port 1234, append 1 line to the end of /etc/ser2net.conf



Using WinSCP to edit the configuration. The setting is added to the ser2net configuration as shown in figure below

.Using WinSCP to edit ser2net configuration file
This will open a tcp 1234 port & set to baud rate 9600. The usb serial port will be /dev/ttyUSB0



Install socat

socat is much more powerful & features than ser2net. To install socat, enter the following command:

opkg install socat

Install socat



Start ser2net or socat
You will need to start ser2net or socat before you can control the Arduino. There is two way to start ser2net & socat. You can start it manually or automatically on every reboot.

Start ser2net manually


ser2net will start based on ser2net configuration file


Start socat manually (Arduino Duemilanove)

socat tcp-l:1234,reuseaddr,fork file:/dev/ttyUSB0,nonblock,raw,echo=0,waitlock=/var/run/tty,b9600

This will open a tcp 1234 port & set to baud rate 9600. The usb serial port will be /dev/ttyUSB0


Start socat manually (Arduino Uno R3 USB chip)

socat tcp-l:1234,reuseaddr,fork file:/dev/ttyACM0,nonblock,raw,echo=0,waitlock=/var/run/tty,b9600

This will open a tcp 1234 port & set to baud rate 9600. The usb serial port will be /dev/ttyACM0


Open the port 
This is particular important, it use to prevent autoreset on initiation of serial.
cat /dev/ttyUSB0 


You can open the port on every router reboot

  • Login to router
  • Click System -> Startup
  • Scroll down the screen until you see Local Startup
  • Enter cat /dev/ttyUSB0 before exit 0 as shown in figure below. 

Openwrt Startup


Arduino Code
The code I'm using is downloaded from Ocean Control

New article was addes on 19 Aug 2012, it is a 16 output Arduino Controller. You can download this code for this project.

Communicate with Arduino
Done! You have finishing install all the required modules/drivers for the router. It is time to test the Arduino.
To control from SSH, use the following code to turn on channel 3.
echo "@00 on 3/r" > /dev/ttyUSB0
Another way is to use realTerm.  You can download realTerm from 
 RealTerm Communicate with Arduino
  1. Run realTerm
  2. Click on Port tab
  3. Enter 9600 for Baud since the default baud rate for the Arduino is set to 9600
  4. Enter, where is the router IP & 1234 is the port. Make sure it match with the ser2net or socat settings.
  5. Click on Open button
  6. Click on Send tab
  7. Enable +CR from EOL since the Arduino require Carriage Return as the termination.
  8. Enter @00 on 1 & click on Send ASCII button
You will notice that the LED1 from Arduino is turned on.
Enter @00 of 1 & click on Send ASCII button to turn off LED1 


Here I develop a program using Delphi called Arduino Control System. Click here to download the Delphi source code & executable file:

  • Extract the file to any folder
  • You can change the host (router IP) & port in the setting.txt file to match with your router settings.
  • Run Arduino.exe

 Arduino Control System

How to use the Arduino Control System

When the program is loaded, it read the status from Arduino & display the output to the screen. If the output is ON then a green box is show, in the other hand, a red box is show.

  • Click on the buttons (1-8) to toggle the output from ON to OFF or from OFF to ON
  • Click on Off All to turn off all output
  • Click on On All to turn on all output
To control the Arduino over the internet, you need a DDNS account to update your public IP & you must enable port forward to 1234. Read here for more information.
Upon open TCP port 1234 from the router, you will open the port for public & anyone can control your arduino without authentication. To resolved this problem, read this article 
and also this article.




Read 66113 times Last modified on Monday, 07 October 2013 22:36
Back to Top