6 Star 20 Fork 2

FredyXu / CW_ESP8266_SSD1306_I2C_4PIN

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
wifi.h 1.48 KB
Copy Edit Web IDE Raw Blame History
FredyXu authored 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

Comment ( 0 )

Sign in for post a comment

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

Search

103611 48b8ff67 1899542 103622 4d02230c 1899542