forked from jnsbyr/esp8266-intexsbh20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
138 lines (120 loc) · 3.43 KB
/
common.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
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
/*
* project: Intex PureSpa SB-H20 WiFi Controller
*
* file: common.h
*
* encoding: UTF-8
* created: 13th March 2021
*
* Copyright (C) 2021 Jens B.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
#ifndef COMMON_H
#define COMMON_H
#include <limits.h>
#include <../d1_mini/pins_arduino.h>
//#define SERIAL_DEBUG
namespace CONFIG
{
const char POOL_MODEL_NAME[] = "Intex PureSpa SB-H20";
const char WIFI_VERSION[] = "1.0.0.0"; // 01.04.2021
// WiFi parameters
const unsigned long WIFI_MAX_DISCONNECT_DURATION = 900000; // [ms] 5 min until reboot
// MQTT publish rates
const unsigned int POOL_UPDATE_PERIOD = 500; // [ms]
const unsigned int WIFI_UPDATE_PERIOD = 30000; // [ms] 30 sec
const unsigned int FORCED_STATE_UPDATE_PERIOD = 10000; // [ms] 10 sec
}
// Config File Tags
namespace CONFIG_TAG
{
const char FILENAME[] = "config.json";
const char WIFI_SSID[] = "wifiSSID";
const char WIFI_PASSPHRASE[] = "wifiPassphrase";
const char WIFI_OTA_URL[] = "firmwareURL";
const char MQTT_SERVER[] = "mqttServer";
const char MQTT_ERROR_LANG[] = "errorLanguage";
};
// MQTT topics
namespace MQTT_TOPIC
{
// publish
const char BUBBLE[] = "pool/bubble";
const char ERROR[] = "pool/error";
const char FILTER[] = "pool/filter";
const char HEATER[] = "pool/heater";
const char MODEL[] = "pool/model";
const char POWER[] = "pool/power";
const char WATER_ACT[] = "pool/water/tempAct";
const char WATER_SET[] = "pool/water/tempSet";
const char VERSION[] = "wifi/version";
const char IP[] = "wifi/ip";
const char RSSI[] = "wifi/rssi";
const char WIFI_TEMP[] = "wifi/temp";
const char STATE[] = "wifi/state";
const char OTA[] = "wifi/update";
// subscribe
const char CMD_BUBBLE[] = "pool/command/bubble";
const char CMD_FILTER[] = "pool/command/filter";
const char CMD_HEATER[] = "pool/command/heater";
const char CMD_POWER[] = "pool/command/power";
const char CMD_WATER[] = "pool/command/water/tempSet";
const char CMD_OTA[] = "wifi/command/update";
}
// Languages
enum class LANG
{
CODE = 0, EN = 1, DE = 2
};
// ESP8266 pins
namespace PIN
{
const uint8 CLOCK = D5;
const uint8 DATA = D6;
const uint8 LATCH = D7;
}
// serial debugging
#ifdef SERIAL_DEBUG
#define DEBUG_MSG(...) Serial.printf( __VA_ARGS__ )
#else
#define DEBUG_MSG(...)
#endif
// time delta with overflow support
static unsigned long timeDiff(unsigned long newTime, unsigned long oldTime)
{
if (newTime >= oldTime)
{
return newTime - oldTime;
}
else
{
return ULONG_MAX - oldTime + newTime + 1;
}
}
// unsigned int delta with overflow support
static unsigned long diff(unsigned int newVal, unsigned int oldVal)
{
if (newVal >= oldVal)
{
return newVal - oldVal;
}
else
{
return UINT_MAX - oldVal + newVal + 1;
}
}
#endif /* COMMON_H */