
const char* ssid = "ASUS SW2";
const char* password = "q1w2e3r4t5";


String transmitir(String parametro) {


  if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
    String urlpar = url + parametro;
    HTTPClient http;
    Serial.println("urlpar=" + urlpar);
    //  http.begin("http://unicarlos.com/2018/domotica/pdo/General/tablas.php"); //Specify the URL
    //http.begin("http://unicarlos.com/2018/domotica/pdo/Arduino/guardarEntrada.php?escena=Escena1&entrada=ds131");
    http.begin(urlpar);
    int httpCode = http.GET();                                        //Make the request

    if (httpCode > 0) { //Check for the returning code

      trama = http.getString();
      Serial.println("httpCode=" + String(httpCode));
      Serial.println("trama=" + trama);

      http.end(); //Free the resources
      return trama;
    }

    else {
      Serial.println("Error on HTTP request");
    }

    http.end(); //Free the resources
  }
  return "";
}


String translateEncryptionType(wifi_auth_mode_t encryptionType) {

  switch (encryptionType) {
    case (WIFI_AUTH_OPEN):
      return "Open";
    case (WIFI_AUTH_WEP):
      return "WEP";
    case (WIFI_AUTH_WPA_PSK):
      return "WPA_PSK";
    case (WIFI_AUTH_WPA2_PSK):
      return "WPA2_PSK";
    case (WIFI_AUTH_WPA_WPA2_PSK):
      return "WPA_WPA2_PSK";
    case (WIFI_AUTH_WPA2_ENTERPRISE):
      return "WPA2_ENTERPRISE";
  }
}

void scanNetworks() {

  int numberOfNetworks = WiFi.scanNetworks();

  Serial.print("Number of networks found: ");
  Serial.println(numberOfNetworks);

  for (int i = 0; i < numberOfNetworks; i++) {

    Serial.print("Network name: ");
    Serial.println(WiFi.SSID(i));

    Serial.print("Signal strength: ");
    Serial.println(WiFi.RSSI(i));

    Serial.print("MAC address: ");
    Serial.println(WiFi.BSSIDstr(i));

    Serial.print("Encryption type: ");
    String encryptionTypeDescription = translateEncryptionType(WiFi.encryptionType(i));
    Serial.println(encryptionTypeDescription);
    Serial.println("-----------------------");

  }
}

void connectToNetwork() {
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Estableciendo conexion a la WiFi..");
  }

  Serial.println("Conectado a la red WiFi");

}
