完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在尝试从我的 android(蓝牙)获取 ssid 和密码,并将它们传递到 wifi 以开始连接。它从不连接到我的wifi。
我读到它需要一些 delay() 并且我添加了一些 ms 但它仍然无法正常工作。有任何想法吗? 代码:全选/* * Arduino home button sketch * Tzivaras Vasilis * vtzivaras@gmail.com * */ #include #include #include #include #include #define BUTTONPIN D3 SoftwareSerial mySerial(D1,D2); String Data = ""; String password1 = ""; String ssid1 = ""; int button = 0; // 0 isrealeashed, 1 is pressed char inChar; int READINGSTATUS = -1; char str[80] = "This is - www.tutorialspoint.com - website"; const char s[2] = ":"; char *token; const char* ssid = ""; const char* password = ""; const char* host = "cemup.com"; const int httpsPort = 9002; // Use web browser to view and copy // SHA1 fingerprint of the certificate const char* fingerprint = "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C"; void parseInput() { int i=0; int pos = 0; // Check if full message is received. for(i=0; i 0) { char myc = mySerial.read(); Data.concat(myc); Serial.print(myc); Serial.print(" "); delay(20); if (myc == '>') { break; } } } //parseInput(); //mySerial.write("Everything is ok"); //Serial.print("Android said: "); //Serial.println(Data); //Serial.println("Connecting with: "); //Serial.println(password1); //Serial.println(ssid1); //char id[ssid1.length()+1]; //ssid1.toCharArray(id, ssid1.length()+1); //password.toCharArray(password1, ); // Connecting to WIFI hotspot //Serial.print("SSID: "); //Serial.println(id); ssid = "myssid"; password = "*****"; Serial.println(micros()); // Connecting to WIFI hotspot WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); // Use WiFiClientSecure class to create TLS connection WiFiClientSecure client; Serial.print("connecting to "); Serial.println(host); if (!client.connect(host, httpsPort)) { Serial.println("connection failed"); return; } /* if (client.verify(fingerprint, host)) { Serial.println("certificate matches"); } else { Serial.println("certificate doesn't match"); } */ String url = "/"; Serial.print("requesting URL: "); Serial.println(url); client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "User-Agent: BuildFailureDetectorESP8266\r\n" + "Connection: close\r\n\r\n"); Serial.println("request sent"); while (client.connected()) { String line = client.readStringUntil('\n'); if (line == "\r") { Serial.println("headers received"); break; } } String line = client.readStringUntil('\n'); if (line.startsWith("{\"state\":\"success\"")) { Serial.println("esp8266/Arduino CI successfull!"); } else { Serial.println("esp8266/Arduino CI has failed"); } Serial.println("reply was:"); Serial.println("=========="); Serial.println(line); Serial.println("=========="); Serial.println("closing connection"); } void loop() { int buttonState = digitalRead(BUTTONPIN); if( buttonState == 1) { Serial.println("Button is releashed!"); }else { Serial.println("Button is pressed!"); } if (mySerial.available() > 0) { //Serial.println("---> Incoming byte!"); char myc = mySerial.read(); Serial.print(myc); Serial.print(" "); } /* inChar = mySerial.read(); if(inChar == '<') { READINGSTATUS = 1; inChar = mySerial.read(); }else if (inChar == '>') { READINGSTATUS = 0; } if (READINGSTATUS == 1) { Data.concat(inChar); } } if( READINGSTATUS == 0) { parseInput(); READINGSTATUS = -1; } */ delay(50); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
733 浏览 1 评论
552浏览 6评论
461浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
445浏览 5评论
446浏览 4评论
417浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 14:36 , Processed in 0.621730 second(s), Total 45, Slave 38 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号