siri控制8266-Arduino中文社区 - Powered by Discuz! Archiver

15842547810 发表于 2020-4-8 00:14

siri控制8266

//本程序是操作8266的GPIO 0 口// 程序如下
#include <ESP8266WiFi.h>const char* ssid = "TP-11222";               //路由器账号const char* password = "11000323";          //路由器密码
WiFiServer server(80);// 服务器端口号void setup() {Serial.begin(115200);delay(10);pinMode(0, OUTPUT);                  //定义IO 0 输出
digitalWrite(0, 0);                        //IO 0上点低电频
// Connect to WiFi networkSerial.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"); cStart the serverserver.begin();Serial.println("Server started @ ");// Print the IP address & instructionsSerial.println(WiFi.localIP());//打印出IP地址,后期可以制作显示器来外部硬件显示ipSerial.println("To control GPIO, open your web browser.");Serial.println("To set GPIO 0 high, type:");Serial.print(WiFi.localIP());Serial.println("/gpio/1");Serial.println("To set GPIO 0 low, type:");Serial.print(WiFi.localIP());Serial.println("/gpio/0");Serial.println("To toggle GPIO 0, type:");Serial.print(WiFi.localIP());Serial.println("/gpio/4");}void loop() {// Check if a client has connectedWiFiClient client = server.available();if (!client) {    delay(100);    return;}String req = client.readStringUntil('\r');Serial.println(req);client.flush();// Match the requestint val;          //      下面开始判断ip进行动作指令if (req.indexOf("/gpio/off") != -1)    digitalWrite(0, 1);else if (req.indexOf("/gpio/on") != -1)    digitalWrite(0, 0);
else {    Serial.println("invalid request");    client.print("HTTP/1.1 404\r\n");    client.stop();    return;}client.flush();// Prepare the responseString s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nWelcome wenzheng space! ";s += "</html>\n";// Send the response to the clientclient.print(s);delay(1);Serial.println("Client disonnected");}




程序下载好后
打开串口监视器
复位8266
查看8622地址


https://www.arduino.cn/forum.php?mod=image&aid=64516&size=300x300&key=61e50f910a66b52f&nocache=yes&type=fixnone

记住这个地址192.168.1.112   我的是这个地址 ,每个人的都不一样,自己记住



下面是ios捷径的配置(请用苹果内置浏览器打开):
开灯
https://www.icloud.com/shortcuts/738ab973d2024d6a97c2692638bbd809?from=singlemessage&isappinstalled=0
关灯
https://www.icloud.com/shortcuts/8e25019a47604bb794856e5317ca7a30?from=singlemessage&isappinstalled=0



进入快捷指令编辑



https://www.arduino.cn/forum.php?mod=image&aid=64518&size=300x300&key=076dd0d22ba11154&nocache=yes&type=fixnone



给这个地址改成自己的





https://www.arduino.cn/forum.php?mod=image&aid=64517&size=300x300&key=6f3514de714aacb8&nocache=yes&type=fixnone






点右上角的完成就可以了



体验siri控制灯吧

唯一缺点内网控制不能用外网   







页: [1]
查看完整版本: siri控制8266