Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
2 views2 pages

Wifi Connected Code in Lab

This document contains an Arduino sketch that sets up a SoftwareSerial connection with an ESP8266 module. It defines the Wi-Fi access point name and password, and includes functions to send AT commands to the ESP8266 to connect to the Wi-Fi network. The main loop is empty, indicating that the program primarily focuses on establishing the connection during the setup phase.

Uploaded by

nitheesh2001k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Wifi Connected Code in Lab

This document contains an Arduino sketch that sets up a SoftwareSerial connection with an ESP8266 module. It defines the Wi-Fi access point name and password, and includes functions to send AT commands to the ESP8266 to connect to the Wi-Fi network. The main loop is empty, indicating that the program primarily focuses on establishing the connection during the setup phase.

Uploaded by

nitheesh2001k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <SoftwareSerial.

h>

#define RX 2
#define TX 3

String AP = "ABC"; // AP NAME


String PASS = "12345678"; // AP PASSWORD

SoftwareSerial esp8266(RX,TX);

int countTrueCommand;
int countTimeCommand;
boolean found = false;

void setup() {
Serial.begin(9600);
esp8266.begin(115200);
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
}

void loop()
{
}

void sendCommand(String command, int maxTime, char readReplay[]) {


Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while(countTimeCommand < (maxTime*1))
{
esp8266.println(command);//at+cipsend
if(esp8266.find(readReplay))//ok
{
found = true;
break;
}

countTimeCommand++;
}

if(found == true)
{
Serial.println("OYI");
countTrueCommand++;
countTimeCommand = 0;
}

if(found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}

found = false;
}

You might also like