WIFIO is a dual Arduino WIFI module (ESP8266+ATMEGA328P) FCC approve-able with transferable licence. Can use the 328P for I/O expansion also...

Moderator: igrr

User avatar
By LEP70
#88162 Hello, I'm a beginner with ESP8266 and I would like to connect a NodeMcu (with an ESP8266) to a WiFi network using an WEP Key.
I found a sketch example to command a LED using a webserver (https://michel.re/esp8266/)

Code: Select all////////////////////////////////////////////////////////////////
// Programme simple de webserver
////////////////////////////////////////////////////////////////
#include <ESP8266WiFi.h>
const char* ssid = "Your ssid";
const char* password = "Your password";
int ledPin = 13;
// ATTENTION GPIO13 correspond à la PIN 07
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);
   pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.println(WiFi.localIP());
}
 
void loop() {
  // Control de la connection client
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Attente de l'envoi de quelque chose du client
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Première ligne de la requête
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Lecture-préparation réponse de la requête
  int value = LOW;
  if (request.indexOf("/LED=ON") != -1)  {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED=OFF") != -1)  {
    digitalWrite(ledPin, LOW);
    value = LOW;
  }
 
  // Réponse à la requête
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("");
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
  client.println("<head>");
  client.println("</head>");
  client.println("<body>");
  client.println("<div style=\"text-align:center\">");
  client.println("<h1>TEST WIFI SERVEUR</h1><br><br>");
  client.print("Led pin is now: ");
  if(value == HIGH) {
    client.print("On");
  } else {
    client.print("Off");
  }
  client.println("<br><br>");
  client.println("<a href=\"/LED=ON\"\"><button style=\"height: 50px; width: 100px\"> ON </button></a>");
  client.println("<a href=\"/LED=OFF\"\"><button style=\"height: 50px; width: 100px\"> OFF </button></a><br />");
  client.println("</body>");
  client.println("</html>");
 
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
 
}


The sketch works fine with a WPA network, but don't with a WEP network : the Serial Monitor prints only ....... and never connects to the network.
Any ideas to fix this problem ?

Thanks.
User avatar
By Ben123
#88528 Hey,

you might have figured it out in the mean time, but if not: You need to enable WEP support explicitely first (as it's considered insecure and outdated by now – try not to use it unless you really have to!). To do so, you have to call

Code: Select all  WiFi.enableInsecureWEP();


before using
Code: Select allWiFi.mode
/
Code: Select allWiFi.begin
. Took myself a while to figure out, but works for me!

Best,
Ben