一、Arduino IDE配置(主要要点,并非新手用的分步教程)
1、下载最新版的Arduino IDE;
网址:Software | Arduino,下载Arduino IDE 2.1.1;
2、安装ESP32开发板包,试了各种路径都很麻烦,避免走弯路,直接搜索点灯科技。盛赞国产之光,我辈当自强,以后开发软件不能被老外卡脖子。
点灯科技:点灯科技-点灯物联网解决方案
package官方版下载丨最新版下载丨绿色版下载丨APP下载-123云盘
一次性全部下载备用,我用的是2.0.7版本。是自解压版本,双击直接就安装好了。
3、Arduino IDE开发板管理器里面,输入ESP32,选择ESP32 dev module,找到自己的板子类型;
我用的芯片是ESP32 WROOM,LED接GPIO15。
二、程序部分
1、程序目的:将示例程序里的SimpleWiFiServer、WiFiSmartConfig组合起来。
SimpleWiFiServer代码:
/*
WiFi Web Server LED Blink
A simple web server that lets you blink an LED via the web.
This sketch will print the IP address of your WiFi Shield (once connected)
to the Serial monitor. From there, you can open that address in a web browser
to turn on and off the LED on pin 5.
If the IP address of your shield is yourAddress:
http://yourAddress/H turns the LED on
http://yourAddress/L turns it off
This example is written for a network using WPA2 encryption. For insecure
WEP or WPA, change the Wifi.begin() call and use Wifi.setMinSecurity() accordingly.
Circuit:
* WiFi shield attached
* LED attached to pin 5
created for arduino 25 Nov 2012
by Tom Igoe
ported for sparkfun esp32
31.01.2017 by Jan Hendrik Berlin
*/
#include <WiFi.h>
const char* ssid = "yourssid";
const char* password = "yourpasswd";
WiFiServer server(80);
void setup()
{
Serial.begin(115200);
pinMode(5, OUTPUT); // set the LED pin mode
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}
void loop(){
WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
Serial.println("New Client."); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header: