Hello,
I am using an esp8266 "ESPino(ESP-12 Module)" currently. I am trying to connect my microcontroller to a tcp server which I open using the Android App "TCP Server" from MightyIT. The connection gets established like I intended. However, each time I upload the sketch again, another connection is established with the same IP adress. The app now shows that there are multiple clients with the same IP adress. How can I preven this? Is there a way I can check if there is already a connecton established?
#include <ESP8266WiFi.h>
#define SendKey 0 //Button to send data Flash BTN on NodeMCU
int port = 3000; //Port number
const IPAddress serverA(10,39,1,144);
//Server connect to WiFi Network
WiFiClient client;
const char *ssid = "********"; //My wifi ssid
const char *password = "*******"; //My wifi password
WiFiServer server(port);
int count=0;
//=======================================================================
// Power on setup
//=======================================================================
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println();
//WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password); //Connect to wifi
// Wait for connection
Serial.println("Connecting to Wifi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println(port);
if( not client.connected()){
if(client.connect(serverA, port)){
Serial.println("Connected Successfully");
}else{
Serial.print("Ups there was a problem");
client.stop();
}
}else{
Serial.println("There is already a connection");
}
}
//=======================================================================
// Loop
//=======================================================================
void loop()
{
while(client.connected()){
Serial.println("Still connected");
}
}
