Menu Close

ESP8266 Connecting to Internet

Robo India presents tutorial on connecting ESP8266 wifi module to internet. 

1. Introduction:

This tutorial explain how to connect to internet using ESP8266 wifi module by LUA Programming.

1.1 Prerequisites:

1.1.1 Basics of ESPlorer and ESP8266This tutorial explains basic of ESPlorer.

Connect RX and TX pins of ESP8266 module to the Serial Port of you computer, if you don’t have one in your computer, FTDI or CP2102 can be used.

3. LUA Programme:

The following  LUA code will be required to connect ESP8266 wifi module to internet. Download this init.lua file. Open it and write your Wifi Access Point Name and security key in it. Save this file and upload the same to your ESP8266 wifi module.

You may download init.lua file from here.

wifi.setmode(wifi.STATION)
wifi.sta.config("AP_NAME","SECURITY_KEY") -- Replace with your AP Name and security key.
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
print("Obtaining IP...")
else
tmr.stop(1)
print("Got IP. "..wifi.sta.getip())
end
end)

4.  Explaining programme:

This code is written in init.lua so as your ESP8266 wifi module starts up this code will be executed. In this code the ESP8266 is working in station mode. It connects to the wireless access point provided by you. The we have created a timer of one second duration that timer is to obtain IP address. This timer runs till it get IP address. Once the ESP8266 module obtains IP address the timer stops. Obtaining IP address means that your ESP8266 has been connected to the Access Point Provided by you. If the access point has got access to internet your ESP8266 is connected to internet.

If you have any query please write us at info@roboindia.com

our whatsapp helpline:  +91 9694011188

Thanks and Regards
Content Development Team 
Robo India
http://roboindia.com


Leave a Reply