| LightHub v4.0.0 Smarthome controller firmware

main.h
Go to the documentation of this file.
1 #pragma once
2
3 #include "options.h"
4
5 #if defined(M5STACK)
6 #include <M5Stack.h>
7 #endif
8
9 #if defined(__SAM3X8E__)
10 #include <watchdog.h>
11 #include <ArduinoHttpClient.h>
12 //#include "TimerInterrupt_Generic.h"
13 #endif
14
15 #if defined(ARDUINO_ARCH_AVR)
16 #include "HTTPClient.h"
17 //#include <ArduinoHttpClient.h>
18 #include <avr/pgmspace.h>
19 #include <avr/wdt.h>
20 #endif
21
22 #if defined(ARDUINO_ARCH_ESP8266)
23 #include <FS.h> //this needs to be first, or it all crashes and burns...
24 #ifndef FS_STORAGE
25 #include <ESP_EEPROM.h>
26 #endif
27 //#include <ESP8266HTTPClient.h>
28 //#include <ArduinoHttpClient.h>
29 //#include "HttpClient.h"
30 //#include <WiFiManager.h>
31 //#include <DNSServer.h>
32 //#include <ESP8266WebServer.h>
33 //#include <ESP8266WiFi.h>
34 #include <user_interface.h>
35 //#define Ethernet WiFi
36 #endif
37
38 #if defined ARDUINO_ARCH_ESP32
39 #include <FS.h> //this needs to be first, or it all crashes and burns...
40 //#include "SPIFFS.h"
41 //#include <EEPROM.h>
42 //#include <NRFFlashStorage.h>
43 //#include "HttpClient.h"
44 //#include <ArduinoHttpClient.h>
45 //#include <HTTPClient.h>
46 //#include <WiFi.h>
47 //#include <WiFiClient.h>
48 //#include <WiFiClientSecure.h>
49 //#include <WebServer.h>
50 //#include <WiFiManager.h>
51 //include <DNSServer.h>
52
53 //#define Ethernet WiFi
54 #endif
55
56 #ifdef NRF5
57 //#include <NRFFlashStorage.h>
58 #include <ArduinoHttpClient.h>
59 #endif
60
61 #ifdef ARDUINO_ARCH_STM32
62 #include "HttpClient.h"
63 //#include "UIPEthernet.h"
64 //#include <NRFFlashStorage.h>
65 //#include <EEPROM.h>
66 #endif
67
68 #include "streamlog.h"
69 extern Streamlog debugSerial;
70 extern Streamlog infoSerial;
71 extern Streamlog errorSerial;
72
73 #if defined(__SAM3X8E__)
74 #define wdt_res() watchdogReset()
75 #define wdt_en()
76 #define wdt_dis()
77 #endif
78
79 //#ifndef DHCP_RETRY_INTERVAL
80 //#define DHCP_RETRY_INTERVAL 60000
81 //#endif
82
83 #if defined(ESP8266)
84 #define wdt_en() wdt_enable(WDTO_8S)
85 #define wdt_dis() wdt_disable()
86 #define wdt_res() wdt_reset()
87 #endif
88
89 #ifdef ARDUINO_ARCH_ESP32
90 #define wdt_res()
91 #define wdt_en()
92 #define wdt_dis()
93 #endif
94
95 #if defined(NRF5)
96 #define wdt_res()
97 #define wdt_en()
98 #define wdt_dis()
99 #endif
100
101 #if defined(ARDUINO_ARCH_STM32)
102 #define wdt_res()
103 #define wdt_en()
104 #define wdt_dis()
105 #endif
106
107 //#if defined(ESP8266)
108 //#define wdt_res()
109 //#define wdt_en()
110 //#define wdt_dis()
111 //#endif
112 #if defined(ARDUINO_ARCH_AVR)
113 #if defined(WATCH_DOG_TICKER_DISABLE)
114 #define wdt_en() wdt_disable()
115 #define wdt_dis() wdt_disable()
116 #define wdt_res() wdt_disable()
117 #else
118 #define wdt_en() wdt_enable(WDTO_8S)
119 #define wdt_dis() wdt_disable()
120 #define wdt_res() wdt_reset()
121 #endif
122 #endif
123
124 #ifndef OWIRE_DISABLE
125 #include "DallasTemperature.h"
126 #endif
127
128 #ifdef _modbus
129 #include <ModbusMaster.h>
130 #endif
131
132 #ifdef _owire
133 #include "owTerm.h"
134 #endif
135
136 #if defined(_dmxin) || defined(_dmxout) || defined (_artnet)
137 #include "dmx.h"
138 #endif
139
140 #ifdef WIFI_ENABLE
141
142 #if defined(ARDUINO_ARCH_ESP32)
143 #include <WiFi.h>
144 #include <HTTPClient.h>
145 #include <WiFiClient.h>
146 #include <WiFiClientSecure.h>
147 #include <WiFiManager.h>
148 #include <WebServer.h>
149 #include <ESPmDNS.h>
150 #else
151 #include <ESP8266WiFi.h>
152 #include <ESP8266HTTPClient.h>
153 #include <WiFiManager.h>
154 #include <DNSServer.h>
155 #include <ESP8266WebServer.h>
156 #include <ESP8266mDNS.h>
157 #endif
158 #define Ethernet WiFi
159 #else //Wired connection
160 #ifdef Wiz5500
161 #include <Ethernet2.h>
162 #else
163 #ifdef UIPETHERNET
164 #include "UIPEthernet.h"
165 #else
166 #include <Ethernet.h>
167 #endif
168 #endif
169 #endif
170
171
172 #ifdef _artnet
173 #include <Artnet.h>
174 #endif
175
176 #ifdef SD_CARD_INSERTED
177 #include "sd_card_w5100.h"
178 #endif
179
180 #ifdef MDNS_ENABLE
181 #ifndef WIFI_ENABLE
182 #include <ArduinoMDNS.h>
183 #endif
184 #endif
185
186 #include "Arduino.h"
187 #include "utils.h"
188 #include "textconst.h"
189 #include <PubSubClient.h>
190 #include <SPI.h>
191 #include <string.h>
192 #include "aJSON.h"
193 #include <Cmd.h>
194 #include "stdarg.h"
195 #include "item.h"
196 #include "inputs.h"
197
198 #ifdef _artnet
199 extern Artnet *artnet;
200 #endif
201
202 enum lan_status {
203 INITIAL_STATE = 0,
204 AWAITING_ADDRESS = 1,
205 HAVE_IP_ADDRESS = 2,
206 LIBS_INITIALIZED = 3,
207 IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER = 4,
208 RETAINING_COLLECTING = 5,
209 OPERATION = 6,
210 OPERATION_NO_MQTT = 7,
211 DO_REINIT = -10,
212 REINIT = - 11,
213 DO_RECONNECT = 12,
214 RECONNECT = 13,
215 READ_RE_CONFIG = 14,
216 DO_READ_RE_CONFIG = 15,
217 DO_NOTHING = -15
218 };
219
220 extern lan_status lanStatus;
221
222 typedef union {
223 uint32_t UID_Long[5];
224 uint8_t UID_Byte[20];
225 } UID;
226
227 bool isNotRetainingStatus();
228
229 void mqttCallback(char *topic, byte *payload, unsigned int length);
230
231 void printMACAddress();
232
233 lan_status lanLoop();
234
235 #ifndef OWIRE_DISABLE
236 void Changed(int i, DeviceAddress addr, float currentTemp);
237 #endif
238
239 void modbusIdle(void);
240
241 int cmdFunctionHelp(int arg_cnt, char **args);
242
243 int cmdFunctionKill(int arg_cnt, char **args);
244
245 void applyConfig();
246
247 int cmdFunctionLoad(int arg_cnt, char **args);
248
249 int loadConfigFromEEPROM();
250
251 int cmdFunctionSave(int arg_cnt, char **args);
252
253 int cmdFunctionSetMac(int arg_cnt, char **args);
254
255 int cmdFunctionGet(int arg_cnt, char **args);
256
257 int cmdFunctionLoglevel(int arg_cnt, char **args);
258
259 void printBool(bool arg);
260 /*
261 void saveFlash(short n, char *str);
262
263 int loadFlash(short n, char *str, short l=MAXFLASHSTR);
264
265 void saveFlash(short n, IPAddress& ip);
266
267 int ipLoadFromFlash(short n, IPAddress &ip);
268 */
269
270 int loadConfigFromHttp();
271
272 void preTransmission();
273
274 void postTransmission();
275
276 void setup_main();
277
278 void loop_main();
279
280 void owIdle(void);
281
282 void modbusIdle(void);
283
284 void inputLoop(short);
285
286 void inputSetup(void);
287
288 void pollingLoop(void);
289
290 void thermoLoop(void);
291
292 short thermoSetCurTemp(char *name, float t);
293
294 void modbusIdle(void);
295
296 void printConfigSummary();
297
298 void setupCmdArduino();
299
300 void setupMacAddress();
301
302 void printFirmwareVersionAndBuildOptions();
303
304 bool IsThermostat(const aJsonObject *item);
305
306 bool disabledDisconnected(const aJsonObject *thermoExtensionArray, int thermoLatestCommand);
307
308 void resetHard();
309
310 void onInitialStateInitLAN();
311
312 void ip_ready_config_loaded_connecting_to_broker();
313
314 void printCurentLanConfig();
315
316 //void printFreeRam();
ip_ready_config_loaded_connecting_to_broker
void ip_ready_config_loaded_connecting_to_broker()
Definition: main.cpp:864
modbusIdle
void modbusIdle(void)
Definition: main.cpp:2406
owTerm.h
DO_NOTHING
@ DO_NOTHING
Definition: main.h:217
printMACAddress
void printMACAddress()
Definition: main.cpp:435
setupMacAddress
void setupMacAddress()
Definition: main.cpp:2263
REINIT
@ REINIT
Definition: main.h:212
RETAINING_COLLECTING
@ RETAINING_COLLECTING
Definition: main.h:208
cmdFunctionLoad
int cmdFunctionLoad(int arg_cnt, char **args)
Definition: main.cpp:1386
inputLoop
void inputLoop(short)
Definition: main.cpp:2443
IsThermostat
bool IsThermostat(const aJsonObject *item)
errorSerial
Streamlog errorSerial
options.h
IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER
@ IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER
Definition: main.h:207
printConfigSummary
void printConfigSummary()
Definition: main.cpp:1354
OPERATION_NO_MQTT
@ OPERATION_NO_MQTT
Definition: main.h:210
OPERATION
@ OPERATION
Definition: main.h:209
dmx.h
AWAITING_ADDRESS
@ AWAITING_ADDRESS
Definition: main.h:204
onInitialStateInitLAN
void onInitialStateInitLAN()
Definition: main.cpp:981
printCurentLanConfig
void printCurentLanConfig()
Definition: main.cpp:1191
textconst.h
printBool
void printBool(bool arg)
Definition: main.cpp:1639
lan_status
lan_status
Definition: main.h:202
utils.h
INITIAL_STATE
@ INITIAL_STATE
Definition: main.h:203
thermoSetCurTemp
short thermoSetCurTemp(char *name, float t)
mqttCallback
void mqttCallback(char *topic, byte *payload, unsigned int length)
Definition: main.cpp:370
setup_main
void setup_main()
Definition: main.cpp:1941
cmdFunctionLoglevel
int cmdFunctionLoglevel(int arg_cnt, char **args)
Definition: main.cpp:1479
setupCmdArduino
void setupCmdArduino()
Definition: main.cpp:2295
LIBS_INITIALIZED
@ LIBS_INITIALIZED
Definition: main.h:206
cmdFunctionKill
int cmdFunctionKill(int arg_cnt, char **args)
Definition: main.cpp:1202
RECONNECT
@ RECONNECT
Definition: main.h:214
loop_main
void loop_main()
Definition: main.cpp:2316
streamlog.h
printFirmwareVersionAndBuildOptions
void printFirmwareVersionAndBuildOptions()
Definition: main.cpp:2062
preTransmission
void preTransmission()
Definition: main.cpp:1894
Changed
void Changed(int i, DeviceAddress addr, float currentTemp)
Definition: main.cpp:1115
owIdle
void owIdle(void)
Definition: main.cpp:2377
DO_READ_RE_CONFIG
@ DO_READ_RE_CONFIG
Definition: main.h:216
infoSerial
Streamlog infoSerial
loadConfigFromHttp
int loadConfigFromHttp()
Definition: main.cpp:1653
Streamlog
Definition: streamlog.h:32
applyConfig
void applyConfig()
Definition: main.cpp:1216
inputs.h
debugSerial
Streamlog debugSerial
lanLoop
lan_status lanLoop()
Definition: main.cpp:523
cmdFunctionHelp
int cmdFunctionHelp(int arg_cnt, char **args)
Definition: main.cpp:1171
cmdFunctionGet
int cmdFunctionGet(int arg_cnt, char **args)
Definition: main.cpp:1599
READ_RE_CONFIG
@ READ_RE_CONFIG
Definition: main.h:215
pollingLoop
void pollingLoop(void)
Definition: main.cpp:2523
UID
Definition: main.h:222
cmdFunctionSetMac
int cmdFunctionSetMac(int arg_cnt, char **args)
Definition: main.cpp:1586
loadConfigFromEEPROM
int loadConfigFromEEPROM()
Definition: main.cpp:1397
isNotRetainingStatus
bool isNotRetainingStatus()
Definition: main.cpp:224
lanStatus
lan_status lanStatus
Definition: main.cpp:80
thermoLoop
void thermoLoop(void)
Definition: main.cpp:2593
resetHard
void resetHard()
Definition: main.cpp:1100
disabledDisconnected
bool disabledDisconnected(const aJsonObject *thermoExtensionArray, int thermoLatestCommand)
postTransmission
void postTransmission()
Definition: main.cpp:1903
inputSetup
void inputSetup(void)
Definition: main.cpp:2503
cmdFunctionSave
int cmdFunctionSave(int arg_cnt, char **args)
Definition: main.cpp:1434
HAVE_IP_ADDRESS
@ HAVE_IP_ADDRESS
Definition: main.h:205
DO_REINIT
@ DO_REINIT
Definition: main.h:211
item.h
DO_RECONNECT
@ DO_RECONNECT
Definition: main.h:213