Using a NodeMCU v1.0 ESP-12E to connect to a network

Hi,

I have just started getting into using WiFi modules and plan to use this one with an arduino for a project in future however I cannot seem to be able to connect to my home network and want to make sure this is setup before dabbling with the arduino.

Here is the code I have been working off:

#include <ESP8266WiFi.h> // Include the Wi-Fi library

const char* ssid = "VM082331-2G";
const char* password = "*****";

void setup() {
Serial.begin(115200);
delay(10);
Serial.println('\n');

WiFi.begin(ssid, password);
Serial.print("Connecting to ");
Serial.print(ssid); Serial.println(" ...");

int i = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(++i); Serial.print(' ');
}

Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP());

}

void loop() {
Serial.println(WiFi.begin());

}

When uploading it doesn't give any errors but won't connect to my network even though the SSID and Password are the same here are their outputs.

Sketch uses 264672 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 26820 bytes (32%) of dynamic memory, leaving 55100 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.6
2.6
esptool.py v2.6
Serial port COM3
Connecting....
Chip is ESP8266EX
Features: WiFi
MAC: ***************
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 268832 bytes to 195875...

Writing at 0x00000000... (8 %)
Writing at 0x00004000... (16 %)
Writing at 0x00008000... (25 %)
Writing at 0x0000c000... (33 %)
Writing at 0x00010000... (41 %)
Writing at 0x00014000... (50 %)
Writing at 0x00018000... (58 %)
Writing at 0x0001c000... (66 %)
Writing at 0x00020000... (75 %)
Writing at 0x00024000... (83 %)
Writing at 0x00028000... (91 %)
Writing at 0x0002c000... (100 %)
Wrote 268832 bytes (195875 compressed) at 0x00000000 in 17.4 seconds (effective 123.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

And Monitor

<<<stack<<<

last failed alloc call: 401001F0(32)

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld

Connecting to VM082331-2G ...
1 2 3 4 5 6 7 8

Any help on this would be greatly appreciated :slight_smile:

Thanks For Looking,
Ben

If You use the advice given in the topic "BEGINNERS and LEARNERS read this…" several more helpers will assist You. Atach code using code the tags </>. That creates a scrolling window for us.
Using Serial.print for test messages, including printing out appropriate status from connected devices, also calling for some extra code, is a well working strategy.

BenjaminoTzu:
<<<stack<<<

last failed alloc call: 401001F0(32)

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

That's a crash, and there must be a lot more in that stack trace. I don't think this is the complete output of your Serial monitor. Use the ESP Exception Decoder extension to make sense of what all those numbers mean.

Which ESP module are you using? Do you have it set up properly in your IDE? Do you have the latest ESP core?

Try changing

Serial.print(++i); Serial.print(' ');

to

Serial.print(WiFi.status()); Serial.print(' ');

This prints your WiFi status as it tries to connect to your WiFi.
The WiFi.status function returns a value:

0 WiFi is in process of changing between statuses
1 SSID cannot be reached
2 Scan Completed
3 Successful connection is established
4 Password is incorrect
5 Connection Lost
6 Module is disconnected or not configured in station mode

You should normally see a few sixes , followed by a single three.
Tell me if you get something different.

1 Like

Hi Everyone,

Sorry I have just been messing around with the code today and noticed that in the Serial Monitor it Displays that it is connected I just didn't see it as it didn't autoscroll to it.

Sorry again everyone,
Ben