added example to read data from MQTT Server
This commit is contained in:
parent
03ea93b741
commit
b4ecfed027
@ -64,6 +64,11 @@ void onMqttConnect(bool sessionPresent)
|
||||
uint16_t packetIdSub = mqttClient.subscribe(MQTT_PATH_SUB, 2);
|
||||
Serial.print("subscribed to: ");
|
||||
Serial.println(MQTT_PATH_SUB);
|
||||
|
||||
//Testing read
|
||||
uint16_t packetIdSub2 = mqttClient.subscribe("smartgarden/updates/esp-sebastian/brightness", 2);
|
||||
Serial.print("also subscribed to: ");
|
||||
Serial.println("smartgarden/updates/esp-sebastian/brightness");
|
||||
}
|
||||
|
||||
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
|
||||
@ -103,6 +108,18 @@ void onMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties
|
||||
Serial.println(topic);
|
||||
toggleValve();
|
||||
}
|
||||
|
||||
//Testing reading
|
||||
String messageTemp;
|
||||
for (int i = 0; i < len; i++) {
|
||||
//Serial.print((char)payload[i]);
|
||||
messageTemp += (char)payload[i];
|
||||
}
|
||||
if (strcmp(topic, "smartgarden/updates/esp-sebastian/brightness") == 0) {
|
||||
Serial.println("### Received brightness value: ###");
|
||||
Serial.println(messageTemp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void onMqttPublish(uint16_t packetId)
|
||||
@ -135,4 +152,4 @@ void setupConnections()
|
||||
|
||||
void publishMessage(const char *topic, const char *msg) {
|
||||
mqttClient.publish(topic, 1, true, msg);
|
||||
}
|
||||
}
|
||||
@ -17,6 +17,10 @@
|
||||
#include <AutoConnect.h>
|
||||
#include <AsyncMqttClient.h>
|
||||
|
||||
// BH1750 lightsensor
|
||||
#define MIN_LIGHT 0
|
||||
#define MAX_LIGHT 54612
|
||||
|
||||
// DHT11
|
||||
#define PIN_DHT11 14
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user