/*
Basic AT Commands - Check Mode
Use the serial monitor to interface with the AT commands!
https://www.instructables.com/Getting-Started-With-the-ESP8266-ESP-01/
https://www.pridopia.co.uk/pi-doc/ESP8266ATCommandsSet.pdf
If you want to check what mode your Wi-Fi module is in,
you can simply type the following command:
> AT+CWMODE?
This will display a number (1, 2, or 3) associated with
the corresponding mode of operation.
Once we have the ESP-01 operating in STA mode,
we need to connect to a Wi-Fi network.
First we can check if we are already connected to one by sending the command:
> AT+CIFSR
This will display the station IP address of our ESP-01 module.
If you don’t get an IP address after entering the previous command,
use the following command to connect to your network:
> AT+CWJAP="Wokwi-GUEST",""
Type the name of your Wi-Fi network and the password to connect to it.
Make sure you include the quotation marks.
After a couple of seconds, you should get an "OK" response.
You can check again to see if you have an IP address using the AT+CIFSR command.
Then we need to enable multiple connections before we can configure the ESP8266 ESP-01 module as a server. Type the next command:
> AT+CIPMUX=1
Once again, each number is associated with a type of connection:
Single = 0
Multiple = 1
The following step is to start the server at port 80:
> AT+CIPSERVER=1,80
The first number is used to indicate whether we want
to close server mode (0), or open server mode (1).
The second number indicates the port that the client uses to connect to a server.
We chose port 80 because this is the default port for HTTP protocol.
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}# Wokwi Library List
# See https://docs.wokwi.com/guides/libraries
AsyncTCP@wokwi:4f5e87acf004319cc1b2dcc4e55baf920b6d6892
ESPAsyncWebServer@wokwi:0cf09b5c148feb04914900f951648cdb15acd49b
ESP-DASH@wokwi:d9fa2c4727d9e43d0db0099622bbe489c07c3b2d
ArduinoJson
OneWire
DallasTemperature
RCSwitch
esp8266_mdns
/*
# Wokwi Library List
# See https://docs.wokwi.com/guides/libraries
AsyncTCP@wokwi:4f5e87acf004319cc1b2dcc4e55baf920b6d6892
ESPAsyncWebServer@wokwi:0cf09b5c148feb04914900f951648cdb15acd49b
ESP-DASH@wokwi:d9fa2c4727d9e43d0db0099622bbe489c07c3b2d
ArduinoJson
OneWire
DallasTemperature
RCSwitch
esp8266_mdns
# Wokwi Library List
# See https://docs.wokwi.com/guides/libraries
AsyncTCP@wokwi:4f5e87acf004319cc1b2dcc4e55baf920b6d6892
ESPAsyncWebServer@wokwi:0cf09b5c148feb04914900f951648cdb15acd49b
ESP-DASH@wokwi:d9fa2c4727d9e43d0db0099622bbe489c07c3b2d
ArduinoJson
OneWire
DallasTemperature
RCSwitch
esp8266_mdns
*/
#include <WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
MDNSResponder mdns;
// Replace with your network credentials
const char* ssid = "Wokwi-GUEST";
const char* password = "";
ESP8266WebServer server(80);
// Replace with your remote TriState values
char* socket1TriStateOn = "0FFF0FFFFFFF";
char* socket1TriStateOff = "0FFF0FFFFFF0";
char* socket2TriStateOn = "0FFFFF0FFFFF";
char* socket2TriStateOff = "0FFFFF0FFFF0";
String webPage = "";
void setup(void){
webPage += "<h1>ESP8266 Web Server</h1><p>Socket #1 <a href=\"socket1On\"><button>ON</button></a> <a href=\"socket1Off\"><button>OFF</button></a></p>";
webPage += "<p>Socket #2 <a href=\"socket2On\"><button>ON</button></a> <a href=\"socket2Off\"><button>OFF</button></a></p>";
mySwitch.enableTransmit(2);
delay(1000);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (mdns.begin("esp8266", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
server.on("/", [](){
server.send(200, "text/html", webPage);
});
server.on("/socket1On", [](){
server.send(200, "text/html", webPage);
mySwitch.sendTriState(socket1TriStateOn);
delay(1000);
});
server.on("/socket1Off", [](){
server.send(200, "text/html", webPage);
mySwitch.sendTriState(socket1TriStateOff);
delay(1000);
});
server.on("/socket2On", [](){
server.send(200, "text/html", webPage);
mySwitch.sendTriState(socket2TriStateOn);
delay(1000);
});
server.on("/socket2Off", [](){
server.send(200, "text/html", webPage);
mySwitch.sendTriState(socket2TriStateOff);
delay(1000);
});
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
} Loading
esp-01
esp-01