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 #ifdef UARTtoMQTT
#include <queue>
#include <Ticker.h>
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// GLOBALS TO THE MODULE // GLOBALS TO THE MODULE
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -33,13 +30,20 @@ void _recvWithEndMarker() {
} }
} }
void _sendNewData() {
void _uartSendUARTtoMQTT() {
if (newData == true && MQTT_SUPPORT) { 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; 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 #if MQTT_SUPPORT
void _UARTtoMQTTMqttCallback(unsigned int type, const char * topic, const char * payload) { void _UARTtoMQTTMqttCallback(unsigned int type, const char * topic, const char * payload) {
if (type == MQTT_CONNECT_EVENT) { 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); bool isUARTOut = t.equals(MQTT_TOPIC_UARTOUT);
if (isUARTOut) { if (isUARTOut) {
Serial.print(payload);
Serial.println();
_uartSendMQTTtoUART(payload);
} }
} }
@ -79,7 +82,7 @@ void UARTtoMQTTSetup() {
void UARTtoMQTTLoop() { void UARTtoMQTTLoop() {
_recvWithEndMarker(); _recvWithEndMarker();
_sendNewData();
_uartSendUARTtoMQTT();
} }
#endif #endif

Loading…
Cancel
Save