Skip to content

Commit 85c65f8

Browse files
committed
Add more exambles
1 parent a34c33e commit 85c65f8

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

examples/subscribe/subscribe.ino

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <EasyMqtt.h>
2+
3+
EasyMqtt mqtt;
4+
5+
void setup() {
6+
Serial.begin(115200);
7+
Serial.println();
8+
9+
mqtt.wifi("ssid", "pass");
10+
mqtt.mqtt("server", 1883, "user", "password");
11+
12+
mqtt["write"] >> [](String value) {
13+
Serial.print("Incomming: ");
14+
Serial.println(value);
15+
};
16+
}
17+
18+
void loop() {
19+
mqtt.loop();
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <EasyMqtt.h>
2+
#include <DHT.h>
3+
4+
EasyMqtt mqtt;
5+
DHT dht(D7, DHT22);
6+
7+
void setup() {
8+
dht.begin();
9+
mqtt.wifi("ssid", "pass");
10+
mqtt.mqtt("server", 1883, "user", "password");
11+
12+
mqtt["temperature"] << []() {
13+
float value = dht.readTemperature();
14+
if(isnan(value)) {
15+
return String("");
16+
} else {
17+
return String(value);
18+
}
19+
}
20+
21+
mqtt["humidity"] << []() {
22+
float value = dht.dht.readHumidity();
23+
if(isnan(value)) {
24+
return String("");
25+
} else {
26+
return String(value);
27+
}
28+
}
29+
30+
}
31+
32+
void loop() {
33+
mqtt.loop();
34+
}

0 commit comments

Comments
 (0)