Go Down

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


Greetings! I am new with arduino so firstly I will explain what am I trying to achieve and then ask you some questions about it.

I want to make a simple weather "station" which prints the temperature and humidity on a web page.

I've read that this can be done with the Arduino Ethernet Shield and the Ethernet Library. Great, but I will place it outside the house so I want it to connect to my wifi network and do the exactly same thing. I've seen and read about the wifi shields but they are quite expensive. After reading for hours I found some articles that explain how cheap routers can be hacked with dd-wrt and used as clients (bridge mode) to connect to the main wifi network. There is one thing that I didn't understand - is this only to controll remotely the arduino or arduino can access internet (and ethernet library can be used) ? (link to the article)

Another method I found is this. I think that this is better than the one i explained above. It uses an ethernet shield and a cheap router which offers bridge mode. A lan cable is connected to the ethernet shield and the router and according to the article the arduino can access the internet.

So my question is - has anybody tried one of these methods and which one do you recommend me to use? Are there any other cheap methods? Do you have any suggestions about them?

Excuse me if there are any mistakes but I am not a native speaker.


The below uses a inexpensive router, arduino, and ethernet shield. Will you have power available at the weather station?

Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


As long as your wireless router support OpenWRT then you can eliminate the use of Ethernet shield and Wifi shield. Plug your Arduino to the USB port of wireless router & coding with HTLM+Javascript+Lua, or HTML+Javascript+PHP
Electronics and computer projects


True, you could eliminate the WiFi and Ethernet shield this way, howevr, you'd obviously loose all compatibility to the Ethernet shiled library.

Depending on yopur projects requirements you may end up having to write a lot of code that otherwise is provided in form of the Ethenet library and a host of other libraries that depend on the Ethenet library.

But, yes, connecting a cheap router that preferably runs on 5V USB power is a safe bet. I use that approah in two projects with more coming up. I use a TP-Link TL-WR703n, TP-Link TL-WR702n and the TP-Link TL-WR703n and the 3020 should also work witout problems.

The 703 uses 100mA in WiFi mode.



There is no point to use ethernet shield library if a wireless router is being used in the project.
I think using HTML & javascript is much more easy than using ethernet shield library since most of the people already learn HTML and javascript.
I will post my project which only install a serial library for the FDTI USB2Serial without installing additional OpenWRT packages. The project will control & query the Arduino output.
Electronics and computer projects


There is a point, actually several points to use an Ethernet shield.

If you are using existing libraries that rely on the Ethernet library, e.g, ArdOSC or DHCP/Bonjour you save yourself a lot of time coding things that are already coded. Good luck trying to code that functionality in HTML & javascript ;-)

I understand that the motivations of people for engaging in Arduino projects is different. Perhaps if you consider it a learnig experience and time for coding is not a problem, in that case elimiating the Ethernet card and library and associated functionality a a valid approach.

However, if one intends to get a project on their feet quickly and has a specific functionality in mind, then spending $30 on a little extra hardware is not an issue.



I agree that in certain use cases the Ethernet card is a bit superflous, but if you start that argument you may as well replace the whole Arduino, again depending on what you do and what your embedded coding skills are.

The TL WR703n hosts a 300Mhz Atheros processor (Arduino 16Mhz) with 32MB dram (Arduino MEGA 128kb). It has some GPIO and OpenWRT is an embedded Linux box.  8)



You are right. If a project really require ethernet/wifi library then you must go with ethernet/wifi shield. Otherwise OpenWRT+wireless router is the best choice.
Electronics and computer projects


I'm releasing the Wireless Router Home Automation source code, it is available from my website:

I'm still preparing the documentation. This is going to take me sometime to complete the documentation since I'm Chinese educated.
Meanwhile you can studying the source code, it is well commented.
Electronics and computer projects


Thank you guys for all the answers.

@zoomkat - Yes, I'll have power.

I personally think that using an ethernet shield is better because i can use the ethernet library which is very nice and easy to understand.
I don't like connecting arduino to the serial port of a router because basically it doesn't have a "direct connection" to the internet. (correct me if I am wrong) This means that there must be sth that constantly controlls the data from the router to the arduino and from the arduino to the router. (much complicated) Although it is the cheapest method I don't really like to try it because I am a beginner with arduino :D.

I am planning to collect the data from the arduino web server page with a VPS with a php cron job and store it in a MySQL database, so that I can play with it in web or software apps.

Final question: Will my arduino have internet access if I put TP-Link TL-WR702N in bridge mode with my home wi-fi network, and simply connect it with the ethernet shield with a lan cable?

I have some other questions but they are not related to networking so I'll open another thread.


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