-->
Page 1 of 1

ESP8266-01 WiFi Relay - STA and AP mode problem

PostPosted: Tue Dec 26, 2017 2:26 pm
by dinorex
Hi, I try to run this simple code on ESP-01 but I can not connect to any access point.

Code: Select all#include <ESP8266WiFi.h>

IPAddress myIP;

const char *sid = "Mysid";
const char *pass = "Mypass";

void setup()
{
  delay(100);
  Serial.begin(9600);
  Serial.println("Hello");

  WiFi.persistent(false);
  WiFi.mode(WIFI_OFF);
  WiFi.mode(WIFI_STA);
  WiFi.begin(sid, pass);
  delay(100);
}

void loop() {
  int i, i_prev;

  if (WiFi.status() != WL_CONNECTED) {
    Serial.print("Connecting to sid: "); Serial.println(sid);
    Serial.print("Password: "); Serial.println(pass);
    while (WiFi.status() != WL_CONNECTED) {
      Serial.print(WiFi.status()); Serial.print("|");
      delay(500);
      /*
        WL_IDLE_STATUS      = 0,
        WL_NO_SSID_AVAIL    = 1,
        WL_SCAN_COMPLETED   = 2,
        WL_CONNECTED        = 3,
        WL_CONNECT_FAILED   = 4,
        WL_CONNECTION_LOST  = 5,
        WL_DISCONNECTED     = 6
      */
    }
   
    //Print the IP address
    myIP = WiFi.localIP();
    Serial.print("IP address: "); Serial.println(myIP);
  }

  i = WiFi.softAPgetStationNum();
  if (i_prev != i) Serial.printf("Stations connected=%d\r\n", i);
  i_prev = i;
 
  delayMicroseconds(100);
}


I got the output like:
Code: Select allHello
Connecting to sid: Mysid
Password: Mypass
6|6|6|6|6|6|6|6|6|6|6|6|6|1|1|1|1|1|6|6|6|6|6|6|6|6|6|6|6|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|6|6|6|6|6|6|6|6|6|6|6|6|6|1|1|1|1|6|6|6|6|6|6|6|6|6|6|6|1|1|1|1|6|6|6|6|6|6|6|6|6|6|6|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|6|6|6|6|6|6|6|6|6|6|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|6|6|6|6|6|6|6|6|6|6|66|6|1|1|1|1|1|1|1|1|1|..........


I tried many ways of doing it. I can not setup STA mode nor AP mode like the whole ESP's Wifi module was broken or stop working. When I setup AP mode, then when I try to connect to it I got connecting -> enter password -> disconnected.

I am sure that this module worked once, but after another firmware update it stopped working. I'm not sure if I should clear flash, but I tried WIFI_OFF, ESP.eraseConfig(); ESP.restart ESP.reset() etc.

This is my setup. I use Arduino IDE but I installed also Espressif libraries:
2017-12-26 20_10_38-WiFi_AP_v1 _ Arduino 1.8.5.png

2017-12-26 20_11_54-Menedżer płytek.png


I use this code to enable AP mode. It starts AP, setup the IP but I can not connect to it.

Code: Select allWiFi.disconnect();
    //WiFi.softAPdisconnect(true);
    //WiFi.mode(WIFI_OFF);
    delay(1000);
    WiFi.mode(WIFI_AP);
    delay(100);
   
    bool ok1 = false;
    bool ok2 = false;
   
    Serial.print("Starting Access Point...");
   
    while ((ok1==false) || (ok2==false)) {
      ok1 = ok2 = false;
      ok1 = WiFi.softAPConfig(local_IP, gateway, subnet);
      //if (ok1) ok2 = WiFi.softAP(AP_SID, AP_PASS, 7);   //<- try different channel
      if (ok1) ok2 = WiFi.softAP(AP_SID);
      delay(100);
    }
   
    Serial.println("OK");
    myIP = WiFi.softAPIP();
    Serial.print("Address: http://"); Serial.println(myIP);
    Serial.print("SID: "); Serial.println(AP_SID);
    Serial.print("PASS: "); Serial.println(AP_PASS);