Skip to content

Commit 241c45b

Browse files
committed
Add will
1 parent 77ba4ed commit 241c45b

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

ToDo.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22

33
## Improvements
44

5-
Change MqttMap to include reference to mqttclient
5+
### Change MqttMap to include reference to mqttclient
66
* Change loop, publish, ... to not need mqttclient
77

8-
Add easyMqtt/$id/system/connected + will to indicate if device is online
8+
### Add easyMqtt/$id/system/connected + will to indicate if device is online
99

1010
## Future
1111

12-
Add system info
12+
### Add system info
1313
* easyMqtt/$id/system/uptime
1414
* easyMqtt/$id/system/mem
1515
* easyMqtt/$id/system/reset
1616
* easyMqtt/$id/system/debug
1717
* easyMqtt/$id/system/config
1818

19-
Add better debugging
19+
### Add better debugging
2020
* Add new EasyDebug class, extends Print (Print.h), and prints to easyMqtt/$id/system/debug if enabled
2121
* Add getDebugger on EasyMqtt that returns the EasyDebug instance
2222

23-
Add support for filters
23+
### Add support for filters
2424
* Don't send if value is the same as last.
2525
* Don't send if value is Nan
2626

27-
Add support for float type (extend MqttMap)
27+
### Add support for float type (extend MqttMap)
2828

29-
Add publish configured endpoints, to support openhab2 auto configure
29+
### Add publish configured endpoints, to support openhab2 auto configure
3030
something like
3131
easyMqtt/$id/system/config
3232
{
@@ -36,3 +36,27 @@ easyMqtt/$id/system/config
3636
}
3737

3838
Read / Write / String / Number / ...
39+
40+
### Add config values
41+
Add config values that is persisted to flash memory
42+
43+
http://esp8266.github.io/Arduino/versions/2.0.0/doc/filesystem.html
44+
45+
```C++
46+
#include <EasyMqtt.h>
47+
48+
EasyMqtt mqtt;
49+
50+
setup() {
51+
// init config with name "test" with default value 123
52+
// The value can be changed using easyMqtt/$id/config/test
53+
// Is loaded from
54+
mqtt.config("timeout", 5000);
55+
}
56+
57+
loop() {
58+
mqtt.loop();
59+
mqtt.config("timeout"); // Read back config value
60+
}
61+
62+
```

src/EasyMqtt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ class EasyMqtt : public MqttMap {
2424
*/
2525
void mqttReconnect() {
2626
while (!mqttClient.connected()) {
27-
if (mqttClient.connect(deviceId.c_str(), mqtt_username, mqtt_password)) {
27+
if (mqttClient.connect(deviceId.c_str(), mqtt_username, mqtt_password), get("system")["connected"].getTopic().c_str(), 2, 0, "false") {
2828
debug("Connected to MQTT");
2929
subscribe();
30+
get("system")["connected"].publish("true");
3031
} else {
3132
Serial.print("failed, rc=");
3233
Serial.print(mqttClient.state());

0 commit comments

Comments
 (0)