File tree Expand file tree Collapse file tree 4 files changed +28
-23
lines changed Expand file tree Collapse file tree 4 files changed +28
-23
lines changed Original file line number Diff line number Diff line change 1
1
# EasyMqtt
2
2
Easy handling of Mqtt on esp8266
3
3
4
- * Easy wifi configuration
5
- * Easy mqtt configuration
4
+ * Easy wifi configuration using web interface
5
+ * Easy mqtt configuration using web interface
6
6
* Easy configuration of mqtt endpoints
7
7
* Web based UI to see current values
8
8
@@ -13,14 +13,10 @@ Easy handling of Mqtt on esp8266
13
13
EasyMqtt mqtt;
14
14
15
15
void setup () {
16
- // Setup wifi
17
- mqtt.wifi("ssid", "password");
18
- mqtt.mqtt("host", 1883, "user", "pass");
19
-
20
- mqtt.config().setString("foo", "My Foo");
16
+ mqtt.config().set("foo", "My Foo");
21
17
22
- mqtt[ "foo"] << [ ] ( ) {
23
- return mqtt.config().getString ("foo");
18
+ mqtt[ "foo"] << [ & ] ( ) {
19
+ return String( mqtt.config().get ("foo", "default") );
24
20
};
25
21
}
26
22
Original file line number Diff line number Diff line change @@ -9,22 +9,12 @@ void setup() {
9
9
mqtt.wifi (" ssid" , " pass" );
10
10
mqtt.mqtt (" server" , 1883 , " user" , " password" );
11
11
12
- mqtt[" temperature" ] << []() {
13
- float value = dht.readTemperature ();
14
- if (isnan (value)) {
15
- return String (" " );
16
- } else {
17
- return String (value);
18
- }
12
+ mqtt[" temperature" ] << [&]() {
13
+ return dht.readTemperature ();
19
14
};
20
15
21
- mqtt[" humidity" ] << []() {
22
- float value = dht.readHumidity ();
23
- if (isnan (value)) {
24
- return String (" " );
25
- } else {
26
- return String (value);
27
- }
16
+ mqtt[" humidity" ] << [&]() {
17
+ return dht.readHumidity ();
28
18
};
29
19
30
20
}
Original file line number Diff line number Diff line change @@ -219,6 +219,23 @@ void Entry::operator<<(std::function<String()> inFunction) {
219
219
Entry::inFunction = inFunction;
220
220
}
221
221
222
+ void Entry::operator <<(std::function<char *()> inFunction) {
223
+ Entry::inFunction = [&]() {
224
+ return String (inFunction ());
225
+ };
226
+ }
227
+
228
+ void Entry::operator <<(std::function<float ()> inFunction) {
229
+ Entry::inFunction = [&]() {
230
+ float value = inFunction ();
231
+ if (isnan (value)) {
232
+ return String (" " );
233
+ } else {
234
+ return String (value);
235
+ }
236
+ };
237
+ }
238
+
222
239
void Entry::operator >>(std::function<void (String payload)> outFunction) {
223
240
Entry::outFunction = outFunction;
224
241
}
Original file line number Diff line number Diff line change @@ -99,6 +99,8 @@ class Entry {
99
99
* Read data from function and send it to mqtt
100
100
*/
101
101
void operator <<(std::function<String()> inFunction);
102
+ void operator <<(std::function<char *()> inFunction);
103
+ void operator <<(std::function<float ()> inFunction);
102
104
103
105
/* *
104
106
* Handle data comming from mqtt
You can’t perform that action at this time.
0 commit comments