-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.h
94 lines (86 loc) · 2.33 KB
/
init.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef __INIT_H_
#define __INIT_H_
char OUT[12];
const char* ssid = STASSID;
const char* password = STAPSK;
bool wifiTimeout = false;
long lastHmMillis = 0;
long lastMbMillis = 0;
int rebootCount = 0;
int loopCounter = 0;
int IntervalModbus = 1;
//------------------------------
// Serial
void serialBegin(){
Serial.begin(SERIALSPEED);
delay(1200);
Serial.println("");
Serial.println("______________________________ ");
Serial.println("");
}
void serialPrintSW(){
Serial.print("Software Version : ");Serial.printf(" V%4.2f\n",SW_VERSION);
Serial.print("Software Datum : ");Serial.printf(" %s\n",SW_DATE);
}
//------------------------------
// WiFi network
void startWifi(){
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("WiFi init : wait...");
int timeout = 0;
while (WiFi.status() != WL_CONNECTED && timeout < WIFI_TIMEOUT * 2) {
Serial.print(".");
delay(500);
timeout++;
}
if (timeout < WIFI_TIMEOUT * 2){
Serial.println("");
Serial.println("WiFi status : connected");
Serial.print("ESP-IP address : ");
Serial.println(WiFi.localIP());
Serial.print("WiFi strength : ");Serial.printf("%6d dBm\n",WiFi.RSSI());
wifiTimeout = false;
}
else {
Serial.println("");
Serial.println("WiFi status : failed!");
wifiTimeout = true;
}
}
//------------------------------
// init Preferences
#ifdef ESP32
#include <Preferences.h>
Preferences paraWifi, paraESP;
void initPreferences(){
paraESP.begin("ESP");
}
#endif
//------------------------------
// Zähler für Reboot
void rebootCounter(){
#ifdef ESP8266
//writeReboot(0); //einmalig aktivieren zum zurücksetzen
rebootCount = readReboot();
if (rebootCount >= 65634) rebootCount = 0;
rebootCount++;
Serial.print("Reboot counter : ");Serial.println(rebootCount);
writeReboot(rebootCount);
#else
//paraESP.putUInt("BOOT", 0); //einmalig aktivieren zum zurücksetzen
rebootCount = paraESP.getUInt("BOOT");
if (rebootCount >= 65634) rebootCount = 0;
rebootCount++;
Serial.print("Reboot counter : ");Serial.println(rebootCount);
paraESP.putUInt("BOOT", rebootCount);
#endif
}
int readRebootCounter(){
#ifdef ESP8266
return readReboot();
#else
return paraESP.getUInt("BOOT");
#endif
}
#endif // __INIT_H_