Skip to content

Update BlynkSimpleEsp8266.h #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/BlynkSimpleEsp8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,31 @@ class BlynkWifi
(void)myip; // Eliminate warnings about unused myip
BLYNK_LOG_IP("IP: ", myip);
}

bool connectWiFi_t(const char* ssid,
const char* pass,
uint16_t timeout = 10000)
{
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
WiFi.mode(WIFI_STA);
if (WiFi.status() != WL_CONNECTED) {
if (pass && strlen(pass)) {
WiFi.begin(ssid, pass);
} else {
WiFi.begin(ssid);
}
}
int WFB = timeout / 500; // set default 20 cycles
while ((WiFi.status() != WL_CONNECTED) && (WFB>0)) {
BlynkDelay(500);
--WFB;
}
if (WiFi.status() != WL_CONNECTED) return false;
BLYNK_LOG1(BLYNK_F("Connected to WiFi"));
IPAddress myip = WiFi.localIP();
BLYNK_LOG_IP("IP: ", myip);
return true;
}

void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
Expand Down Expand Up @@ -93,6 +118,24 @@ class BlynkWifi
config(auth, ip, port);
while(this->connect() != true) {}
}



bool begin_t(const char* auth,
const char* ssid,
const char* pass,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT,
uint16_t wifi_timeout = 30000)
{
if (WiFi.status() != WL_CONNECTED) {
uint16_t connect_count = wifi_timeout / 10000;
while ((connectWiFi_t(ssid, pass, wifi_timeout / 3)) && (connect_count>0)) --connect_count;
if (WiFi.status() != WL_CONNECTED) return false;
}
config(auth, ip, port);
return this->connect();
}

};

Expand Down