完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
有时,网络服务器会卡在新客户端上,并且不会断开连接。
代码:全选#include #include Servo servo1; int pinservo = D2; int pulsomin = 1000; int pulsomax = 2000; const char* ssid = "Manuela"; const char* password = "manuel34068833"; int ledPin = D4; WiFiServer server(80); void setup() { Serial.begin(115200); delay(10); servo1.attach(pinservo,pulsomin,pulsomax); servo1.write(50); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); // Connect to 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"); // Start the server server.begin(); Serial.println("Server started"); // Print the IP address Serial.print("Use this URL : "); Serial.print("http://"); Serial.print(WiFi.localIP()); Serial.println("/"); } void loop() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Wait until the client sends some data Serial.println("new client"); while(!client.available()){ delay(100); } // Read the first line of the request String request = client.readStringUntil('r'); Serial.println(request); client.flush(); // Match the request int value = LOW; if (request.indexOf("Abrir") != -1) { digitalWrite(ledPin, HIGH); value = HIGH; servo1.write(39); delay(400); servo1.write(50); } if (request.indexOf("AbrirYcerrar") != -1){ digitalWrite(ledPin, LOW); value = LOW; servo1.write(39); delay(400); servo1.write(50); delay(55000); servo1.write(39); delay(400); servo1.write(50); } // Return the response client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); // do not forget this one client.println(""); client.println(""); client.println(""); client.println(" "); client.println(" Clickea ACA Para abrir el porton");client.println(""); delay(100); Serial.println("Client disconnected"); Serial.println(""); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
523浏览 6评论
433浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
420浏览 5评论
413浏览 4评论
387浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-10-31 21:12 , Processed in 0.715997 second(s), Total 76, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号