|
|
@ -1,4 +1,4 @@ |
|
|
|
#ifdef UARTtoMQTT |
|
|
|
#ifdef UART_MQTT_SUPPORT |
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------- |
|
|
|
// GLOBALS TO THE MODULE |
|
|
@ -30,22 +30,22 @@ void _recvWithEndMarker() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void _uartSendUARTtoMQTT() { |
|
|
|
void _uartSendUART_MQTT() { |
|
|
|
if (newData == true && MQTT_SUPPORT) { |
|
|
|
DEBUG_MSG_P(PSTR("[UARTtoMQTT] Send data over MQTT: %s\n"), receivedChars); |
|
|
|
DEBUG_MSG_P(PSTR("[UART_MQTT] 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); |
|
|
|
void _uartSendMQTT_UART(const char * message) { |
|
|
|
DEBUG_MSG_P(PSTR("[UART_MQTT] 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) { |
|
|
|
void _UART_MQTTMqttCallback(unsigned int type, const char * topic, const char * payload) { |
|
|
|
if (type == MQTT_CONNECT_EVENT) { |
|
|
|
mqttSubscribe(MQTT_TOPIC_UARTOUT); |
|
|
|
} |
|
|
@ -57,7 +57,7 @@ void _UARTtoMQTTMqttCallback(unsigned int type, const char * topic, const char * |
|
|
|
bool isUARTOut = t.equals(MQTT_TOPIC_UARTOUT); |
|
|
|
|
|
|
|
if (isUARTOut) { |
|
|
|
_uartSendMQTTtoUART(payload); |
|
|
|
_uartSendMQTT_UART(payload); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -67,20 +67,20 @@ void _UARTtoMQTTMqttCallback(unsigned int type, const char * topic, const char * |
|
|
|
// SETUP & LOOP |
|
|
|
// ----------------------------------------------------------------------------- |
|
|
|
|
|
|
|
void UARTtoMQTTSetup() { |
|
|
|
void uart_mqttSetup() { |
|
|
|
|
|
|
|
#if MQTT_SUPPORT |
|
|
|
mqttRegister(_UARTtoMQTTMqttCallback); |
|
|
|
mqttRegister(_UART_MQTTMqttCallback); |
|
|
|
#endif |
|
|
|
|
|
|
|
// Register oop |
|
|
|
espurnaRegisterLoop(UARTtoMQTTLoop); |
|
|
|
espurnaRegisterLoop(UART_MQTTLoop); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void UARTtoMQTTLoop() { |
|
|
|
void UART_MQTTLoop() { |
|
|
|
_recvWithEndMarker(); |
|
|
|
_uartSendUARTtoMQTT(); |
|
|
|
_uartSendUART_MQTT(); |
|
|
|
} |
|
|
|
|
|
|
|
#endif |