void setup() {
Serial.begin(115200);
Serial2.begin(115200);
pinMode(AP_SWITCH, INPUT);
pinMode(con_led, OUTPUT);
pinMode(network_led, OUTPUT);
digitalWrite(con_led, HIGH);
digitalWrite(network_led, HIGH);
attachInterrupt(digitalPinToInterrupt(AP_SWITCH), handleInterrupt, FALLING);
wifiManager.autoConnect(AP_NAME,AP_PASSWORD);
client.setTimeout(5);
Serial.println("Connected");
}
void loop() {
// Use WiFiClient class to create TCP connections
if(ap_switch_flag == 1){
wifiManager.resetSettings();
wifiManager.autoConnect(AP_NAME,AP_PASSWORD);
ap_switch_flag = 0;
}
if(!client.connected()){
if (!client.connect(server, port)) {
Serial.print("dccqaec");
}
else {
digitalWrite(con_led, LOW);
}
} else {
send_serialdata_to_server();
send_serverdata_to_serial();
}
if ( (!client.connected())) {
slowBlink();
}
if ( (client.connected())) {
fastBlink();
}
if (!client.connected()) {
digitalWrite(con_led, HIGH);
}
}
Using this code i have connected the ESP withmy phones hotspot. It works fine. But when i turn off the mobile data, it is not able to detect the TCP disconnection. Also tried giving the timeout in setup.