Saturday, 15 September 2012 15:00

Sending Message to Serial Port of Router using Lua

A few ways to send message to serial port of router which flash with OpenWRT. PHP;ser2net; socat; Lua and etc.
  • PHP require to install lighttpd,lighttpd-mod-cgi,lighttpd-mod-fastcgi,php5-cgi,php5-fastcgi,libsqlite3, installation is complicated & consume resources.
  • ser2net/socat is very simple but did not support web service.
  • Lua comes as a default in openWrt and support web service. The goodies is OpenWRT using Luci for web GUI and LuCI is an embedded rapid application development framework written in Lua.
Prerequisite
 
 
 
Installing FTDI for Router
First, we must install USB-Serial library for router in order to making the USB port act as a serial port. Here I install FTDI library since Arduino duemilanove using FTDI chip for interface.
opkg install kmod-usb-serial-ftdi

 

Verify USB-Serial port

To make sure the USB-Serial port is working, enter code below. You should see FTDI USB Serial Device converter now attached to ttyUSB0.

dmesg | grep -i usb

 

Execute Lua script from Router
The most simple way to execute Lua script is SSH to router and enter lua. Now you can enter Lua command line by line. 

login as: root
[email protected]'s password:


BusyBox v1.15.3 (2011-11-24 00:44:20 CET) built-in shell (ash)
Enter 'help' for a list of built-in commands.

_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
Backfire (10.03.1, r29592) ------------------------
* 1/3 shot Kahlua In a shot glass, layer Kahlua
* 1/3 shot Bailey's on the bottom, then Bailey's,
* 1/3 shot Vodka then Vodka.
---------------------------------------------------
[email protected]:~# lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio (double int32)
>

 

 

Open the Port

This is particular important, it use to prevent autoreset on initiation of serial.

cat /dev/ttyUSB0

 

Arduino should acknowledge and reply message to router. This should look like this

[email protected]:/www# cat /dev/ttyUSB0
Conrtonller Ready.

 

 

Sending command to USB-Serial

While cat /dev/ttyUSB0 is still running, open another incident and execute script below.

This will open a ttyUSB0 port and send on3 (include carriage return) to the port. Arduino channel 3 should turn on.

io.output("/dev/ttyUSB0")
io.write("on3\r")

 

Completed step should look like this.

[email protected]:/www# lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio (double int32)
> io.output("/dev/ttyUSB0")
> io.write("on3\r")
>

 

 

Execute Lua script from a File

Save script below to router /www/test.lua. Do not use notepad to create the file (it is not a unix file format). Here I use WinSCP.

print("Turn on channel 2 and channel 3")
io.output("/dev/ttyUSB0")
io.write("on2\r")
io.write("on3\r")

 

Run the file as shown in figure below. Channel 2 and Channel 3 should turn on.

[email protected]:/www# lua /www/test.lua
Turn on channel 2 and channel 3

 

Open USB-Serial port on Reboot

  • Login to router
  • Click System -> Startup
  • Scroll down until you see Local Startup
  • Insert cat /dev/ttyUSB0 in front of 'exit 0' as shown in figure below
  • Reboot the  router
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
 
cat /dev/ttyUSB0
 
exit 0

 

Execute Lua file from Browser

  • The Lua file must place in /www/cgi-bin directory of router.
  • The first line of the Lua file must start with #!/usr/bin/lua
  • Change file permission to 0755 or 0777.

 

Having the same example test.lua, copy it to /www/cgi-bin and rename it to test (without extension), you should have /www/cgi-bin/test in the router.

#!/usr/bin/lua
print("Turn on channel 2 and channel 3")
io.output("/dev/ttyUSB0")
io.write("on2\r")
io.write("on3\r")

 

Setting File Permission to 0755. This is particular important or else you will not allow to run the file.

chmod 0755 /www/cgi-bin/test

 

Execute Lua script from Browser

  • Open a browser
  • Enter http://192.168.1.1/cgi-bin/test (192.168.1.1 is the router IP address, you should use your own IP address)
  • Channel 2 and  Channel 3 should turn on

 

Authentication

Use code below for authentication before execute Lua file. The user name & password same as the router login user name & password.

echo '/cgi-bin:root:$p$root' > /etc/httpd.conf; /etc/init.d/uhttpd restart

 

Updated on  04 Jan 2014
A much more simple example to demostrates how to send yourMessage with carriage return to ttyUSB0 port.

command="echo yourMessage\r > /dev/ttyUSB0"
os.execute(command)

 
Read 42522 times Last modified on Sunday, 12 June 2016 10:52

