Code Ino
Code Ino
#include <SoftwareSerial.h>
#define WIFI_SSID "#####" //WIFI SSID
#define WIFI_PASS "********" // Wifi Password
#define SERVER_IP "192.168.0.1" // IP of the target server.
#define TIMEOUT 5000 //Timeout for the serial communication
#define CONTINUE false
#define HALT true
#define NO_OF_PARAMETERS 1 //No of parameters sending to the server.
boolean initializeESP8266Module(){
esp8266SerialPort.begin(9600);
esp8266SerialPort.setTimeout(TIMEOUT);
delay(2000);
String cmd = "AT+CWJAP=\""; cmd += WIFI_SSID; cmd += "\",\""; cmd += WIFI_PASS; cmd += "\"";
for(int counter=0;counter<5;counter++){
if (sendCommand(cmd, "OK", CONTINUE)){ // Join Access Point
Serial.println("Connected to WiFi.");
break;
}else if(counter==4)
exception("Connection to Wi-Fi failed. Please Check");
}
delay(5000);
1 of 2 26/03/2023, 20:37
Firefox https://raw.githubusercontent.com/oksbwn/Arduino-ESP8266-AT-Co...
void setup()
{
Serial.begin(9600);
Serial.println("ESP8266 Demo");
initializeESP8266Module();
Serial.println("Module is ready.");
}
void loop()
{
String cmd = "AT+CIPSTART=0,\"TCP\",\""; cmd += SERVER_IP; cmd += "\",80"; //Start a TCP
connection. to server SERVER_IP on port 80
if (!sendCommand(cmd, "OK", CONTINUE))
return;
delay(2000);
2 of 2 26/03/2023, 20:37