Go Down

Topic: A few questions about connecting arduino to the internet via wifi using router (Read 3 times) previous topic - next topic


Yes, you will have an Internet connection, but then it  depends what you want to send or receive through the connection and if the connection will be initiated from the Arduino to the out to the internet, for example to post the data to a web site ( relatively easy) or if you want a web site to initiate a connection from the outside to your router (somewhat less easy).


It is not important to "Direct connection" as long as your project is running without problem. :)

If you had this sketch upload to your Arduino http://www.oceancontrols.com.au/KTA-223.html and you had the following file put in the /www/cgi-bin folder of router . Then you can control the Arduino with one line URL without knowing how it work.

Save the following file as luaSerial and save it to /www/cgi-bin directory of router & set its permission to 0755
Code: [Select]

-- LuaSerial interface
-- for Wireless Router Home Automation
-- by SM.Ching http://ediy.com.my
-- Put this file to /www/cgi-bin directory of router
-- use code below to allow 0755 permission for luaSerial file
-- chmod 0755 /www/cgi-bin/luaSerial
-- protocol (Receiving from serial port):
-- @aaccpp
-- where aa is the Arduino address ranged from 0 to 255 (0 means all Arduino)
-- where cc in the command (TG, ON, OF, RS)
-- where pp is the parameters or channel ranged from 0 to 8 (0 means all channes)
-- to toggle output for channel 1: @00TG1
-- to get status from all output: @00RS0
-- protocal (Sending to serial port):
-- #aapp
-- where aa is the Arduino address ranged from 0 to 255 (0 means all Arduino)
-- where pp is either 1 or 0 (ON or OFF for a channel), or ranged from 0(00000000) to 255(11111111) for all channels

port= "/dev/ttyUSB0"
serialout= io.open(port,"w")  --open serial port and prepare to write data
serialin= io.open(port,"r")   --open serial port and prepare to read data

function readSerial()
while true do
--serialData= nil
serialData= serialin:read();serialin:flush() -- read data from serial port

if string.len(serialData)>0 then
serData = serialData

if  string.len(serialData) == 0 then
return serData


function toggleOutput()
queryResult= readSerial() -- read data from serial port
queryResult= string.sub(queryResult,5)    -- from character 5 until the end, eg. 1 (is on)
      if queryResult== "1" then
str= address..cmd..parameter -- eg. @00of2 (including \r)


str= os.getenv("QUERY_STRING").."\r"   -- get message from URL and terminate with carriage return(\r), eg. @00on2
str= string.upper(str)
address= string.sub(str,1,3) -- get first 3 characters, eg. @00
cmd= string.sub(str,4,5) -- from character 4 until character 5, eg. on
parameter= string.sub(str,6)           -- from character 6 until the end, eg. 2 (including \r)
queryStr= address.."rs"..parameter -- eg. @00rs2

if cmd=="TG" then

serialout:write(str) -- write string(str) to serial port
readSerial() -- read data from serial port, use to clear serial buffer
serialout:write(queryStr) -- write string(queryStr) to serial port
print(readSerial()) -- read data from serial port and display it

use the following command to control Arduino:
Turn on all out

Turn on output 1

Turn off all output

Turn off output 1

Query Arduino (Get status)

Query first output

If you know HTML and Javascript, you can make a very nice web interface.

I had made a simple web interface to control the Arduino.

All the while I'm using Borland Delphi for my projects. I have no experience on HTML and Javascript, the code might be a bit messy :smiley-red:
Electronics and computer projects

Go Up