-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathSomfyController.ino
86 lines (81 loc) · 2.29 KB
/
SomfyController.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
#include <WiFi.h>
#include <LittleFS.h>
#include <esp_task_wdt.h>
#include "ConfigSettings.h"
#include "Network.h"
#include "Web.h"
#include "Sockets.h"
#include "Utils.h"
#include "Somfy.h"
#include "MQTT.h"
#include "GitOTA.h"
ConfigSettings settings;
Web webServer;
SocketEmitter sockEmit;
Network net;
rebootDelay_t rebootDelay;
SomfyShadeController somfy;
MQTTClass mqtt;
GitUpdater git;
uint32_t oldheap = 0;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Startup/Boot....");
Serial.println("Mounting File System...");
if(LittleFS.begin()) Serial.println("File system mounted successfully");
else Serial.println("Error mounting file system");
settings.begin();
if(WiFi.status() == WL_CONNECTED) WiFi.disconnect(true);
delay(10);
Serial.println();
webServer.startup();
webServer.begin();
delay(1000);
net.setup();
somfy.begin();
//git.checkForUpdate();
esp_task_wdt_init(7, true); //enable panic so ESP32 restarts
esp_task_wdt_add(NULL); //add current thread to WDT watch
}
void loop() {
// put your main code here, to run repeatedly:
//uint32_t heap = ESP.getFreeHeap();
if(rebootDelay.reboot && millis() > rebootDelay.rebootTime) {
Serial.print("Rebooting after ");
Serial.print(rebootDelay.rebootTime);
Serial.println("ms");
net.end();
ESP.restart();
return;
}
uint32_t timing = millis();
net.loop();
if(millis() - timing > 100) Serial.printf("Timing Net: %ldms\n", millis() - timing);
timing = millis();
esp_task_wdt_reset();
somfy.loop();
if(millis() - timing > 100) Serial.printf("Timing Somfy: %ldms\n", millis() - timing);
timing = millis();
esp_task_wdt_reset();
if(net.connected() || net.softAPOpened) {
if(!rebootDelay.reboot && net.connected() && !net.softAPOpened) {
git.loop();
esp_task_wdt_reset();
}
webServer.loop();
esp_task_wdt_reset();
if(millis() - timing > 100) Serial.printf("Timing WebServer: %ldms\n", millis() - timing);
esp_task_wdt_reset();
timing = millis();
sockEmit.loop();
if(millis() - timing > 100) Serial.printf("Timing Socket: %ldms\n", millis() - timing);
esp_task_wdt_reset();
timing = millis();
}
if(rebootDelay.reboot && millis() > rebootDelay.rebootTime) {
net.end();
ESP.restart();
}
esp_task_wdt_reset();
}