Let your esp32 connect to the Internet in one minute

1. Software installation

If you want to write code, you must first have a software. It is recommended that Xiaobai start using the arduino software, and then use the platformIO of vscode after getting familiar with it later.

I will skip the installation of the software here, and I will write an article later to tell you how to install the software (here, everyone uses the software by default).

2. Connect to the Internet in one minute

As a chip that can be connected to the Internet, the simplest demo can connect your esp32 to the network in one minute.

The development board used is esp32-s nodemcu, as shown below:

code show as below:

#include <WiFi.h>

const char* ssid     = "xxx"; // wifi名称
const char* password = "xxx"; // wifi密码

void setup()
{
    Serial.begin(115200);//初始化串口,波特率115200
    WiFi.begin(ssid, password);//连接wifi

    while (WiFi.status() != WL_CONNECTED) { // 等待连接WIFI 直到连接成功 退出循环
        delay(500);
        Serial.print(".");
    }
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());  // 显示连接WIFI后的IP地址
  
}

void loop(){
}

Upload the above code to the esp32 development board, open the serial port, and check whether it is connected to the network.

There are some garbled characters in the front, don’t worry about it, just read the next two sentences: The IP address is 192.168.31.91. At this point the module has been connected to the network.

You can log in to your home router to check it, or you can use the command line to ping it (the computer and the module are under the same network).

It can be pinged, and the module is successfully connected to the Internet.

Guess you like

Origin blog.csdn.net/weixin_58125062/article/details/129718766