Sunday, March 17, 2013

Ethernet to UART software bridge

When you want to make a quick project, it is very important to have a bunch of software written for you.   For example, it took me more than a week to write an application that makes a communication between microcontroller and a router. The problem with the router is, that it has small memory, so you can't install a compiler or to install java, python etc... Of course, you have lua(or another scripting language), a great embedded language, but how many people knows lua. The embedded world is based on C(in my opinion). In order to write apps for openwrt in C language, you need to install tools, figure out how to use, configure, write your app. So i made this app, that i think is a general app for embedded stuff.

What this software does, is very simple, but i think very useful. If you want to connect, let's say your arduino to a router, just connect it via native UART or via USB to UART converter and you can communicate with it over your IP network.

How does it work? The program creates a TCP server socket on a router(on any port you want). So using a simple client app on your PC you can collect data from your board. For example you can use Hercules(just google it). The program also opens the serial port. So all data received over TCP are send to serial port, and all data received over serial port are send over TCP.

How to install? Just copy .ipk file to router using for example winscp. To install the app, login to your router with putty and type the command:

          opkg  install  eth_uart_bridge_1.0_ar71xx.ipk

How to use? In command line type:

          eth_uart_bridge

The program will be started with default parameters as shown below :
  • 5000      - TCP port
  • ttyATH0 - default openwrt serial port
  • 9600bps - serial baud rate
  • 8N1       - 8 bits, no parity, 1 stop bit
If you want to run the program with non-dafault settings, just type:

         eth_uart_bridge  /path_to_file/config_file.txt

   where the config_file.txt is a file that holds configuration data.It can have any name and looks like so:

    Ethernet_port:5007;           //1024 - 9999
    Serial_port:ttyUSB0;
    Baud_rate:19200;  
    Frame_info:8N2;

The router kernel uses the serial port as console output. In order to block that you have to comment(with #) or erase the following line in /etc/inittab:

          ttyS0::askfirst:/bin/ash --login

If you want to run the program when the router starts just add this line in /etc/rc.local:
        
         eth_uart_bridge > /dev/null 2>&1 &
 
For more details about starting at startup go here.

You can download the package here, and the configuration file here. This software was tested on the TL-WR740 and TL-MR3020. Actually it can be installed on any router that is ar71xx compatible.


    Update: Before making some stuff, it is useful to google first. Unfortunately i forgot to do that :D.  There is a software that makes exactly the same thing i needed. The program is called ser2net (serial to network proxy). This program is ported to all linux compatible OS. 


No comments:

Post a Comment

Write your comments here...