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