Note

Tested using Arduino Mega (AtMega 2560) and OpenWRT backfire 10.03.1 on a TP-Link TL-WR1043ND.

Basics

Install the following packages on your OpenWRT device:

  • kmod-usb-acm
  • socat

Connect your Arduino on the USB port and check the kernel messages. It should mention a new ttyACM0 device; that's our Arduino.

Now fire up socat to listen on a TCP port and connect it to /dev/ttyACM0 like this:

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

Change your baudrate (here 9600) and port (here 1234) accordingly. Now you should be able to telnet to the device on another machine like this:

$ telnet 192.168.1.1 1234

Background service

In order to create it a always-running background service we should hook in to OpenWRT's services, but this will do as well:

#!/bin/ash

DEV=/dev/ttyACM0
PORT=50000
BAUD=9600

while true; do 
    if [ -e $DEV ]
    then
        socat tcp-l:$PORT,reuseaddr,fork file:$DEV,nonblock,raw,echo=0,waitlock=/var/run/tty,b$BAUD
    else
        sleep 2
    fi
done

Put it somewhere and make it executable (chmod +x filename). Add it to boot time by editing /etc/rc.local:

# make sure it's above 'exit 0'!
/path/to/the-script_above.sh &

exit 0

Tip

The appended & puts it in the background so rc.local will finish (and the boot of the device finishes) with the script in the background.

Share on: TwitterHacker NewsFacebookLinkedInRedditEmail


Published

Category

Miscellaneous

Tags

Connect with me on...