完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好。
我想把带有外部按钮的 Sonoff Th16 放在盒子里。当我按下按钮时,我想访问 Wifimanager 的门户以输入新密码。这可能吗?这是我想要使用的代码。感谢您的帮助! 代码:全选#include #include #include #include // https://github.com/bblanchon/ArduinoJson #include // https://github.com/arduino-libraries/NTPClient WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "pool.ntp.org", timezonemins*60, 60000); DynamicJsonBuffer jsonBuffer; WiFiClientSecure client; static char respBuffer[4096]; uint8_t relayPin = 12; // this is the relay Pin uint8_t ledPin = 13; // this is the green led Pin uint16_t minutesNow; uint16_t startMins; uint16_t switchOffMin; uint16_t switchOnMin; boolean relay = HIGH; void setup() { pinMode(relayPin, OUTPUT); pinMode(ledPin, OUTPUT); digitalWrite(relayPin, HIGH); // switch on the light by default WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { // Waiting to connect to wifi network delay (500); digitalWrite(ledPin, !digitalRead(ledPin)); // this blinks the LED } digitalWrite(ledPin, HIGH); // switches off the LED const char request[] = "GET /json?lat=" LATTITUDE "&lng=" LONGITUDE "&formatted=0 HTTP/1.1\r\n" "User-Agent: ESP8266/1.0\r\n" "Accept: */*\r\n" "Host: api.sunrise-sunset.org \r\n" "Connection: close \r\n" "\r\n"; while (!client.connect("api.sunrise-sunset.org", 443)) { // Waiting to get the sunrise and sunset time delay(3000); } client.print(request); client.flush(); uint16_t index = 0; while(client.connected()) { if (client.available()) { respBuffer[index++] = client.read(); delay(1); } } client.stop(); char* json = strchr(respBuffer, '{'); JsonObject& req = jsonBuffer.parseObject(json); JsonObject& results = req["results"]; String sr = results["sunrise"]; String ss = results["sunset"]; switchOffMin = sr.substring(11,13).toInt()*60 + sr.substring(14,16).toInt(); switchOffMin = switchOffMin + timezonemins + sunriseDelay; if (switchOffMin>1440) {switchOffMin = switchOffMin -1440;} // day correction switchOnMin = ss.substring(11,13).toInt()*60 + ss.substring(14,16).toInt(); switchOnMin = (switchOnMin + timezonemins + sunsetDelay) % 1440; timeClient.begin(); while (!timeClient.update()) { // Waiting to find the current time delay(3000); } startMins = timeClient.getHours()*60 + timeClient.getMinutes(); startMins = startMins - (millis()/60000); // compensate for the current elapsed time } void loop() { if (timeClient.update()) { minutesNow = timeClient.getHours()*60 + timeClient.getMinutes(); } else { minutesNow = (startMins + (millis()/60000)) % 1440; } //timeClient.update(); minutesNow = timeClient.getHours()*60 + timeClient.getMinutes(); if ((minutesNow > switchOffMin) && (minutesNow < switchOnMin) && (relay == HIGH)) { digitalWrite(relayPin, LOW); // switch off the light digitalWrite(ledPin, LOW); // switches on the LED relay = LOW; } else if (((minutesNow < switchOffMin) || (minutesNow > switchOnMin)) && (relay == LOW)) { digitalWrite(relayPin, HIGH); // switch on the light digitalWrite(ledPin, HIGH); // switches off the LED relay = HIGH; } delay(3000); } |
|
相关推荐
1个回答
|
|
ody[2048];void setup() { pinMode(0, INPUT_PULLUP); Serial.begin(115200); delay(10); WiFiManager wifiManager; wifiManager.autoConnect("SonoffTH16"); timeClient.begin(); client.setInsecure();}void loop() { if (digitalRead(0) == LOW) { WiFiManager wifiManager; wifiManager.setConfigPortalTimeout(180); if (!wifiManager.startConfigPortal("SonoffTH16")) { Serial.println("failed to connect and hit timeout"); delay(3000); ESP.restart(); } } timeClient.update(); delay(1000);}
|
|
|
|
只有小组成员才能发言,加入小组>>
140 浏览 0 评论
1158 浏览 1 评论
584浏览 6评论
482浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
467浏览 5评论
466浏览 4评论
441浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 18:21 , Processed in 0.967185 second(s), Total 77, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号