1 Star 0 Fork 10

niubileni / CW_ESP8266_SSD1306_I2C_4PIN

加入 Gitee
与超过 600 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
wifi.h 1.48 KB
一键复制 编辑 Web IDE 原始数据 按行查看 历史
FredyXu 提交于 2020-01-18 23:24 . 增加备用WIFI
// ESP8266 wifi
#ifndef _NET_ESP8266_H
#define _NET_ESP8266_H
#include <ESP8266WiFi.h>
extern void d_home_update();
// 函数声明
bool connect_wifi(String ssid, String password);
void init_wifi();
// 连接WIFI
void init_wifi()
{
// WiFi.mode(WIFI_STA);
String wifi_info = "";
d_home_update("info", "WiFi...");
bool flag_connected = false;
int connect_num = 0;
while(flag_connected == false && connect_num < 2) {
if(connect_num == 0) {
Serial.println("连接主WIFI");
wifi_time_s = millis();
flag_connected = connect_wifi(ssid_1, password_1);
}
else if(connect_num == 1){
Serial.println("连接备用WIFI");
wifi_time_s = millis();
flag_connected = connect_wifi(ssid_2, password_2);
}
connect_num++;
}
if(flag_connected) {
wifi_info = "WiFi...OK";
Serial.println("连接成功");
}
else {
wifi_info = "WiFi...Failed";
Serial.println("连接失败");
flag_net = false;
}
d_home_update("info", wifi_info);
}
bool connect_wifi(String ssid, String password) {
bool check = true;
// WiFi初始化
WiFi.begin(ssid, password);
unsigned long connect_time;
int current_ssid = 1;
bool flag_stop_try = false;
while (WiFi.status() != WL_CONNECTED && flag_net)
{
// check_btn();
delay(100);
Serial.print(".");
connect_time = int(millis() - wifi_time_s);
d_home_update("info", "WiFi...(" + String((wifi_timeout - connect_time) / 1000) + ")");
if (connect_time >= wifi_timeout)
{
check = false;
break;
}
}
return check;
}
#endif

评论 ( 0 )

你可以在登录后,发表评论

C
1
https://gitee.com/niubileni/cw_esp8266_ssd1306_i2c_4pin.git
git@gitee.com:niubileni/cw_esp8266_ssd1306_i2c_4pin.git
niubileni
cw_esp8266_ssd1306_i2c_4pin
CW_ESP8266_SSD1306_I2C_4PIN
master

搜索帮助