完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我有这段代码适用于我的 ESP8266:
代码:全选#include #include const size_t input_buffer_length = 256; const char* ssid = "myWifi"; const char* wifiPassword = "password123"; const char* passwordToOpenDoor = "/87"; //password should begin with a slash const int doorPin = 5; const int buzzerPin = 4; const int toneDuration = 700; int numOfRequests = 0; WiFiServer server(301); //Pick any port number you like WiFiClient client; void setup() { Serial.begin(115200); delay(10); Serial.println(WiFi.localIP()); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, 1); pinMode(doorPin, OUTPUT); digitalWrite(doorPin, 0); pinMode(buzzerPin, OUTPUT); digitalWrite(buzzerPin, 0); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, wifiPassword); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); experimental::ESP8266WiFiGratuitous::stationKeepAliveSetIntervalMs(); server.begin(); Serial.println("Server started."); Serial.println(WiFi.localIP()); } void loop() { client = server.available(); if (!client) { return; } while(!client.available()){ delay(1); } char request[input_buffer_length]; client.readBytesUntil('\r', request, input_buffer_length); Serial.println(request); if(strstr(request, passwordToOpenDoor)) {//Is password correct? GenerateResponse("Password is correct"); OpenDoor(); CorrectPasswordSound(); } //Got a GET request and it wasn't the favicon.ico request, must have been a bad password: else if (!strstr(request, "favicon.ico")) { GenerateResponse("Password is incorrect."); } } void OpenDoor() { digitalWrite(LED_BUILTIN, 0); //flash the onboard LED to help during testing. digitalWrite(doorPin, 1); delay(500); digitalWrite(LED_BUILTIN, 1); digitalWrite(doorPin, 0); } void GenerateResponse(const char *text) { Serial.println(text); client.print( "HTTP/1.1 200 OK\r\n" "Content-Type: text/html\r\n" "\r\n" "\r\n" "\r\n" " " |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
1106 浏览 1 评论
574浏览 6评论
477浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
460浏览 5评论
461浏览 4评论
435浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-18 12:45 , Processed in 0.989238 second(s), Total 75, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号