From ee70c520dd981b631d82489de34437c5d734a4cc Mon Sep 17 00:00:00 2001 From: AlbertWeterings <36169962+AlbertWeterings@users.noreply.github.com> Date: Wed, 21 Feb 2018 06:40:01 +0100 Subject: [PATCH] Update uart_mqtt --- code/espurna/uart_mqtt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/code/espurna/uart_mqtt b/code/espurna/uart_mqtt index fa7c84a3..c27fbd95 100644 --- a/code/espurna/uart_mqtt +++ b/code/espurna/uart_mqtt @@ -1,8 +1,5 @@ #ifdef UARTtoMQTT -#include -#include - // ----------------------------------------------------------------------------- // GLOBALS TO THE MODULE // ----------------------------------------------------------------------------- @@ -33,13 +30,20 @@ void _recvWithEndMarker() { } } -void _sendNewData() { +void _uartSendUARTtoMQTT() { if (newData == true && MQTT_SUPPORT) { - mqttSend(MQTT_TOPIC_UARTIN, receivedChars); // publish: UART -> mqtt bus + DEBUG_MSG_P(PSTR("[UARTtoMQTT] Send data over MQTT: %s\n"), receivedChars); + mqttSend(MQTT_TOPIC_UARTIN, receivedChars); // publish: UART -> mqtt bus newData = false; } } +void _uartSendMQTTtoUART(const char * message) { + DEBUG_MSG_P(PSTR("[UARTtoMQTT] Send data over UART: %s\n"), message); + Serial.print(message); + Serial.println(); +} + #if MQTT_SUPPORT void _UARTtoMQTTMqttCallback(unsigned int type, const char * topic, const char * payload) { if (type == MQTT_CONNECT_EVENT) { @@ -53,8 +57,7 @@ void _UARTtoMQTTMqttCallback(unsigned int type, const char * topic, const char * bool isUARTOut = t.equals(MQTT_TOPIC_UARTOUT); if (isUARTOut) { - Serial.print(payload); - Serial.println(); + _uartSendMQTTtoUART(payload); } } @@ -79,7 +82,7 @@ void UARTtoMQTTSetup() { void UARTtoMQTTLoop() { _recvWithEndMarker(); - _sendNewData(); + _uartSendUARTtoMQTT(); } #endif