 
 // Try to connect Wi-Fi
 bool connectSTA(const char* ssid, const char* password, byte bssid[6]) {
+  
+  WiFi.disconnect(true);
   WiFi.mode(WIFI_STA);
+
   // First connect to a wi-fi network
   WiFi.begin(ssid, password, 0, bssid);
+
   // Inform user we are trying to connect
   Serial.print(F("[ INFO ] Trying to connect WiFi: "));
   Serial.print(ssid);

  setupRFID(rfidss, rfidgain);
  const char * l_hostname = json["hostnm"];

  if (our_hostname != 0)
    free(our_hostname);
  our_hostname = (char*) malloc(sizeof(l_hostname));
  strcpy(our_hostname, l_hostname);

  const char * bssidmac = json["bssid"];
  byte bssid[6];
  parseBytes(bssidmac, ':', bssid, 6, 16);

  // Set Hostname.
  WiFi.hostname(our_hostname);

  // Start mDNS service so we can connect to http://esp-rfid.local (if Bonjour installed on Windows or Avahi on Linux)
  if (!MDNS.begin(our_hostname)) {
    Serial.println("Error setting up MDNS responder!");
  }
  // Add Web Server service to mDNS

bool activateRelay = false;
bool inAPMode = false;
bool isWifiConnected = false;
int autoRestartIntervalSeconds = 0;

bool wifiDisabled = true;
bool doDisableWifi = false;
bool doEnableWifi = false;
int wifiTimeout = -1;
unsigned long wiFiUptimeMillis = 0;
char * deviceHostname = 0;

int relayPin;
int relayType;
