ESP8266WiFi WiFi.status()

After sending you the email below I decided to do some more investigation and print out the Actual value from WiFi.status().
Here is the result on the monitor

With password "password"
Attempting to start Station mode
................
7
HTTP server started

So the function returns a non-valid result of 7.
Which means what?

Hmm well that one is undefined really,
from 'wl_definitions.h'

typedef enum {
    WL_NO_SHIELD        = 255,   // for compatibility with WiFi Shield library
    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
} wl_status_t;

so we are still at the same 3 options. Please show me the full wiring diagram, and consider the possibility that the WiFi part of the ESP-01 is broken.

Have you tried uploading the sketch using 'generic ESP8285' already ?

Does the Access Point show up in the network list on your phone or PC ?

I am sure this is not a software issue.

1 Like

What wiring diagram?
The ESP01 is powered with 3.3v which is also connected to the RST, CH_PD pins.
RX/TX are unconnected.
The rest is software.
It is connecting up to a router which allocates a DHCP IP address and a PC on the same network uses the browser to log in to the 192.168.1.121 network which says connection refused or the AP ESP8266 created on the ESP-01.
The STA does not work producing the wrong connection code 7 which means you cannot proceed to get a local IP address to login to the AP through the browser on the existing network. You have to log off the internet (as using Wifi on the PC) and log into the WiFi connection ESP8266 which works for a minute or two and then drops out.
It displays the control screen. But I have still have to build another board to display the LED status.
But the status does not change on GPI02.

It is not a hardware problem as have tried it on several ESP01's and they all act the same.
ESP8285 has different parameters and will not compile for a ESP01.

I have changed the value that WiFiStatus() it is tested against to 7, and again it says IP address is not set.
Also typing "esp8266.local/" gets error connection refused.
It also throws out the previously working AP esp8266 and wont connect on 192.168.4.1

If RX & TX are unconnected, how are you uploading a sketch ? I need to see the actual wiring schematic, including the supply for the 3.3v and how you obtain that.

You have tested them how ? You see i can compile and upload the code i've posted, and it works (and i am not the only one !!) so that rules out any software issue unless there is an issue with the core you have installed and using (which core that is you have still not told me)

It will compile just fine, but it may not upload. Those are 2 different things.

Anyway the code works for both ESP8266 & ESP8285, since they are the same MCU, but with a different type of flash.

Ah so the AP was working ?? Seriously man, you should communicate what is working and what isn't ! If it is just the STA mode that fails, a power issue is the most likely culprit, but you just keep saying that you power it with 3.3v but how ?

Deva,
I have no problem compiling the program or uploading it onto the ESP01.
The power supply is via a external 3.3 regulator attached to the +5v supply of the UNO.
The UNO is suspended by having the RESET grounded all the time and thus I can use the TX and RX serial ports to program and monitor the responses on the arduino monitor screen inside the IDE.
The RX pin is protected by 1K in series and a 2K to GND as per usual.
I have given you all the info I have, the wrong response to WiFi.Status() and the fact that it seems to skip all the STA set up and only does the AP setup.
AND that drops out almost immediately.
The firmware is Firmware_bin_1.7.4.0 which I put at the top of this mailing.
It is the latest version.
I have also made sure that the latest version of the ESP8266WiFI library was downloaded via the board manager.

The firmware are AT-commands, once you upload a sketch those get overwritten.

By core i mean, when you go into the boards manager, you find 'esp8266' the version nr there.


I am on 2.4.2 I think the latest is 3.0.2 which is also OK (2.7.4 is also a known good core. From version 3 onwards some macros have changed, which may / can cause some issues) If you do decide to install a different version, make sure to remove the previous version completely to prevent the IDE from mixing core files up.

ESP8266WIFI is a core library, if you use a version that is not actually part of that core things may not quite work as expected. Remove the 'newer' version, and for good practice, un and re-install the core, to prevent mix ups from that end.

So once more about the firmware. There can only be 1 firmware on the flash of the ESP. Either the expressive one with AT-commands, or 'ours' the program we write in the Arduino IDE and then upload after compiling it with the ESP specific core. There is also an SDK on the chip, but we don't have to deal with that. There are some parts of the MCU that are simplified for the developers (of the core and of the at-command firmware) but these are all included in the datasheet for the ESP. This whole thing is below the hood. Don't bother about it.

Well that sounds good, i usually just load an empty sketch or blink or actually i upload the blink modulator (that is hared before but with pin 13) onto the UNO, but that is all fine.
You pull GPIO0 low and reset to put it in flash mode i guess. All good.

