|
@@ -49,6 +49,10 @@ PubSubClient mqtt(mqttClient);
|
49
|
49
|
static unsigned long last_mqtt_reconnect_time = 0;
|
50
|
50
|
static unsigned long last_mqtt_write_time = 0;
|
51
|
51
|
|
|
52
|
+#ifdef FEATURE_UI
|
|
53
|
+static struct ui_status prev_status = ui_status;
|
|
54
|
+#endif // FEATURE_UI
|
|
55
|
+
|
52
|
56
|
static void writeMQTT() {
|
53
|
57
|
if (!mqtt.connected()) {
|
54
|
58
|
return;
|
|
@@ -117,73 +121,44 @@ static void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
117
|
121
|
} else if (ps.indexOf("none") != -1) {
|
118
|
122
|
state = 4;
|
119
|
123
|
} else {
|
|
124
|
+ debug.println(F("parse abort"));
|
120
|
125
|
return;
|
121
|
126
|
}
|
122
|
127
|
#endif
|
123
|
128
|
|
124
|
|
-#ifdef FEATURE_RELAIS
|
125
|
|
- int id = -1;
|
126
|
|
-
|
127
|
|
- String our_topic(SENSOR_LOCATION);
|
128
|
|
- our_topic += "/";
|
129
|
|
-
|
130
|
|
- if (!ts.startsWith(our_topic)) {
|
131
|
|
- debug.print(F("Unknown MQTT room "));
|
132
|
|
- debug.println(ts);
|
133
|
|
- return;
|
134
|
|
- }
|
135
|
|
-
|
136
|
|
- String ids = ts.substring(our_topic.length());
|
137
|
|
- for (int i = 0; i < relais_count(); i++) {
|
138
|
|
- if (ids == relais_name(i)) {
|
139
|
|
- id = i;
|
140
|
|
- break;
|
141
|
|
- }
|
142
|
|
- }
|
143
|
|
-
|
144
|
|
- if (id < 0) {
|
145
|
|
- debug.print(F("Unknown MQTT topic "));
|
146
|
|
- debug.println(ts);
|
147
|
|
- return;
|
148
|
|
- }
|
149
|
|
-
|
150
|
|
- if ((id >= 0) && (id < relais_count())) {
|
151
|
|
- debug.print(F("Turning "));
|
152
|
|
- debug.print(state ? "on" : "off");
|
153
|
|
- debug.print(F(" relais "));
|
154
|
|
- debug.println(id);
|
155
|
|
-
|
156
|
|
- relais_set(id, state);
|
157
|
|
-
|
158
|
|
- writeDatabase();
|
159
|
|
- }
|
160
|
|
-#endif // FEATURE_RELAIS
|
161
|
|
-
|
162
|
129
|
#ifdef FEATURE_UI
|
163
|
130
|
// store new topic values for display
|
164
|
131
|
if (ts == "livingroom/light_kitchen") {
|
165
|
132
|
ui_status.light_kitchen = state ? true : false;
|
|
133
|
+ prev_status.light_kitchen = ui_status.light_kitchen;
|
166
|
134
|
ui_progress(UI_UPDATE);
|
167
|
135
|
} else if (ts == "livingroom/light_pc") {
|
168
|
136
|
ui_status.light_pc = state ? true : false;
|
|
137
|
+ prev_status.light_pc = ui_status.light_pc;
|
169
|
138
|
ui_progress(UI_UPDATE);
|
170
|
139
|
} else if (ts == "livingroom/light_bench") {
|
171
|
140
|
ui_status.light_bench = state ? true : false;
|
|
141
|
+ prev_status.light_bench = ui_status.light_bench;
|
172
|
142
|
ui_progress(UI_UPDATE);
|
173
|
143
|
} else if (ts == "livingroom/light_amp") {
|
174
|
144
|
ui_status.light_amp = state ? true : false;
|
|
145
|
+ prev_status.light_amp = ui_status.light_amp;
|
175
|
146
|
ui_progress(UI_UPDATE);
|
176
|
147
|
} else if (ts == "livingroom/light_box") {
|
177
|
148
|
ui_status.light_box = state ? true : false;
|
|
149
|
+ prev_status.light_box = ui_status.light_box;
|
178
|
150
|
ui_progress(UI_UPDATE);
|
179
|
151
|
} else if (ts == "livingroom/light_corner/cmnd/POWER") {
|
180
|
|
- ui_status.light_corner = state ? true: false;
|
|
152
|
+ ui_status.light_corner = state ? true : false;
|
|
153
|
+ prev_status.light_corner = ui_status.light_corner;
|
181
|
154
|
ui_progress(UI_UPDATE);
|
182
|
155
|
} else if (ts == "livingroom/workbench/cmnd/POWER") {
|
183
|
156
|
ui_status.light_workspace = state ? true : false;
|
|
157
|
+ prev_status.light_workspace = ui_status.light_workspace;
|
184
|
158
|
ui_progress(UI_UPDATE);
|
185
|
159
|
} else if (ts == "livingroom/amp/cmnd/POWER") {
|
186
|
160
|
ui_status.sound_amplifier = state ? true : false;
|
|
161
|
+ prev_status.sound_amplifier = ui_status.sound_amplifier;
|
187
|
162
|
ui_progress(UI_UPDATE);
|
188
|
163
|
} else if (ts == "bathroom/force_light") {
|
189
|
164
|
if (state == 0) {
|
|
@@ -197,9 +172,48 @@ static void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
197
|
172
|
} else if (state == 4) {
|
198
|
173
|
ui_status.bathroom_lights = BATH_LIGHT_NONE;
|
199
|
174
|
}
|
|
175
|
+ prev_status.bathroom_lights = ui_status.bathroom_lights;
|
200
|
176
|
ui_progress(UI_UPDATE);
|
201
|
177
|
}
|
202
|
178
|
#endif // FEATURE_UI
|
|
179
|
+
|
|
180
|
+#ifdef FEATURE_RELAIS
|
|
181
|
+ int id = -1;
|
|
182
|
+
|
|
183
|
+ String our_topic(SENSOR_LOCATION);
|
|
184
|
+ our_topic += "/";
|
|
185
|
+
|
|
186
|
+ if (!ts.startsWith(our_topic)) {
|
|
187
|
+ debug.print(F("Unknown MQTT room "));
|
|
188
|
+ debug.println(ts);
|
|
189
|
+ return;
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ String ids = ts.substring(our_topic.length());
|
|
193
|
+ for (int i = 0; i < relais_count(); i++) {
|
|
194
|
+ if (ids == relais_name(i)) {
|
|
195
|
+ id = i;
|
|
196
|
+ break;
|
|
197
|
+ }
|
|
198
|
+ }
|
|
199
|
+
|
|
200
|
+ if (id < 0) {
|
|
201
|
+ debug.print(F("Unknown MQTT topic "));
|
|
202
|
+ debug.println(ts);
|
|
203
|
+ return;
|
|
204
|
+ }
|
|
205
|
+
|
|
206
|
+ if ((id >= 0) && (id < relais_count())) {
|
|
207
|
+ debug.print(F("Turning "));
|
|
208
|
+ debug.print(state ? "on" : "off");
|
|
209
|
+ debug.print(F(" relais "));
|
|
210
|
+ debug.println(id);
|
|
211
|
+
|
|
212
|
+ relais_set(id, state);
|
|
213
|
+
|
|
214
|
+ writeDatabase();
|
|
215
|
+ }
|
|
216
|
+#endif // FEATURE_RELAIS
|
203
|
217
|
}
|
204
|
218
|
|
205
|
219
|
static void mqttReconnect() {
|
|
@@ -259,7 +273,6 @@ void runMQTT() {
|
259
|
273
|
}
|
260
|
274
|
|
261
|
275
|
#ifdef FEATURE_UI
|
262
|
|
-static struct ui_status prev_status = ui_status;
|
263
|
276
|
|
264
|
277
|
static void mqttPublish(const char* ts, const char *ps, bool retained) {
|
265
|
278
|
debug.print(F("MQTT Tx> @ \""));
|