This project gives details about the ability of the ESP8266 is not only limited to connecting to a WiFi network and exchange data to the internet, but it can also set up a network of its own by creating an Access Point and allowing other devices to connect to it. This example demonstrates how to turn the ESP8266 into an access point (AP) in two different ways, one is using LUA scripting and other is with the Arduino IDE and serve up web pages to any connected client.
It is assumed that you have gone through “Getting started with ESP8266” if you are new to this. First, we will discuss about how to achieve this using LUA Scripting for this refer ESP8266 should be Flashed with the NodeMCU and refer Getting Started with the ESPlorer IDE, then we will discuss about how to achieve the same using Arduino IDE for this refer ESP8266 programming with the Arduino IDE.
Circuit Connection:
Here we are using USB to TTL converter for connecting the Module with the PC. The 3.3V output of the converter is used to power the module.
The connection details are as below:
ESP8266 |
USB-TTL
|
VCC |
3.3v |
GND |
GND |
TX |
RX |
RX |
TX |
CH_PD |
Connected to 3.3v to enable chip firmware boot |
Don’t forget to pull up CH_PD HIGH, you won’t get a response from the module if it is not done.
You can also use Arduino UNO by uploading empty setup() and loop() functions, if you don’t have a USB-TTL converter.
The connection details are as below:
WIFI Module |
Arduino UNO
|
Vcc |
3.3v |
Gnd |
Gnd |
TX |
TX |
RX |
RX |
CH_PD |
Connected to 3.3v to enable chip firmware boot |
For viewing the data from the ESP8266 a serial terminal in Arduino IDE can be used.
Writing Server Script in LUA:
This code given below will configure the ESP to act as an Access Point and it has its own SSID=”test” and Password=”password” and also act as the server which will continuously listen for a connection.
print(“ESP8266 Server”)
wifi.setmode(wifi.STATIONAP);
wifi.ap.config({ssid=”test”,pwd=”password”});
print(“Server IP Address:”,wifi.ap.getip())
sv = net.createServer(net.TCP)
sv:listen(80, function(conn)
conn:on(“receive”, function(conn, receivedData)
print(“Received Data: ” .. receivedData)
end)
conn:on(“sent”, function(conn)
collectgarbage()
end)
end)
This will create a WiFi Access point named “test” which can be seen through any client devices.
Creating server using Arduino IDE:
The below Arduino code will also create a server and Access Point in ESP8266 which will continuously listen for a connection.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char *ssid = “test”;
const char *password = “password”;
ESP8266WebServer server(80);
void handleRoot() {
server.send(200, “text/html”, “<h1>You are connected</h1>”);
}
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print(“Configuring access point…”);
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print(“AP IP address: “);
Serial.println(myIP);
server.on(“/”, handleRoot);
server.begin();
Serial.println(“HTTP server started”);
}
void loop() {
server.handleClient();
}
After uploading this sketch, you can find a new Access Point named “test” from your Laptop or PC.
Filed Under: Featured Contributions
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.