Control Arduino with TP-Link TL-WR1043ND Router
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
opkg update
opkg install kmod-usb-serial-ftdi
|
opkg install kmod-usb-acm |
opkg install kmod-usb-serial-pl2303 |
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
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.
echo "@00 on 3/r" > /dev/ttyUSB0 |
- 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
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
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
文章来源: blog.csdn.net,作者:悟空胆好小,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/xushx_bigbear/article/details/46608099
- 点赞
- 收藏
- 关注作者
评论(0)