您的位置:首页 > 产品设计 > UI/UE

Control Arduino with TP-Link TL-WR1043ND Router

2015-06-23 17:25 423 查看
http://ediy.com.my/index.php/blog/item/6-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

Run PuTTy

Enter 192.168.1.1 for Host Name (this is the default IP for Openwrt set in TL-WR1043ND)

Change connection type to SSH

Click on Open button

Enter your router username (username is root if you didn't change it)

Enter your password



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



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



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


Edit ser2net Configuration

To make ser2net listen on TCP port 1234, append 1 line to the end of /etc/ser2net.conf
1234:raw:0:/dev/ttyUSB0:9600
Using WinSCP to edit the configuration. The setting is added to the ser2net configuration as
shown in figure below

.


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


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
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.



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 fromhttp://realterm.sourceforge.net/



Run realTerm

Click on Port tab

Enter 9600 for Baud since the default baud rate for the Arduino is set to 9600

Enter 192.168.1.1:1234, where 192.168.1.1 is the router IP & 1234 is the port. Make sure it match with the ser2net or socat settings.

Click on Open button

Click on Send tab

Enable +CR from EOL since the Arduino require Carriage Return as the termination.

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 hereto
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



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

Note:
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.

Warning

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.

password
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: