File tree Expand file tree Collapse file tree 4 files changed +25
-4
lines changed Expand file tree Collapse file tree 4 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -16,10 +16,14 @@ class ConfigEntry : public MqttEntry {
16
16
return get (key).getValue ();
17
17
}
18
18
19
+ void reset () {
20
+ SPIFFS.remove (" /config.cfg" );
21
+ }
22
+
19
23
protected:
20
24
String getKey (MqttEntry* entry) {
21
25
String key = entry->getTopic ();
22
- key.replace (getTopic (), " " );
26
+ key.replace (getTopic () + " / " , " " );
23
27
key.replace (" /" , " ." );
24
28
return key;
25
29
}
@@ -45,12 +49,17 @@ class ConfigEntry : public MqttEntry {
45
49
}
46
50
47
51
void store () {
52
+ Serial.println (" store" );
48
53
File f = SPIFFS.open (" /config.cfg" , " w" );
49
54
if (f) {
50
55
each ([&](MqttEntry* entry) {
51
- f.println (toString (entry).c_str ());
56
+ if (entry->getTopic () != getTopic ()) {
57
+ f.println (toString (entry).c_str ());
58
+ }
52
59
});
53
60
f.close ();
61
+ } else {
62
+ Serial.println (" Failed to store config" );
54
63
}
55
64
}
56
65
};
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ class EasyMqtt : public MqttEntry {
24
24
Handle connections to mqtt
25
25
*/
26
26
void mqttReconnect () {
27
+ // if(WiFi.status() != WL_CONNECTED) {
27
28
while (!mqttClient.connected ()) {
28
29
if (mqttClient.connect (deviceId.c_str (), mqtt_username, mqtt_password)) {
29
30
debug (" Connected to MQTT" );
@@ -41,12 +42,17 @@ class EasyMqtt : public MqttEntry {
41
42
42
43
public:
43
44
EasyMqtt () : MqttEntry(" easyMqtt" , mqttClient) {
45
+ Serial.begin (115200 );
44
46
deviceId = String (ESP.getChipId ());
45
47
48
+ debug (" test" );
46
49
config = new ConfigEntry (mqttClient, *this );
47
50
addChild (config);
48
51
49
52
get (" system" ).setInterval (30 );
53
+ get (" system" )[" deviceId" ] << [this ]() {
54
+ return deviceId;
55
+ };
50
56
get (" system" )[" mem" ][" heap" ] << []() {
51
57
return String (ESP.getFreeHeap ());
52
58
};
@@ -59,6 +65,11 @@ class EasyMqtt : public MqttEntry {
59
65
ESP.restart ();
60
66
}
61
67
};
68
+ get (" system" )[" config" ][" reset" ] >> [this ](String value) {
69
+ if (value == " reset" ) {
70
+ getConfig ()->reset ();
71
+ }
72
+ };
62
73
}
63
74
64
75
ConfigEntry* getConfig () {
Original file line number Diff line number Diff line change 7
7
8
8
class MqttEntry {
9
9
private:
10
- std::function<void (String payload )> outFunction = NULL ;
10
+ std::function<void (String)> outFunction = NULL ;
11
11
std::function<String()> inFunction = NULL ;
12
+ std::function<void (MqttEntry*, String)> publishFunction = NULL ;
12
13
13
14
char * name = " N/A" ;
14
15
int force = 0 ;
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ class WebPortal {
81
81
}
82
82
});
83
83
page += FPSTR (HTML_FOOTER2);
84
- // page.replace("{device_id}", mqtt->getDeviceId ());
84
+ page.replace (" {device_id}" , mqtt->get ( " system/deviceId " ). getValue ());
85
85
page.replace (" {topic}" , mqtt->getTopic ());
86
86
webServer->send (200 , " text/html" , page);
87
87
}
You can’t perform that action at this time.
0 commit comments