Connecting ESP32 to the WiFi

Hello,

I'm trying to connect my ESP32 to my home WiFi so I did the following sketch:

#include <WiFi.h>

// Replace with your network credentials (STATION)
const char* ssid = "...";
const char* password = "...";

void initWiFi() 
{
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) 
  {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
}

void setup() 
{
  Serial.begin(9600);
  initWiFi();
  Serial.print("RRSI: ");
  Serial.println(WiFi.RSSI());
}

void loop() 
{
  // put your main code here, to run repeatedly:
}

The ESP32 keeps trying to connect to the WiFi but it never really connects to it. I search alot but I can't understand what's missing to put this into a real connection.

Can you, please, advice me?

Thanks in advance!

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Hello @UKHeliBob,

Thanks for the advice! I edited the publication to include the code. I let stay the image to show the message I get.

Thanks!

Thank you for posting the code in code tags. I am sure that you can see how much easier it is to read and copy for examination if required

Not really a problem in this case but you could have copied the Serial monitor output and posted it here in code tags too

The code looks OK and works for me

Connecting to WiFi ......192.168.1.103
RRSI: -42

Are you sure that you are using the correct SSID and password ?

Hello @UKHeliBob

With your reply I tested one thing: I was using the Ethernet cable and it seems that with that I can't connect to the WiFi, my bad on that... I though it would work anyway even with the Ethernet cable in use...

Thanks for the help!

How does one connect an Ethernet cable to an ESP32?

The fact that your PC is using Ethernet should make no difference to the ability of the ESP32 to connect to WiFi

That is exactly how my PC is configured

The cable was not connect to the ESP32 but to my computer :slight_smile:

So you plugged an ethernet cable into your PC and fired up WiFi on a ESP32 and expected the WiFi of an ESP32 to connect to an ethernet cable?

You can buy ethernet modules that can be hooked up to a ESP32. Search on the wrods "arduino ethernet module".

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