Skip to content

Commit 5804b78

Browse files
author
Bjarne Loft
committed
Update readme and examples and support float as input
1 parent 1202ac2 commit 5804b78

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# EasyMqtt
22
Easy handling of Mqtt on esp8266
33

4-
* Easy wifi configuration
5-
* Easy mqtt configuration
4+
* Easy wifi configuration using web interface
5+
* Easy mqtt configuration using web interface
66
* Easy configuration of mqtt endpoints
77
* Web based UI to see current values
88

@@ -13,14 +13,10 @@ Easy handling of Mqtt on esp8266
1313
EasyMqtt mqtt;
1414

1515
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");
2117

22-
mqtt["foo"] << [](){
23-
return mqtt.config().getString("foo");
18+
mqtt["foo"] << [&](){
19+
return String(mqtt.config().get("foo", "default"));
2420
};
2521
}
2622

examples/temperature/temperature.ino

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,12 @@ void setup() {
99
mqtt.wifi("ssid", "pass");
1010
mqtt.mqtt("server", 1883, "user", "password");
1111

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();
1914
};
2015

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();
2818
};
2919

3020
}

src/Entry.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,23 @@ void Entry::operator<<(std::function<String()> inFunction) {
219219
Entry::inFunction = inFunction;
220220
}
221221

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+
222239
void Entry::operator>>(std::function<void(String payload)> outFunction) {
223240
Entry::outFunction = outFunction;
224241
}

src/Entry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class Entry {
9999
* Read data from function and send it to mqtt
100100
*/
101101
void operator<<(std::function<String()> inFunction);
102+
void operator<<(std::function<char *()> inFunction);
103+
void operator<<(std::function<float()> inFunction);
102104

103105
/**
104106
* Handle data comming from mqtt

0 commit comments

Comments
 (0)