Unable to connect Wemos Mini (ESP8266) to WiFi

Hi,

I provided api key, ssid and password. The code compiles and uploads successfully to Wemos Mini (ESP8266). However, when I view output using serial monitor, it goes into an infinite loop which displays text below:

Attempting to connect to WPA SSID: xyz
Status = 1

I am new to this programming environment, so it will be great if you could provide some clarification of what I am doing wrong.

Thanks

Below is my code:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WifiLocation.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <SoftwareSerial.h>

/////////////////////////////// Settings /////////////////////////////////////////////

const char* googleApiKey = ""; // Your google geolocation api key
const char* ssid = ""; // Your Wifi SSID
const char* passwd = ""; // Your Wifi Password
const float timeZone = 8;

///////////////////////////////////////////////////////////////////////////////////////
#define sensorPin A0
//SoftwareSerial MyBlue(2, 3); // RX | TX
// Define Trig and Echo pin:
//#define trigPin 2
//#define echoPin 3
// Define variables:
unsigned long lastTime;
float distance;
boolean low, high, startup = true;
unsigned char alert = 0, event = 0;
String csv;

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");

WifiLocation location(googleApiKey);
location_t loc;

void setup() {
Serial.begin(9600);
Serial1.begin(9600);

Serial.println("Water Level Detector Started...");

// Connect to WPA/WPA2 network
WiFi.mode(WIFI_STA);

WiFi.begin(ssid, passwd);
while (WiFi.status() != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// wait 5 seconds for connection:
Serial.print("Status = ");
Serial.println(WiFi.status());
delay(500);
}

timeClient.begin();
timeClient.setTimeOffset(timeZone*3600);

pinMode(sensorPin, INPUT);

} 

if this is your first try to connect the Wemos to your Wifi I recommend:

start with an example delivered with the IDE.
If you want to see some NTP action, take the example

ESP8266 / NTP-TZ-DST

a) that IDE example MUST work
b) the IDE example is the right procedure to do NTP on an ESP today. 99% of NTP tutorials in the www are outdated.

first goal: get the Wemos connected to your Wifi.
Try the IDE example and tell us if it is working - after you have entered your SSID & Pwd

In the above you are not retrying WIFIi.Begin, it is normal to call that everytime around the while loop. Your coments say wait for 5 seconds, but you are only waiting for 1/2 second - it is normal to wait for 5 or 10 seconds between calls to WIFI.Begin - see the example Arduino - WiFiStatus

If you look in wl_definitions.h I think you will find that a status of 1 means WL_NO_SSID_AVAIL which implies you have got the SID/pwd wrong - case sensitive problem?

If you use the example above that Noiasca has also suggested and get your Wifi working first, you can then progess onto using NTP (there is an example for that too).

Hi,

I provided api key, ssid and password. The code compiles and uploads successfully to Wemos Mini (ESP8266). However, when I view output using serial monitor, it goes into an infinite loop which displays text below:

Attempting to connect to WPA SSID: xyz
Status = 1

I am new to this programming environment, so it will be great if you could provide some clarification of what I am doing wrong. Below is my code:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WifiLocation.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <SoftwareSerial.h>

/////////////////////////////// Settings /////////////////////////////////////////////

const char* googleApiKey = ""; // Your google geolocation api key
const char* ssid = ""; // Your Wifi SSID
const char* passwd = ""; // Your Wifi Password
const float timeZone = 8;

///////////////////////////////////////////////////////////////////////////////////////
#define sensorPin A0
//SoftwareSerial MyBlue(2, 3); // RX | TX
// Define Trig and Echo pin:
//#define trigPin 2
//#define echoPin 3
// Define variables:
unsigned long lastTime;
float distance;
boolean low, high, startup = true;
unsigned char alert = 0, event = 0;
String csv;

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");

WifiLocation location(googleApiKey);
location_t loc;

void setup() {
Serial.begin(9600);
Serial1.begin(9600);

Serial.println("Water Level Detector Started...");

// Connect to WPA/WPA2 network
WiFi.mode(WIFI_STA);

WiFi.begin(ssid, passwd);
while (WiFi.status() != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// wait 5 seconds for connection:
Serial.print("Status = ");
Serial.println(WiFi.status());
delay(500);
}

timeClient.begin();
timeClient.setTimeOffset(timeZone*3600);

pinMode(sensorPin, INPUT);

}

My first suggestion would be to click the "Flag" icon underneath your post and request the moderators to move your topic to a more suitable part of the forum. You may not get much help here, because this forum section is for a specific Arduino board, "Arduino WiFi rev 2" and you are not using that board, your are using a Wemos mini (much preferable in my opinion).

Second suggestion: read the forum guide to learn, among other important things, how to post code correctly. Then edit your post and correct how you posted your code.

1 Like

Status 1 means "WL_NO_SSID_AVAIL" meaning it cannot find the SSID you are using.

There is a standard sketch, I think you will find it in the examples menu, for scanning for all SSID the Wemos can see in range. It is called "wi-fi scanner" or something. Try this and tell us what you see.

DUPLICATE TOPICS MERGED

Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

