A few questions about connecting arduino to the internet via wifi using router

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

If you had this sketch upload to your Arduino Electronics & Automation Engineering T/A Ocean Controls > PC Based > Relayduino USB/RS-485 IO Module (8-28VDC) 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

#!/usr/bin/lua

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

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

	end
end

function toggleOutput()
	serialout:write(queryStr)
	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
  		cmd="of"
	else
		cmd="on"
	end
	str= address..cmd..parameter					-- eg. @00of2 (including \r)
end

----------------------------------------------------------------

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
  toggleOutput()
end

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
http://192.168.1.1/cgi-bin/luaSerial?@00on0

Turn on output 1
http://192.168.1.1/cgi-bin/luaSerial?@00on1

Turn off all output
http://192.168.1.1/cgi-bin/luaSerial?@00of0

Turn off output 1
http://192.168.1.1/cgi-bin/luaSerial?@00of1

Query Arduino (Get status)
http://192.168.1.1/cgi-bin/luaSerial?@00RS0

Query first output
http://192.168.1.1/cgi-bin/luaSerial?@00RS1

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.
http://arduino.cc/forum/index.php/topic,127175.0.html

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