-
Notifications
You must be signed in to change notification settings - Fork 0
/
atmo_wifi.h
43 lines (39 loc) · 1018 Bytes
/
atmo_wifi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#define SITE_TIMEOUT_MS 5000 // timeout for site request
#define WIFI_DELAY_CHECK_TIME_MS 50
#define WIFI_TIMEOUT_MS 10000 // 10 sec to connect to wifi?
TaskHandle_t* WiFiTask;
void StartWiFi(void *args) {
pp("core 0?");
pp(xPortGetCoreID());
int connAttempts = 0;
WiFi.mode(WIFI_STA);
WiFi.begin(Prefs.getString(PREF_SSID_STRING).c_str(), Prefs.getString(PREF_PASSWORD_STRING).c_str());
while (WiFi.status() != WL_CONNECTED) {
delay(WIFI_DELAY_CHECK_TIME_MS); //Serial.print(F("."));
if (connAttempts > WIFI_TIMEOUT_MS / WIFI_DELAY_CHECK_TIME_MS) {
Prefs.putBool(PREF_VALID_BOOL, false); //invalidate location data // TODO indicate this on display
DrawFailedToConnectToWiFi();
AtmoDeepSleep();
}
connAttempts++;
}
vTaskDelete(NULL); // deletes self
}
void StopWiFi() {
WiFi.mode(WIFI_OFF);
}
void EnsureWiFiIsStarted()
{
int counter = 0;
while (!WiFi.isConnected())
{
if (counter % 10 == 0)
{
counter = 0;
Serial.println(".");
}
counter++;
delay(10);
}
}