功能简介
对Siri说turn on,放在远处的LED会点亮
对Siri说turn off, 放在远处的LED 会熄灭
下载观看功能视频(传送门)
ESP8266开发板相关
下载驱动
Windows驱动传送门
相关设置
Mac驱动传送门
链接开发板
并将http://arduino.esp8266.com/stable/package_esp8266com_index.json
复制到图中位置
添加ESP8266,下载即可(最好用加速器)
选中端口,插入ESP8266后一般会多几个端口,简单点,挨个测试下就好
相关代码
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WebServer.h>
ESP8266WiFiMulti wifiMulti;
ESP8266WebServer esp8266_server(80);
void handleRoot(){
esp8266_server.send(200,"text/html","<form action=\"/LED\" method=\"POST\"><input style=\"width: 500px;height: 500px;color:blue;\" type=\"submit\" value=\"Toggle LED\"></form>");
}
void handleNotFound(){
esp8266_server.send(404,"text/plain","404: Not Found");
}
void handleLED(){
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
digitalWrite(D0, !digitalRead(D0));
Serial.println("来者不拒 ...: ");
esp8266_server.sendHeader("Location","/");
esp8266_server.send(303);
}
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(D0, OUTPUT);
wifiMulti.addAP("WIFI名1","密码");
wifiMulti.addAP("WIFI名2","密码");
//可以写多个
Serial.print("Connecting ...: ");
int i = 0;
while(wifiMulti.run() != WL_CONNECTED){
delay(1000);
Serial.print(i + '.');
}
Serial.println();
Serial.print("Connected to ");
Serial.println(WiFi.SSID());
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
esp8266_server.begin();
esp8266_server.on("/", HTTP_GET ,handleRoot);
esp8266_server.on("/LED", HTTP_POST ,handleLED);
esp8266_server.onNotFound(handleNotFound);
}
void loop() {
esp8266_server.handleClient();
}
网络组建
以局域网测试
1、手机打开热点,设置可以多人接入
2、ESP8266需要RST一下
3、随便一台终端设备接入热点,输入Arduino开发环境打印的ESP8266打印的接入网址
4、点击网页的按钮测试下小灯的熄灭与点亮状态
5、如果没问题进行下一步
Apple系列Shortcuts(快捷指令)设置
对:Siri说turn on则开灯,说turn off则关灯
IP设置为Arduino开发环境打印的ESP8266获取的网址