This is my first time connecting Wemos to Wifi. After uploading example delivered with IDE: ESP8266 NTP-TZ-DST, I open serial monitor and see the following:

⸮⸮Gf⸮⸮⸮⸮z⸮R⸮⸮⸮⸮^⸮⸮j⸮⸮cZjZv⸮⸮⸮⸮Gf⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮^⸮⸮j⸮cZ⸮Zv⸮_⸮⸮⸮Gf⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮ڊ⸮⸮cZjZv

That doesn't look right

Arduino version 1.8.

that does look like you have not set your serial monitor to the right speed.

in 2021 lot of makers use at least

  Serial.begin(115200);

I modified speed of serial monitor and got output below:

localtime: isdst=0 yday=316 wday=1 year=117 mon=10 mday=13 hour=17 min=8 sec=2
gmtime:    isdst=0 yday=316 wday=1 year=117 mon=10 mday=13 hour=17 min=8 sec=2
clock:     60s + 70082000ns
millis:    60070
micros:    60070117
gtod:      1510592882s + 998776us
time:      1510592882
timezone:  GMT0BST,M3.5.0/1,M10.5.0
ctime:     Mon Nov 13 17:08:02 2017

time(): 1510592883   gettimeofday(): 1510592883.970165  seconds are unchanged
time(): 1510592884   gettimeofday(): 1510592884.020708  <-- seconds have changed

Is this expected result?

yes.
Coming back to your question
"[Unable to connect Wemos Mini (ESP8266) to WiFi"

--> you have connected to wifi
and you got time information via NTP.

I modified

 Serial.begin(115200);

Getting output below from serial monitor

Attempting to connect to WPA SSID: xyz
Status = 1

WL_NO_SSID_AVAIL cannot find the SSID

I was able to upload example ESP8266 / NTP-TZ-DST with correct and incorrect WiFi SSIS/password and got same output (see below) which is a bit confusing

localtime: isdst=0 yday=316 wday=1 year=117 mon=10 mday=13 hour=17 min=8 sec=2
gmtime:    isdst=0 yday=316 wday=1 year=117 mon=10 mday=13 hour=17 min=8 sec=2
clock:     60s + 70082000ns
millis:    60070
micros:    60070117
gtod:      1510592882s + 998776us
time:      1510592882
timezone:  GMT0BST,M3.5.0/1,M10.5.0
ctime:     Mon Nov 13 17:08:02 2017

time(): 1510592883   gettimeofday(): 1510592883.970165  seconds are unchanged
time(): 1510592884   gettimeofday(): 1510592884.020708  <-- seconds have changed

After running example ESP8266 / NTP-TZ-DST, I ran WiFi code below again:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WifiLocation.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <SoftwareSerial.h>

/////////////////////////////// Settings /////////////////////////////////////////////

const char* googleApiKey = ""; // Your google geolocation api key
const char* ssid = ""; // Your Wifi SSID
const char* passwd = ""; // Your Wifi Password
const float timeZone = 8;

///////////////////////////////////////////////////////////////////////////////////////
#define sensorPin A0
//SoftwareSerial MyBlue(2, 3); // RX | TX
// Define Trig and Echo pin:
//#define trigPin 2
//#define echoPin 3
// Define variables:
unsigned long lastTime;
float distance;
boolean low, high, startup = true;
unsigned char alert = 0, event = 0;
String csv;

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");

WifiLocation location(googleApiKey);
location_t loc;

void setup() {
Serial.begin(115200);
Serial1.begin(115200);

Serial.println("Water Level Detector Started...");

// Connect to WPA/WPA2 network
WiFi.mode(WIFI_STA);

WiFi.begin(ssid, passwd);
while (WiFi.status() != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// wait 5 seconds for connection:
Serial.print("Status = ");
Serial.println(WiFi.status());
delay(500);
}

timeClient.begin();
timeClient.setTimeOffset(timeZone*3600);

pinMode(sensorPin, INPUT);

}

Output

Attempting to connect to WPA SSID: xyz
Status = 1
Attempting to connect to WPA SSID: xyz
Status = 1
Attempting to connect to WPA SSID: xyz
Status = 1

I am expecting to be able to connect to WiFi, and return current date time, macAddress or something to verify connection was successful.

Any guidance to resolve issue will be greatly appreciated

do this test again with a power down of the Wemos.
if the Wemos is off power it will lose the internal time.
now power up the device
upload the NTP sketch with a false SSID / PWD
check the output.

@noiasca here is output

localtime: isdst=0 yday=316 wday=1 year=117 mon=10 mday=13 hour=17 min=17 sec=2
gmtime:    isdst=0 yday=316 wday=1 year=117 mon=10 mday=13 hour=17 min=17 sec=2
clock:     600s + 72078000ns
millis:    600072
micros:    600072114
gtod:      1510593422s + 998471us
time:      1510593422
timezone:  GMT0BST,M3.5.0/1,M10.5.0
ctime:     Mon Nov 13 17:17:02 2017

time(): 1510593423   gettimeofday(): 1510593423.970539  seconds are unchanged
time(): 1510593424   gettimeofday(): 1510593424.020605  <-- seconds have changed

Looks similar, and it takes really long to compile/upload sketch on Win 10