完善资料让更多小伙伴认识你,还能领取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(""); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
988 浏览 1 评论
553浏览 6评论
463浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
447浏览 5评论
448浏览 4评论
421浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 00:17 , Processed in 0.595560 second(s), Total 46, Slave 39 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号