(二)WiFi控制led灯
1、打开示例->ESP8266WIFI->WiFiwebServer;
没有的话,直接复制下面的代码吧!
2、代码如下:
/*
* This sketch demonstrates how to set up a simple HTTP-like server.
* The server will set a GPIO pin depending on the request
* **http://server_ip/?gpio=0** will set the GPIO2 low,
* **http://server_ip/?gpio=1** will set the GPIO2 high
* server_ip is the IP address of the ESP8266 module, will be
* printed to Serial when the module is connected.
*/
#include <ESP8266WiFi.h>
const char* ssid = "your wifi";
const char* password = "123456";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);//开启板子的port 80
void setup() {
Serial.begin(115200);//开启端口,速度为115200
delay(10);
// prepare GPIO2
pinMode(2, OUTPUT);//2号脚位定为输出,即D4脚位
digitalWrite(2, 0);
// Connect to WiFi network
Serial.println(