Browse Source

Update uart_mqtt

Sending data both ways now works
rfm69
AlbertWeterings 6 years ago
committed by GitHub
parent
commit
e784241e33
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 7 deletions
  1. +2
    -7
      code/espurna/uart_mqtt

+ 2
- 7
code/espurna/uart_mqtt View File

@ -35,9 +35,7 @@ void _recvWithEndMarker() {
void _sendNewData() { void _sendNewData() {
if (newData == true && MQTT_SUPPORT) { if (newData == true && MQTT_SUPPORT) {
#if MQTT_SUPPORT
mqttSend(MQTT_TOPIC_UARTIN, receivedChars); // publish: UART -> mqtt bus mqttSend(MQTT_TOPIC_UARTIN, receivedChars); // publish: UART -> mqtt bus
#endif
newData = false; newData = false;
} }
} }
@ -46,20 +44,17 @@ void _sendNewData() {
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) {
mqttSubscribe(MQTT_TOPIC_UARTOUT); mqttSubscribe(MQTT_TOPIC_UARTOUT);
DEBUG_MSG_P(PSTR("[UARTtoMQTT] MQTT Subscribe topic:\n"), MQTT_TOPIC_UARTOUT);
} }
if (type == MQTT_MESSAGE_EVENT) { if (type == MQTT_MESSAGE_EVENT) {
// Match topic // Match topic
String t = mqttTopicKey((char *) topic); String t = mqttTopicKey((char *) topic);
//DEBUG_MSG_P(PSTR("[UARTtoMQTT] t= :\n"), t);
bool isUARTOut = t.equals(MQTT_TOPIC_UARTOUT); bool isUARTOut = t.equals(MQTT_TOPIC_UARTOUT);
if (isUARTOut) { if (isUARTOut) {
//send the received MQTT message to Serial
Serial.print(payload);
Serial.println();
} }
} }


Loading…
Cancel
Save