Code Monkey home page Code Monkey logo

serialmqttbridge's Introduction

Java Serial MQTT Bridge

Java application which forwards messages from serial ports to MQTT broker and vice-versa.

The intention of this bridge is making data received over serial interfaces (such as UART, RS232) available to MQTT brokers for general usage - and the other way around.

I created this little application when I wanted to forward serial messages of the MySensors home sensor/automation system to a general purpose MQTT broker to process these messages with multiple controllers (MyController and OpenHAB) for evaluation and for having a nice way of logging/debugging.

A special feature of SerialMqttBridge is a simple plugin system to modify messages before forwarding them via MQTT or UART. Sometimes it is necessary to adapt the content between both worlds. For example MySensors messages on the serial bus have to be reformatted for MQTT needs:

12;6;1;0;0;36.5\n (serial) <-> Topic: <topicPrefix>/12/6/1/0/0 with content: 36.5 (MQTT)

In the source code you find a class doing this conversion in the de.reitho.serialMqttBridge.plugins package. Taking this one as reference you can write your own adapters.

Function

SerialMqttBridge gets configured with a text file called config.properties. This file has to be in the application root folder.

The file contains the following parameters:

Config parameter Example values Note
Serial connection properties
serial.port COM5 (Windows), /dev/ttyS1 (Linux)
serial.baudRate
115200
serial.dataBits 8
serial.stopBits 1
serial.parity 0
MQTT properties
mqtt.brokerUrl tcp://localhost:1883 Consists of protocol (tcp://), hostname (or IP) and port.
mqtt.brokerUsername jdoe optional, leave blank if no authentication needed
mqtt.brokerPassword s3cr3t optional, leave blank if no authentication needed
mqtt.clientId mqttSerialBridge
mqtt.topicPublish serialgateway-out This is the topic the bridges publishes the forwarded messages to.
mqtt.topicSubscribe serialgateway-in/# This is the topic the bridge subscribes for messages. Wildcards '#' and '+' are supported.
mqtt.qosSubscribe 0 QoS which should be used for subscriptions.
mqtt.qosPublish 0 QoS which should be used for publications.
Logging properties
logging.serialInbound true, false Defines whether incoming serial messages should be logged.
logging.serialOutbound true, false Defines whether outgoing serial messages should be logged.
logging.mqttInbound true, false Defines whether incoming MQTT messages should be logged.
logging.mqttOutbound true, false Defines whether outgoing MQTT messages should be logged.
Publishing preprocessor plugin properties
plugin.mqttPublishPreprocessor com.foo.bar.MqttPreprocessor Name of the class which preprocesses the serial message before publishing it.
plugin.serialSendPreprocessor com.foo.bar.SerialPreprocessor Name of the class which preprocesses the MQTT message before sending it out on serial interface.

System requirements

The application needs Java Runtime version 1.8 to run.

Usage

After downloading and extracting the release archive please check and modify the properties file first. Then you can start the application with

java -jar serialMqttBridge-<VERSION>.jar.

Developers can clone the code and build the application using Maven:

mvn package

If you want to create your own preprocessor plugin just implement the according interfaces in the de.reitho.serialMqttBridge.plugins package, put the classes into the classpath and define them in the config file.

Outlook

Up to now you can only define one or zero preprocessor plugins. In the future I might expand this into a kind of workflow engine which allows custom logging, filtering or persistence.

serialmqttbridge's People

Contributors

dertomm avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.