forked from jhughes1010/weather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifi.ino
54 lines (52 loc) · 1.38 KB
/
wifi.ino
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
44
45
46
47
48
49
50
51
52
53
54
//=======================================================================
// wifi_connect: connect to WiFi or explicitly connect to Blynk, if used
//=======================================================================
long wifi_connect()
{
bool WiFiConnectHalt = false;
int retry = 0;
long wifi_signal = 0;
MonPrintf("Starting wifi for App = %s\n", App);
if (App == "BLYNK") // for posting datas to Blynk App
{
Blynk.begin(auth, ssid, pass);
}
else if ((App == "Thingspeak") || (App == "MQTT")) // for posting datas to Thingspeak website
{
MonPrintf("Connecting to WiFi\n");
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED && !WiFiConnectHalt )
{
MonPrintf(".");
delay(500);
retry++;
if (retry > 15)
{
MonPrintf(".\n");
MonPrintf("Max trys to connect to WiFi reached and failed");
WiFiConnectHalt = true;
wifi_signal = RSSI_INVALID;
return wifi_signal;
}
}
MonPrintf("WiFi connected\n");
wifi_signal = WiFi.RSSI();
}
/*
else if (App == "MQTT") // for posting datas to Thingspeak website
{
MonPrintf("Connecting to WiFi\n");
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
MonPrintf("WiFi connected\n");
}
*/
else
{
MonPrintf(" is not a valid application");
}
return wifi_signal;
}