Control Arduino with TP-Link TL-WR1043ND Router

举报
aiot_bigbear 发表于 2022/09/25 03:55:04 2022/09/25
【摘要】 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...

http://ediy.com.my/index.php/blog/item/6-control-arduino-with-tp-link-tl-wr1043nd-router

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

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

.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

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

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


文章来源: blog.csdn.net,作者:悟空胆好小,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/xushx_bigbear/article/details/46608099

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。