-
Notifications
You must be signed in to change notification settings - Fork 18
/
wifi.ino
53 lines (50 loc) · 1.34 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
//=======================================================================
// 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 )
{
delay(500);
retry++;
if (retry > 15)
{
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;
}