Yes you mentioned that, but then i asked "What kind ????" sorry i am carried away i asked for more specifics repeatedly. I know of at least a dozen 3.3v regulators, which means there must be hundreds of different types.
I started out with the most readily available LM1117 3.3v in a TO-220 package, but without at least a 1uF capacitor on the output it wouldn't work as expected. This is why i ask.. repeatedly... The status 7 thing even rings a bell somewhere, and since the error occurs with the WiFi connecting to STA, a power issue is the most likely since that is the moment when the ESP draws most of it's power (up to 300mA)
So.. Is there a capacitor on the 3.3v rail ? and what package (and type) regulator are you using.

I actually use the 3.3v from my UNO, but it's a genuine UNO and has a decent heatsink for the regulator on the PCB. Only very few of the clones do have sufficient heatsink and also drop out during WiFi connection.

So to repeat also once more, if it's not a power issue, you messed a bit with the builtin libraries of the core and it's better not to. That is a possible cause.

ESP is tough you know, there are many pitfalls and very few good tutorials. Best practice. Un-install the core (if you have more than one installed remove that as well, find the location on your HD, in win 10 it's somewhere in AppData), remove any other ESP specific libraries, and re-install the core of your choosing.

Results with external Power on.

Started Access Point "esp8266"
With password "password"
Attempting to start Station mode

Connected to wallydlink
IP address: (IP unset)
MDNS responder started, type esp8266.local/ in your browser

HTTP server started

with power on externally and usb power, 66ma from external

You have to drop off the internet as there is no response to IP address 192.168.1.121 allocated by DHCP on router.

You have to log onto to esp8266 on the WIFI and it displays menu.
As soon as you select an option such as "off" it crashes with "http://%28ip%20unset%29/?led=off"

Power readings 120ma normal operation from external power supply alone with ESP01+regulator and ARDUNIO Uno on RESET.
UNO takes 26ma normal running and 23ma on RESET (perm). Genuine UNO R3.
That leaves 70ma for ESP01+ regulator.
The regulator is a AMS1117-3.3 located 2 inches from the ESP01.
There is no capacitor on the Output.
Applying USB and its power, the external psu drops to 56ma total.
On operating GPI00 to GND the psu rises to 78ma.
On writing it takes from the psu 84ma.
So power does not seem to be a problem as the USB on its own can supply 500ma.

The problem appears to be software not setting the IP address required when the DHCP sends it.

Also there is no response to typing esp8266.local/ in your browser.

The only installed version of ESP8266WiFi.h is 3.1.1. in
C:\Users\stephen\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.1\libraries\ESP8266WiFi\src
ESP8266WiFi.h is dated December 2014
which came with the IDE.

I still think this is your issue. Without a heatsink the AMS1117 can only provide up to about 100mA (though with heatsink it is rated for 1A)

From the datasheet

'The circuit design used in the AMS1117 series requires the use of
an output capacitor as part of the device frequency compensation.
The addition of 22µF solid tantalum on the output will ensure
stability for all operating conditions. '

If you use a part that requires extra components to work properly, but you don't add them, you can not expect it to work properly.

Are not relevant, you will not be able to measure the requirements anyway.

That is just nonsense. But you seem to think that you are the only one using this software-core or no one else that has experienced this has reported it.

C:\Users\stephen\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.1

You have core 3.1.1 installed, i have no experience with it, but i seriously doubt there is something that significantly wrong with it.

Still you seem to know better, and so i guess we should leave it like this. With that kind of attitude, you will keep running into all sorts of issues. In life and ESPs and Arduinos.

I give up (on you) But i know one day you will fix the power issue and all of a sudden it will work.

From looking at Audrunio Project hub I cannot find any examples of a ESP01 using the ESP8266WIFI.h library.

[https://projecthub.arduino.cc/search?value=ESP01](https://Arduino Project Hub search)
11 projects listed, only one shows a ESP01 board without a Arduino controller,
ESP-01 Wireless QLab Trigger, but it des not list the code.

All the rest of the projects use a different library which is specifically not 8266 !

For the rest the code is loaded on to the Arduino to control the ESP01, it is not loaded on to the ESP01.

Only one project uses the 8266 processor on WIFI and that is using a Wemos D1 Mini
and a Raspberry Pi 3 Model B

So have you tested the code on a ESP01, as I have?

I reran the Webserver Project I loaded on to the Arduino project hub in 2019 and with one small change that it still works, with no errors using AT commands instead of a library. It was run on a Arduino Nano with a 168 processor over a hardware softwareserial port. So no code was loaded into the ESP01.

You scorned the tests that I have done to check your allegation that it is a power problem. I found that it does not draw not 300ma as you said, but a maximum of 120ma including the Arduino interface.

It is 80ma if you do not.

I also tried the code quoted for 8266 product and it did not work.
You re-wrote the code so it did something different, but it still failed to work.
I checked the code and found that it did not respond as you said, but it came back with a different result of 7 to the request for the WiFi.Status() command.
I also found another error that it does not respond with the IP address allocated on connection.
Both of these remain unexplained, but it stops the program dead in its tracks.

I have tried to answer your questions about the setup I am using to do the testing. The 3.3v regulator does have a heatsink and runs cool.
I have tried fitting a 22uf capacitor on the output of the regulator which you quoted from the datasheet, and it made absolutely no difference.
But you said you had fitted a 1uf capacitor instead on your setup?

I have made all the checks I can without going through the code in the library, as I am not learned enough to do this.

Which is why I posted the question in the forum in the first place.

Assuming there is not a problem because no one reported it, is not the correct answer, as many people with the same problem will go back to a solution that works, i.e. attach an Arduino to it! This does not use the library you quoted for the 8266, it uses libraries for the UNO or NANO, both of which I have tried.

Yes of course, many times in all sorts of variants. That is why i am so sure.

My setuo includes a 1uF capacitor on the 3.3v rail. The step-down is from 5v, just like with you.

All i can say is that what i posted works on an ESP-01, just they way i described it.
In fact i have many projects that serve a webpage on an ESP-01 as a UI for settings to control LED's in some way or another,
I have a few ESP8266's left, but when i buy batches of 50+, the ESP8285; are cheaper, and they just use a slightly different type of flash (same speed) something to do with the program counter i think, and they look the same.
All code works on any of these devices. I have a couple of nodeMCU's and a bunch of ESP-07's for a new project. The processor is the same on all, some have more flash, some even have a USB port and some have less pins exposed.
Unfortunately RAM is limited, and i have found the edge, but it has taken a significant time to fill those 80KB,

By now i have no idea what you are doing wrong, but you must be doing something wrong, cause it should work.

Solved:
without WEP switch the result is

Started Access Point "esp8266"
With password "password"
Attempting to start Station mode
................

HTTP server started

With undocumented WEP switch included

Started Access Point "esp8266"
With password "password"
Attempting to start Station mode
................

HTTP server started

Errors in Software code
Function prototypes missing which set up the server.on features
before setup() to deal with server.on commands

// i have a led connected to this active LOW
It should say LED contacted to +3.3v (Anode) and GPI02 (Cathode)

String webIP; defined but when used stops menu for working.

WiFi.enableInsecureWEP(); // Missing Setting to enable WEP missing
Not documented as change in 8266.com or arduino.cc

Leaving this out stops my WEP installation from connecting (Status 7 ?)

Closed as issue included #5364.
Check for WEP when setting authmode in #5364
The log reads
devyte merged 3 commits into esp8266:master from dav1901:issue5359 on Nov 22, 2018
devyte merged commit 5d57365 into esp8266:master on Nov 22, 2018

This documentation appears on 8266 tutorial
const char *password = "thereisnospoon"; // The password required to connect to it, leave blank for an open network
from

is quoted for Access Point mode, but does not work due to the bug above not discovered until 2018 when someone's code no longer works, despite the fact that he had made no changes.

Without this command only WPA/WPA2 protocol is accepted by Adruino ESP8266WiFi.h library

But not mentioned in

Copyright © 2013-2023 · RandomNerdTutorials.com · All Rights Reserved

The command
WiFi.begin(ssid, password, key)
in

does not work with ESP8266WiFi.h as it only accepts two parameters ,ssid and password and gives an error if third parameter is used.
The Last revision is 2018/08/23 by SM !!

Also this example of a Webserver on ardunio.cc


char ssid[] = "yourNetwork";      //  your network SSID (name)
char pass[] = "secretPassword";   // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)
 // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

LAST REVISION: 02/02/2023, 10:44

The only entry for WEP is on
https://arduino-esp8266.readthedocs.io
says

encryptionType
Return the encryption type of a network discovered during the scan.

WiFi.encryptionType(networkItem)
Function returns a number that encodes encryption type as follows: * 5 : ENC_TYPE_WEP - WEP * 2 : ENC_TYPE_TKIP - WPA / PSK * 4 : ENC_TYPE_CCMP - WPA2 / PSK * 7 : ENC_TYPE_NONE - open network * 8 : ENC_TYPE_AUTO - WPA / WPA2 / PSK

There is NO other function to set it or using WiFi.enableInsecureWEP() in these docs.

Software errors continued
The line after connected to is missing this

Serial.println(WiFi.SSID()); // Tell us what network we're connected to

instead it prints ssid variable.

webIP = StationIP();
collects IP address of connection, but cannot be used in menu!

WiFi.reconnect(); // reconnect AP after attempting to connect STA
if it is passed or failed it still reconnects??

server.on("/", handleRoot);
No explanation is to what server.on does and this is the vital component that reacts to what the server receives!

void loop() {
  server.handleClient();
  checkLedStatus();
}

There is no check that we are still connected?

void handleRoot()
Which sends the main menu page to user
if s += webIP; is included at beginning of each line is used Http://192.168.1.281 92.168.1.28 occurs at the begining of the line the web page in the browser, and it cannot handle it.
This is surplus as it relative address call and should start with "/".

So the final working code is

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
// #include <WiFiClient.h> // missing from original
const char *ssid = "myssid";
const char *password = "myloginpassword";
const char *apname = "esp8266";
const char *appass = "password"; // minimum length 8 characters

ESP8266WebServer server(80);
/* function prototypes missing here 
 */
const int ledpin = 2;  // I'm running this on an ESP-01
// i have a led connected to this active LOW
// should say LED contacted to +3.3v (Anode) and GPI02 (Cathode)
// i can't use the internal (pin 1) for the use of Serial

uint8_t ledstatus = 0; // this is keeping track of the state (of our statemachine)

const char   // like this these lines are statically declared and const, so we can't change them at all
*pageheader = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">",
 *htmlhead = "<html><head><title>ESPwebserver</title><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" ></head>",
  *bodystyle = "<body style=\"color: wheat; background-color: teal; font-size: 12pt; font-family: sans-serif;\">",
   *accessIP = "http://192.168.4.1",
    *htmlclose = "</body></html>";

String webIP;

void setup() {
  webIP.reserve(30);  // prevent fragments
  digitalWrite(ledpin, HIGH);
  pinMode(ledpin, OUTPUT);

  Serial.begin(115200);
   WiFi.enableInsecureWEP();
  /*
   *  WiFi.enableInsecureWEP(); // enable WEP missing
   */
  WiFi.softAP(apname, appass,6); // start AP mode
  webIP = accessIP;
  Serial.println();
  Serial.print("Started Access Point \"");
  Serial.print(apname);
  Serial.println("\"");
  Serial.print("With password \"");
  Serial.print(appass);
  Serial.println("\"");
  WiFi.begin(ssid, password,6);  // attempt starting STA mode  what does 6 stand for?
  Serial.println("Attempting to start Station mode");

  uint32_t moment = millis();
  while ((WiFi.status() != WL_CONNECTED) && (millis() < moment + 8000)) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("Connected to ");
    Serial.println(ssid);
    /* Missing   Serial.println(WiFi.SSID());              // Tell us what network we're connected to
   */
   Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
/* MDNS server does not work over WEP
*/
    if (MDNS.begin("esp8266")) {  // type esp8266.local/ in your browser
      Serial.println("MDNS responder started, type esp8266.local/ in your browser");
    }
    webIP = StationIP();
  }
  else if (WiFi.status() == WL_CONNECT_FAILED) {
    Serial.print("Connecting to ");
    Serial.print(ssid);
    Serial.println(" Unsuccessful.");
  }
  else if (WiFi.status() == WL_NO_SSID_AVAIL) {
    Serial.print("Network ");
    Serial.print(ssid);
    Serial.println(" not available.");
  }
  /* in wrong place as no connected ssid checked for content
   *
  WiFi.reconnect();   // reconnect AP after attempting to connect STA
 */
 Serial.println( );
  server.on("/", handleRoot);
  server.begin();
  Serial.println("HTTP server started");
}

void loop() {
  server.handleClient();
  checkLedStatus();
  // no check if still connected 
}


void checkLedStatus() {  // our statemachine
  switch (ledstatus) {
    case 0: {
        digitalWrite(ledpin, HIGH);
        return;
      }
    case 1: {
        digitalWrite(ledpin, LOW);
        return;
      }
    case 2: {
        if (ledBlink(500)) ; // here the return value (of ledBlink() ) gets discarded
        return;
      }
    case 3: {
        modulateLed();
        return;
      }
  }
}


void modulateLed() {
  static uint16_t ms = 100;
  static bool increase = true;

  if (!ledBlink(ms)) return;
  if (ms > 250) increase = false;
  if (ms < 20) increase = true;
  if (increase) ms = (ms * 10) / 9;
  else ms = (ms * 9) / 10;
}

bool ledBlink(uint32_t wait) {
  static bool pinstate = false;
  static uint32_t moment = millis();
  if (millis() > moment + wait) {
    pinstate = !pinstate;
    moment = millis();
    if (pinstate) digitalWrite(ledpin, LOW);
    else digitalWrite(ledpin, HIGH);
    return pinstate;  // if pinstate is true and the pinstate has changed, the modulator will change speed
  }
  return false;
}

void handleRoot() {
  String ledstatusupdate;
  if (server.hasArg("led")) {
    if (server.arg("led") == "off") {
      ledstatus = 0;
      ledstatusupdate = "The LED has been turned Off<br>";
    }
    else if (server.arg("led") == "on") {
      ledstatus = 1;
      ledstatusupdate = "The LED has been turned On<br>";
    }
    else if (server.arg("led") == "blink") {
      ledstatus = 2;
      ledstatusupdate = "The LED has been set to Blink<br>";
    }
    else if (server.arg("led") == "modulate") {
      ledstatus = 3;
      ledstatusupdate = "The LED has been set to Modulate<br>";
    }
  }

  String s = "";
  s += pageheader;
  s += htmlhead;
  s += bodystyle;

  s += "<h1>Welcome to ESP webserver</h1><p>From here you can control your LED making it blink or just turn on or off. ";
  s += "</p>";

  s += ledstatusupdate;
  s += "<br>";

  s += "<form action=\"";
  /* error webIP contains http://IPAddresss which is surplus as relative address call
  s += webIP; 
 */
  s += "\" method=\"get\" name=\"button\">";
  s += "<input type=\"hidden\" name=\"led\" value=\"on\">"; // the hidden parameter gets included
  s += "<input type=\"submit\" value=\" LED ON \"></form><br>"; // the button simply submits the form

  s += "<form action=\"";
  /* error webIP contains http://IPAddresss which is surplus as relative address call
  s += webIP; 
 */ s += "\" method=\"get\" name=\"button\">";
  s += "<input type=\"hidden\" name=\"led\" value=\"off\">";
  s += "<input type=\"submit\" value=\" LED OFF\"></form><br>";

  s += "<form action=\"";
  /* error webIP contains http://IPAddresss which is surplus as relative address call
  s += webIP; 
 */  s += "\" method=\"get\" name=\"button\">";
  s += "<input type=\"hidden\" name=\"led\" value=\"blink\">";
  s += "<input type=\"submit\" value=\"  BLINK  \"></form><br>";

  s += "<form action=\"";
  /* error webIP contains http://IPAddresss which is surplus as relative address call
  s += webIP; 
 */ s += "\" method=\"get\" name=\"button\">";
  s += "<input type=\"hidden\" name=\"led\" value=\"modulate\">";
  s += "<input type=\"submit\" value=\"MODULATE\"></form><br>";

  s += htmlclose;
  yield();  // not stricktly neccesary, though the String class can be slow
  server.send(200, "text/html", s); //Send web page
}

/* void handleRoot() Missing
 */
String StationIP() {
  String stationIP = "http://";
  stationIP += WiFi.localIP().toString();
  return stationIP;
}

That is the same. Active LOW means that current start to flow when the GPIO pin goes LOW, for that obviously the other side should be connected to 3.3v (also i am sure i stated somewhere that if GPIO2 is pulled LOW at boot, the wrong boot mode will be selected, and using the builtin LED is not possible icw using the UART since it is on the TX pin.

  /*
   *  WiFi.enableInsecureWEP(); // enable WEP missing
   */

This must be a bug with the later core versions.

Version 3.x.x is know to have changes to version 2 that are extensions, but lack backwards compatibility, and are insufficiently documented. Mind you, i am confident that my code also worked on 3.0.2

I am happy you got it sorted and i hope i have been of some assistance in clarifying what may or may not be working and what is what.

In the end "Great !! success !!"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.