-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctx.h
85 lines (82 loc) · 2.83 KB
/
ctx.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
class Ctx {
public:
Ctx() :
mqttPort(1883),
sleepTime(60) {
memset(mqttUser, 0, 128);
memset(mqttPassword, 0, 128);
memset(mqttClientName, 0, 21);
strcpy(mqttUpdateStatusTopic, "stat/display/needUpdate");
strcpy(mqttCommandTopic, "cmd/display/upload");
}
~Ctx() {
if (customMqttServer) {
delete customMqttServer;
}
if (customMqttPort) {
delete customMqttPort;
}
if (customMqttUser) {
delete customMqttUser;
}
if (customMqttPassword) {
delete customMqttPassword;
}
if (customMqttUpdateStatusTopic) {
delete customMqttUpdateStatusTopic;
}
if (customMqttCommandTopic) {
delete customMqttCommandTopic;
}
if (customSleepTime) {
delete customSleepTime;
}
if (customFirmwareUrl) {
delete customFirmwareUrl;
}
}
void initWifiManagerParameters() {
customMqttServer = new WiFiManagerParameter("server", "MQTT server", mqttServer, 40);
itoa(mqttPort, mqttPortAsString, 10);
customMqttPort = new WiFiManagerParameter("port", "MQTT port", mqttPortAsString, 6);
customMqttUser = new WiFiManagerParameter("MQTT user", "MQTT user name", mqttUser, 128);
customMqttPassword = new WiFiManagerParameter("MQTT password", "MQTT password", mqttPassword, 128);
customMqttUpdateStatusTopic = new WiFiManagerParameter("updateTopic", "MQTT update topic", mqttUpdateStatusTopic, 128);
customMqttCommandTopic = new WiFiManagerParameter("commandTopic", "MQTT command topic", mqttCommandTopic, 128);
itoa(sleepTime, sleepTimeAsString, 10);
customSleepTime = new WiFiManagerParameter("sleepTime", "sleep time in seconds", sleepTimeAsString, 33);
customFirmwareUrl = new WiFiManagerParameter("firmwareUrl", "base URL for firmware images", firmwareUrl, 128);
}
void updateParameters() {
strcpy(mqttServer, customMqttServer->getValue());
mqttPort = atoi(customMqttPort->getValue());
strcpy(mqttUser, customMqttUser->getValue());
strcpy(mqttPassword, customMqttPassword->getValue());
strcpy(mqttUpdateStatusTopic, customMqttUpdateStatusTopic->getValue());
strcpy(mqttCommandTopic, customMqttCommandTopic->getValue());
sleepTime = atoi(customSleepTime->getValue());
strcpy(firmwareUrl, customFirmwareUrl->getValue());
}
bool isMqttEnabled() {
return (mqttServer && strlen(mqttServer) > 0);
}
char mqttServer[40];
char mqttPortAsString[6];
int mqttPort;
char mqttUser[128];
char mqttPassword[128];
char mqttClientName[21];
char mqttUpdateStatusTopic[128];
char mqttCommandTopic[128];
char sleepTimeAsString[33];
long sleepTime;
char firmwareUrl[128];
WiFiManagerParameter *customMqttServer;
WiFiManagerParameter *customMqttPort;
WiFiManagerParameter *customMqttUser;
WiFiManagerParameter *customMqttPassword;
WiFiManagerParameter *customMqttUpdateStatusTopic;
WiFiManagerParameter *customMqttCommandTopic;
WiFiManagerParameter *customSleepTime;
WiFiManagerParameter *customFirmwareUrl;
};