完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我写了一个简单的函数来管理我的 ESP8266 的 WiFi 连接。
我从 INI 读取数据,我想根据 INI 设置设置 wWiFi。 我有这个问题,如果我加入 ESP AP 网络只能使用静态 IP(自动 IP 分配不起作用)。 作为 ESP 客户端,如果我尝试断开与一个网络的连接并连接到另一个网络,则失败(返回值 7)。有什么帮助吗? 代码:全选void WiFiConnect(const char* filename) { IPAddress mask; if(ini_open (filename)) { NetworkChoice = ini_read ("NetworkChoice", "network","0"); ClientSSID = ini_read ("network" + NetworkChoice , "ClientSSID","BuddaceCasa"); ClientPassword = ini_read ("network" + NetworkChoice , "ClientPassword","25399750057853538077"); ClientSSID0 = ini_read ("network0", "ClientSSID","BuddaceCasa"); ClientPassword0 = ini_read ("network0", "ClientPassword","25399750057853538077"); ClientSSID1 = ini_read ("network1", "ClientSSID","BuddaceCasa"); ClientPassword1 = ini_read ("network1", "ClientPassword","25399750057853538077"); ClientSSID2 = ini_read ("network2", "ClientSSID","BuddaceCasa"); ClientPassword2 = ini_read ("network2", "ClientPassword","25399750057853538077"); HostSSID = ini_read ("host", "HostSSID","CV19Archimede"); HostPassword = ini_read ("host", "HostPassword","PlasticoCV19"); HostIp = ini_read ("host", "HostIp","10.10.0.1"); HostSubnetMask = ini_read ("host", "HostSubnetMask","255.0.0.0"); ini_close(); } else { NetworkChoice = "0"; ClientSSID = "BuddaceCasa"; ClientPassword = "25399750057853538077"; HostSSID = "CV19ArchimedeDef"; HostPassword = "PlasticoCV19Def"; HostIp = "10.0.0.1"; HostSubnetMask = "255.0.0.0"; } Serial.println(NetworkChoice); Serial.println(ClientSSID); Serial.println(ClientPassword); Serial.println(HostSSID); Serial.println(HostPassword); Serial.println(HostIp); Serial.println(HostSubnetMask); // Connect to Wi-Fi //WiFi.mode(WIFI_AP_STA); WiFi.mode(WIFI_AP_STA); WiFi.softAPdisconnect(); WiFi.disconnect(); delay(1000); Serial.println("Controllo disconnessione"); Serial.println(WiFi.status()); ip.fromString(HostIp.c_str()); mask.fromString(HostSubnetMask.c_str()); WiFi.softAP(HostSSID, HostPassword); WiFi.softAPConfig(ip, ip, mask); WiFi.begin(ClientSSID, ClientPassword); WiFi.hostname("CV19Archimede"); WifiRetry = 0; while((WiFi.status() != WL_CONNECTED) && ( WifiRetry < WIFIRETRY)) { delay(500); WifiRetry ++; if (WifiRetry > WIFIRETRY) { WiFi.disconnect(); } } Serial.println("stato corrente"); Serial.println(WiFi.status()); Serial.println(WiFi.localIP().toString()); ////Serial.println("Stato Wifi = " + String(WiFi.status()) + "fine stato" ); MacAddress = WiFi.macAddress(); WiFi.macAddress(mac); ClientIp = WiFi.localIP().toString(); HostIp_Read = WiFi.softAPIP().toString(); ip = WiFi.localIP(); hostip = WiFi.softAPIP(); WiFiEspNetwork(); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
310 浏览 1 评论
551浏览 6评论
461浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
443浏览 5评论
445浏览 4评论
415浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 11:35 , Processed in 0.716381 second(s), Total 74, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号