12 comments

  • Comment Link Aappencyavafe Monday, 20 January 2020 18:00 posted by Aappencyavafe

    lunch http://cialisoni.com/# - cheap cialis online participate online cialis chapter
    green https://cialsagen.com/# - buy viagra online amazon buy viagra cheap generic viagra whereas

  • Comment Link Stevambums Sunday, 19 January 2020 23:09 posted by Stevambums

    Vibramycin Clobetasol Low Price With Free Shipping. Discount Generic Clobetasol Internet Quick Shipping Price Riverside buy cialis online Cialis Au Luxembourg

  • Comment Link Stevambums Friday, 10 January 2020 01:11 posted by Stevambums

    Acheter Amoxicillin Pharmacie Au Rabais Vallee D Aoste Ou Acheter Du Viagra Buy Cialis Tadalis Sx Soft History Cephalexin 11 Pound Puppy Levitra 9 Dollars Walmart

  • Comment Link BruceErho Thursday, 09 January 2020 01:58 posted by BruceErho

    http://dapoxetine4.com - buy priligy pills buy priligy no rx

  • Comment Link Aappencyavafe Wednesday, 08 January 2020 21:37 posted by Aappencyavafe

    travel http://cialisle.com/# - buy online cialis advocate generic cialis online fee

  • Comment Link Aappencyavafe Wednesday, 08 January 2020 00:39 posted by Aappencyavafe

    focus http://cialisoni.com/# - online cialis dance cheap cialis online enemy

  • Comment Link Floydgycle Tuesday, 07 January 2020 19:31 posted by Floydgycle

    XXX Videos Porn XXX
    Free XXX Porn Tube & Videos.
    Best XXX Video & Movies.
    Porn XXX Video Sex Porn Videos.
    Sex XXX Sex Movies Porn Movie.
    Watch now the best free porn!!
    Porn Tube, 100% Free
    XXX Videos, Sex Movies, Porn Videos
    Porn XXX,Free Sex,Porn HD,Porn Movies
    Porn Videos Tube, Porn Video XXX
    XXX Movies, XXX Video Tube
    Best Porn Websites. Watch Best Porn Videos for FREE:
    https://japxxx24.com - Jap XXX Japanese XXX Video Jap XXX Uncensored - Jap XXX.
    https://xxxchinatube.com - China XXX Tube Video XXX China Video Chinese Uncensored - XXX China Tube.
    https://gayxxx24.com - GayXXX Free Gay Porn Movies & Videos Free Gay XXX - Gay XXX.
    https://porno24.org.pl - Duza baza darmowych filmow porno.Czesta aktualizacja.
    https://xxxasianporn24.com - Free Asian Porn Tube Videos. Watch now best Asian Porn Movies.

    Have fun watching porn on best porn websites.
    Have a nice watch :)
    Thank you :D

  • Comment Link Aappencyavafe Sunday, 05 January 2020 00:18 posted by Aappencyavafe

    union http://cialisoni.com/# - generic cialis online technical cialis online canada arrange

  • Comment Link JeremyLam Wednesday, 01 January 2020 22:49 posted by JeremyLam

    Привет всем участникам! класный у вас сайт!
    Нашел обширную базу кино: фэнтези смотреть бесплатно в хорошем качестве
    Здесь: лучшие исторические фильмы онлайн http://kinofly.xyz/istoricheskiy/ список 2018
    Здесь: http://kinofly.xyz/13649-strazhi-galaktiki-3-nachnut-novuyu-fazu-razvitiya-kinovselennoy-marvel.html "Стражи Галактики 3" начнут новую фазу развития киновселенной Marvel смотреть онлайн бесплатно
    Тут: http://kinofly.xyz/13253-iskusstvennyy-intellekt-razgromil-luchshih-igrokov-v-dota-2.html

  • Comment Link WilliamVed Wednesday, 01 January 2020 20:05 posted by WilliamVed




    918indo_13102019
    ANSI
    RobertCom
    RobertComYR
    $aptK7k1y7K
    [email protected]
    GDLVDNU622
    [email protected]
    pop.gmail.com

    124456847
    Maputo
    Mozambique
    Service
    Cycling



    0













    áèçíåñ
    äîñóã
    îáúÿâ
    êóðèëêà
    ôëåéì
    ôëýéì
    îñíîâí
    ðàçâëå÷
    îôôòîïèê
    îôòîïèê
    îôô-òîïèê
    ïðî÷åå
    ðàçíîå
    îáî âñ¸ì
    flood
    flame
    stuff
    blah
    off-topic
    off topic
    offtopic
    oftopic
    general
    common
    business
    îáùà
    îáùèé
    îáùåå
    îáùèå
    ðåêëàì
    adver
    false

  • Comment Link WilliamVed Wednesday, 01 January 2020 16:48 posted by WilliamVed




    918indo_13102019
    ANSI
    RobertCom
    RobertComYR
    $aptK7k1y7K
    [email protected]
    GDLVDNU622
    [email protected]
    pop.gmail.com

    124456847
    Maputo
    Mozambique
    Service
    Cycling



    0













    áèçíåñ
    äîñóã
    îáúÿâ
    êóðèëêà
    ôëåéì
    ôëýéì
    îñíîâí
    ðàçâëå÷
    îôôòîïèê
    îôòîïèê
    îôô-òîïèê
    ïðî÷åå
    ðàçíîå
    îáî âñ¸ì
    flood
    flame
    stuff
    blah
    off-topic
    off topic
    offtopic
    oftopic
    general
    common
    business
    îáùà
    îáùèé
    îáùåå
    îáùèå
    ðåêëàì
    adver
    false

  • Comment Link Account-liz Monday, 30 December 2019 20:38 posted by Account-liz

    I'm selling Aged 2012 Twitter accounts with verified email address only for 4$

    All accounts come with full access to the original email that was used to create the account!
    FAQ.

    Are the accounts aged? Yes, 7 years old

    What are the accounts like? with followers, following, bio or profile picture, all with a luxury name & username

    Only for today. buy 2 get 1 account for free

    If you're interested Contact me via
    Email - [email protected] . com

    https://sellaccs.net

    Discord : CongMMO#9766
    Skype & Telegram : congmmo
    ICQ : @652720497
    Thank you!

Leave a comment

Back to Top