Browse Source

Update uart_mqtt

rfm69
AlbertWeterings 6 years ago
committed by GitHub
parent
commit
ee70c520dd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 8 deletions
  1. +11
    -8
      code/espurna/uart_mqtt

+ 11
- 8
code/espurna/uart_mqtt View File

@ -1,8 +1,5 @@
#ifdef UARTtoMQTT
#include <queue>
#include <Ticker.h>
// -----------------------------------------------------------------------------
// 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

Loading…
Cancel
Save