-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathNemesis.ino
224 lines (173 loc) · 5.69 KB
/
Nemesis.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/***************************************************
Copyright (C) 2016 Steffen Ochs, Phantomias2006
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
HISTORY: Please refer Github History
****************************************************/
// EXECPTION LIST
// https://links2004.github.io/Arduino/dc/deb/md_esp8266_doc_exception_causes.html
// WATCHDOG
// https://techtutorialsx.com/2017/01/21/esp8266-watchdog-functions/
// Entwicklereinstellungen
#define DEBUG // ENABLE SERIAL DEBUG MESSAGES
//#define OTA // ENABLE OTA UPDATE
//#define THINGSPEAK // ENABLE THINGSPEAK CONNECTION
//#define MEMORYCLOUD // ENABLE DATA LOGGER
//#define WEBSOCKET // ENABLE WEBSOCKET
//#define AMPERE // ENABLE AMPERE MEASUREMENT TEST
#ifdef DEBUG
#define DPRINT(...) Serial.print(__VA_ARGS__)
#define DPRINTLN(...) Serial.println(__VA_ARGS__)
#define DPRINTP(...) Serial.print(F(__VA_ARGS__))
#define DPRINTPLN(...) Serial.println(F(__VA_ARGS__))
#define DPRINTF(...) Serial.printf(__VA_ARGS__)
#define IPRINT(...) Serial.print("[INFO]\t");Serial.print(__VA_ARGS__)
#define IPRINTLN(...) Serial.print("[INFO]\t");Serial.println(__VA_ARGS__)
#define IPRINTP(...) Serial.print("[INFO]\t");Serial.print(F(__VA_ARGS__))
#define IPRINTPLN(...) Serial.print("[INFO]\t");Serial.println(F(__VA_ARGS__))
#define IPRINTF(...) Serial.print("[INFO]\t");Serial.printf(__VA_ARGS__)
#else
#define DPRINT(...) //blank line
#define DPRINTLN(...) //blank line
#define DPRINTP(...) //blank line
#define DPRINTPLN(...) //blank line
#define DPRINTF(...) //blank line
#define IPRINT(...) //blank line
#define IPRINTLN(...) //blank line
#define IPRINTP(...) //blank line
#define IPRINTPLN(...) //blank line
#define IPRINTF(...) //blank line
#endif
// ++++++++++++++++++++++++++++++++++++++++++++++++++++
// INCLUDE SUBROUTINES
#include "c_init.h"
#include "c_webhandler.h"
#include "c_button.h"
#include "c_median.h"
#include "c_sensor.h"
#include "c_pitmaster.h"
#include "c_temp.h"
#include "c_ee.h"
#include "c_fs.h"
#include "c_com.h"
#include "c_icons.h"
#include "c_wifi.h"
#include "c_frames.h"
#include "c_bot.h"
#include "c_pmqtt.h"
#include "c_ota.h"
#include "c_server.h"
#include "c_api.h"
#include "c_ws.h"
//++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SETUP
void setup() {
//delay(1000);
// Initialize Serial
set_serial(); Serial.setDebugOutput(true);
set_ostimer();
printf("SDK version:%s\n", system_get_sdk_version()); //getSdkVersion
// Initialize OLED
set_OLED();
// Open Config-File
check_sector();
setEE(); start_fs();
// Current Battery Voltage
get_Vbat(); get_rssi();
if (!sys.stby) {
// Initalize Aktor
set_piepser();
// GodMode aktiv
if (sys.god & (1<<0)) {
piepserON(); delay(500); piepserOFF();
}
// Initialize mqtt
set_pmqtt(1);
// Initialize Wifi
set_wifi();
// Initialize Server
server_setup();
// Initialize OTA
#ifdef OTA
set_ota();
ArduinoOTA.begin();
#endif
// Initialize Sensors
set_sensor();
set_channels(0);
// Initialize Buttons
set_button();
// Current Wifi Signal Strength
get_Vbat();
get_rssi();
cal_soc();
// Initialize Pitmaster
set_pitmaster(0);
// Check Reset Info
if (checkResetInfo()) {
//if (SPIFFS.remove(LOG_FILE)) Serial.println("Neues Log angelegt");
}
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++
// LOOP
void loop() {
// Detect Serial Input
static char serialbuffer[300];
if (readline(Serial.read(), serialbuffer, 300) > 0) {
read_serial(serialbuffer);
}
// Manual Restart
if (sys.restartnow) {
if (wifi.mode == 5) WiFi.disconnect();
delay(100);
yield();
ESP.restart();
}
// Standby oder Mess-Betrieb
if (standby_control()) return;
// Close Start Screen
if (question.typ == SYSTEMSTART && millis() > 3000) {
displayblocked = false; // Close Start Screen (if not already done)
question.typ = NO;
}
// WiFi - Monitoring
wifimonitoring();
// MQTT - Abschaltung und Initialisierung
checkMqtt();
// Detect OTA
#ifdef OTA
ArduinoOTA.handle();
#endif
// HTTP Update
check_api();
if (update.state > 0) do_http_update();
// Detect Button Event
if (button_input()) button_event();
// Update Display
int remainingTimeBudget;
if (!displayblocked) remainingTimeBudget = ui.update();
else remainingTimeBudget = 1;
// Timer Actions
if (remainingTimeBudget > 0) {
// Don't do stuff if you are below your time budget.
maintimer();
#ifdef AMPERE
ampere_control();
#endif
// Pitmaster eventuell raus aus der Bedingung
pitmaster_control(0); // Pitmaster 1
updateServo();
if (servointerrupt) { // nur innerhalb eines Servo-Takts
delay(10); // sonst geht das Wifi Modul nicht in Standby, yield() reicht nicht!
}
}
}