|
|
@ -48,9 +48,7 @@ uint32_t lastTransmit = 0; |
|
|
|
//Variables for the mqtt packages and topics
|
|
|
|
uint16_t statusPacketIdSub = 0; |
|
|
|
String commandTopic; |
|
|
|
String temperatureTopic; |
|
|
|
String humidityTopic; |
|
|
|
String pressureTopic; |
|
|
|
String bme280Topic; |
|
|
|
|
|
|
|
void setup() { |
|
|
|
// gpio configuration
|
|
|
@ -72,10 +70,8 @@ void setup() { |
|
|
|
bme280.printValues(); |
|
|
|
|
|
|
|
//Configure the MQTT topics
|
|
|
|
commandTopic = "esp32-node/cmd/" + iot.hostname + "/command"; |
|
|
|
temperatureTopic = "esp32-node/stat/" + iot.hostname + "/temperature"; |
|
|
|
humidityTopic = "esp32-node/stat/" + iot.hostname + "/humidity"; |
|
|
|
pressureTopic = "esp32-node/stat/" + iot.hostname + "/pressure"; |
|
|
|
commandTopic = "esp32-node/cmd/" + iot.hostname + "/play"; |
|
|
|
bme280Topic = "esp32-node/stat/" + iot.hostname + "/bme280"; |
|
|
|
|
|
|
|
//Set up the Callbacks for the MQTT instance. Refer to the Async MQTT Client documentation
|
|
|
|
// TODO: We should do this actually _before_ connecting the mqtt client...
|
|
|
@ -116,13 +112,15 @@ void onMqttConnect(bool sessionPresent) { |
|
|
|
|
|
|
|
void transmitStatus() { |
|
|
|
DEBUG_PRINTLN(__func__); |
|
|
|
char sensorC[6]; |
|
|
|
sprintf(sensorC, "%04i", bme280.readTemperature()); |
|
|
|
statusPacketIdSub = iot.mqtt.publish(temperatureTopic.c_str(), 1, true, sensorC); |
|
|
|
sprintf(sensorC, "%04i", bme280.readHumidity()); |
|
|
|
statusPacketIdSub = iot.mqtt.publish(humidityTopic.c_str(), 1, true, sensorC); |
|
|
|
sprintf(sensorC, "%04i", bme280.readPressure()); |
|
|
|
statusPacketIdSub = iot.mqtt.publish(pressureTopic.c_str(), 1, true, sensorC); |
|
|
|
StaticJsonBuffer<200> jsonBuffer; |
|
|
|
JsonObject& root = jsonBuffer.createObject(); |
|
|
|
root["temperature"] = bme280.readTemperature(); |
|
|
|
root["humidity"] = bme280.readHumidity(); |
|
|
|
root["pressure"] = bme280.readPressure(); |
|
|
|
|
|
|
|
char sensorBuf[root.measureLength()+1]; |
|
|
|
root.printTo(sensorBuf, sizeof(sensorBuf)); |
|
|
|
statusPacketIdSub = iot.mqtt.publish(bme280Topic.c_str(), 1, true, sensorBuf); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -131,7 +129,10 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties |
|
|
|
DEBUG_PRINTLN(__func__); |
|
|
|
|
|
|
|
//Since we only subscribed to one topic, we only have to compare the payload
|
|
|
|
if (strcmp(payload, "true") == 0) { |
|
|
|
if (strcmp(payload, "ON") == 0) { |
|
|
|
mp3.start(); |
|
|
|
} else if (strcmp(payload, "OFF") == 0) { |
|
|
|
mp3.stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|