This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ehsensor.ino
119 lines (111 loc) · 2.13 KB
/
ehsensor.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// ehsensor
// Home automation solution
//
// ESP8266 ModBus TCP Slave Device
//
#define VERSION "0.1.2"
#ifdef ESP8266
#define PIN_ACT D4
#define BUSY digitalWrite(PIN_ACT, LOW);
#define IDLE digitalWrite(PIN_ACT, HIGH);
#define OW_PIN D2
#define PIN_LED D0
#define PIN_KEY 0
#else
#define PIN_ACT TX
#define BUSY digitalWrite(PIN_ACT, LOW);
#define IDLE digitalWrite(PIN_ACT, HIGH);
#define OW_PIN 2
#define PIN_LED TX
#define PIN_KEY 0
#endif
#define DEFAULT_NAME "ehsensor8"
#define NTP1 "192.168.30.30"
#define NTP2 ""
#define NTP3 ""
#define TZ 5
#define DEFAULT_ADMIN_NAME "admin"
#define DEFAULT_PASSWORD "password3"
String adminUsername = DEFAULT_ADMIN_NAME;
String adminPassword = DEFAULT_PASSWORD;
String name = DEFAULT_NAME;
String ntp[3] {NTP1, NTP2, NTP3};
int8_t tz = TZ;
struct events {
uint16_t webReady;
uint16_t ntpReady;
uint16_t wifiReady;
};
template <typename T>
class SReg {
public:
T val;
uint16_t event = 0;
void set(T v) {
val = v;
age = 0;
event++;
}
T get() {
return val;
}
String toString() {
return String(val);
}
uint16_t getAge() {
return age;
}
bool isValid() {
return true;
}
private:
uint16_t age = 0xFFFF;
};
#define REG_COUNT 32
SReg<int> iReg[REG_COUNT];
SReg<float> fReg[REG_COUNT];
events event = {0};
#ifdef ESP8266
#include <FS.h>
#else
#include <SPIFFS.h>
#endif
#include <Run.h>
#include "wifi.h"
#include "web.h"
#include "update.h"
#include "ds1820.h"
#include "modbus.h"
uint32_t restartESP() {
ESP.restart();
return RUN_DELETE;
}
uint32_t formatSPIFFS() {
SPIFFS.end();
SPIFFS.format();
SPIFFS.begin();
return RUN_DELETE;
}
uint32_t global() {
SPIFFS.begin();
return RUN_DELETE;
}
void setup(void)
{
#ifdef ESP8266
Serial.begin(74880);
#else
Serial.begin(115200);
#endif
taskAdd(wifiInit); // Connect to WiFi network & Start discovery services
taskAdd(global);
taskAdd(modbusInit); // Strat ModBus Slave
taskAdd(dsInit); // Start 1-Wire temperature sensors
taskAdd(webInit); // Start Web-server
taskAdd(updateInit); // Add update service
}
void loop() {
taskExec();
yield();
}