-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions.h
51 lines (35 loc) · 967 Bytes
/
Functions.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
44
45
46
47
48
49
50
51
#include <WiFi.h>
#include <WiFiClient.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include "TimeLib.h"
const char* WIFI_SSID = "WIFI NETWORK NAME";
const char* WIFI_PASSWORD = "WIFI PASSWORD";
void initializeWiFi(String initialMessage) {
int wifiReconnectCount = 0;
Serial.println(initialMessage);
Serial.println(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
if(wifiReconnectCount > 4500){
ESP.restart();
}
delay(500);
Serial.print(".");
wifiReconnectCount++;
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(WIFI_SSID);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void checkReconnectWifi(){
// if WiFi is down, try reconnecting every CHECK_WIFI_TIME seconds
if ((WiFi.status() != WL_CONNECTED)) {
WiFi.disconnect();
initializeWiFi("Reconnecting To ");
}
}