-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodbus-SmartHome.ino
104 lines (95 loc) · 1.89 KB
/
modbus-SmartHome.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
//////////////////////////////////////////
// ESP8266/ESP32 Modbus SmartHome Device
// (c)2018, [email protected]
//
#define VERSION "0.2 - " __DATE__
#define SERIAL
//#define WS2812
#define LCD
//#define JSONRPC
#define HOMEKIT
#define DS1820
#define MEM_LOW 4096
#define DEFAULT_NAME "mbh1"
#define DEFAULT_PASSWORD "P@ssw0rd"
#define TDEBUG(format, ...) // Serial.printf_P(PSTR(format), ##__VA_ARGS__);
#define BUSY ;
#define IDLE ;
String sysName = DEFAULT_NAME;
String sysPassword = DEFAULT_PASSWORD;
#ifdef ESP8266
#include <FS.h>
#include <ModbusIP_ESP8266.h>
#else
#include <SPIFFS.h>
#endif
#include "cli.h"
#include "gpio.h"
#include "mb.h"
#include "update.h"
#include "web.h"
#include "wifi.h"
#include <Run.h>
#if defined(DS1820)
#include "ds1820.h"
#endif
#if defined(WS2812) && defined(ESP8266)
#undef SERIAL
#include "leds.h"
#endif
#if defined(LCD)
#include "lcd.h"
#endif
#if defined(JSONRPC)
#include "jsonrpc.h"
#endif
#if defined(HOMEKIT)
#include "homekit.h"
#endif
ModbusIP *mb;
uint32_t mem = 0;
uint32_t tm = 0;
uint32_t restartESP() {
ESP.restart();
return RUN_DELETE;
}
uint32_t watchDog() {
if (ESP.getFreeHeap() < MEM_LOW)
ESP.restart();
return 10000;
}
void setup(void) {
#if defined(SERIAL)
#if defined(ESP32)
Serial.begin(115200);
#else
Serial.begin(74880);
#endif
#endif
SPIFFS.begin();
wifiInit(); // Connect to WiFi network & Start discovery services
webInit(); // Start Web-server
modbusInit(); // Initialize Modbus subsystem
taskAdd(cliInit);
taskAdd(updateInit);
#if defined(DS1820)
taskAdd(dsInit); // Start 1-Wire temperature sensors
#endif
taskAdd(gpioInit);
#if defined(WS2812) && defined(ESP8266)
taskAdd(ledsInit); // WS2812 led stripes
#endif
#if defined(JSONRPC)
taskAdd(jsonRpcInit);
#endif
#if defined(HOMEKIT)
taskAdd(homekitInit);
#endif
#if defined(LCD)
taskAdd(lcdInit);
#endif
}
void loop() {
taskExec();
yield();
}