#include <SoftwareSerial.h>
#define DEBUG true
int connectionId;
SoftwareSerial esp32(7, 6);
String espmode = "3";
String SSid = "BSJ";//enter ur SSID (service set ID) here
String password = "batool0005"; //password
void wifisetup(String mode, String ssid, String pass);
void st_server(String HI, String Data, String HIcolor);
void setup() {
pinMode(12, OUTPUT);
Serial.begin(9600);
esp32.begin(9600);
digitalWrite(10, LOW);
delay(1000);
wifisetup(espmode, SSid, password);
delay(1000);
digitalWrite(10, HIGH);
}
String heading = "Internet of Things";
String color = "blue";
String dataSend = "hello world";
void loop() {
digitalWrite(10, LOW);
delay(1000);
st_server(heading, dataSend, color);
delay(1000);
digitalWrite(10, HIGH);
}
//functions
//1 - send data
String sendData(String command, const int timeout, boolean debug){
String response = "";
esp32.print(command);
long int time = millis();
while((time + timeout) > millis()){
while(esp32.available()){
char c = esp32.read();
response += c;
}
}
if(debug){
Serial.print(response);
}
return response;
}
//2 - connectivity
void wifisetup(String mode, String ssid, String pass){
sendData("AT\r\n", 2000, debug);//reset
String mode0 = "AT+CWMODE= ";
mode0 += mode;
mode0 += "\r\n";
sendData(mode0, 2000, debug);
String ssidset = "AT+CWJAP=\ ";
ssidset += ssid;
ssidset +="\","\";
ssidset += pass;
ssidset += "\";
ssidset +="\r\n";
sendData(ssid, 10000, debug);
delay(900);
sendData("AT+CIFSR \r\n", 4000, debug);
sendData("AT+CIPMUX=I \r\n", 2000, debug);
sendData("AT+CIPSERVER=I,80 \r\n", 2000, debug);
sendData("AT+CIPSTO=1000 \r\n", 1000, debug);
return;
}