MQTT to Bluetooth

MQTT to Bluetooth

The following application was created by a project with the purpose to connect MQTT parts with Bluetooth devices.

The goal was to implement an application that is capable of transforming incoming MQTT topics or JSON strings over HTTP to a format that is compliant with Bluetooth device.

Basic information about the application and key features

The MQTT to Bluetooth application is based on a spring boot java microservice architecture. Therefore, one of the key features of the application is the low consumption of resources, as the framework allows for the efficient distribution and usage of resources in general.

Furthermore the architecture includes multiple packages, such as the Java MQTT Paho client, the JSON libraries JSON-Simple and the Apache Maven package for Build, Deployment, and Testing.

One of the features is the configuration file with the options to control and customize the Bluetooth components.

Lastly, the application also supports a customize start command.

Architecture and functional principles of the MQTT to Bluetooth

Preconditons

Before starting the application, you must ensure that the MQTT server and the corresponding Bluetooth device are running.

The current version does not have an interface that performs checks such as the above-mentioned prerequisites, as in a general operation both servers must be active.

In case these preconditions are not met, the application will throw multiple errors and will eventually crash.

Functional principles

At first, a JSON string is being sent via MQTT (HTTP is possible as well). This string is being directed into the MQTT to Bluetooth application, where the string is then being transformed into a Bluetooth device compliant format, which is predefined.

Lastly the application executes the command and sent it to the Bluetooth device.

Version Informations

The application is currently stable and the actual status is stable (Version 1.0.1).

Version Status Change Description
0.9.1Beta
1.0.1Stable

Installation

Configuration File

The following table explains you, the individual functions of the configuration file.

File OptionExample
Meaning
General Config
CONVERTER_MODE0MQTT mode (Application works only with valid MQTT JSON commands)
1HTTP mode [URL: localhost:8080/HTTPToEV3ConverterApi?jsonMessage:{}] (Application works only with valid HTTP JSON commands)
2MQTT and HTTP mode [URL: localhost:8080/HTTPToEV3ConverterApi?jsonMessage:{}] (Application works with valid HTTP JSON and MQTT JSON commands)
MQTT_HTTP_APACHE_KAFKA_STREAM_LOGGER_MODE0No logging (No logging of the input and output stream)
1HTTP/MQTT stream logging
(Only logging of the input stream)
2Kafka stream logging
(Only logging of the output stream)
3HTTP/MQTT and Kafka stream logging (Logging of the input and output stream)
MQTT_HTTP_APACHE_KAFKA_LOGGER_PATHPath/Micro_Services/MqttAndHttpApacheKafkaConverterLog.logDefine the log path and file
MQTT/ HTTP Config
MQTT_BROKER_HOSTtcp://MQTT_Broker_Hostname:MQTT_Broker_PortDefine the MQTT Broker Hostname or IP and the Port (Default: 1883)
MQTT_CLIENT_IDMQTTToApacheKafkaStreamClient Define the MQTT client ID
MQTT_RECEPTION_TOPIC_NAMEMQTT/TopicDefine the reception MQTT Topic
MQTT/Topic;MQTT/Topic Define the reception MQTT Topics separated with ‘;’
MQTT_SEND_TOPIC_NAME MQTT/TopicDefine the send MQTT Topic
MQTT/Topic;MQTT/Topic Define the send MQTT Topics separated with ‘;’
LAST_WILL_TESTAMENT_TOPIC_NAMEMQTT/Topic Define the Last Will and Testament Topic
LAST_WILL_TESTAMENT_QOS2Define the Last Will and Testament QOS
LAST_WILL_TESTAMENT_MESSAGEThe device is currently not available.Define the Last Will and Testament message
Bluetooth Config
BLUETOOTH_IP_ADDRESS10.0.1.1Define the Bluetooth IP address
BLUETOOTH_SOCKET5000Define the Bluetooth socket
BLUETOOTH_RECEPTION_SOCKET5000Define the Bluetooth reception socket
BLUETOOTH_COMMANDS startDefine a Bluetooth start connection command

Requirements

  1. The application was developed for Java 9 and may also run under higher Java versions.

Establishment

  1. Download the correct file for your Operating System.
  2. Unpack the file and copy the Jar and configuration folder & file to your local Operating System.
  3. Adjust your favorite user and set the correct rights at the Jar file (sudo chown user:user Path/MQTT_To_Bluetooth.jar & sudo chmod 755 Path/MQTT_To_Bluetooth.jar)
  4. Optional by Linux and MAC OS X Systems: Copy, implement and customize the Service Script.
    1. Download and copy the Script from here.
    2. Place the Script inside your /etc/init.d directory.
    3. Set the correct rights to your Script (sudo chmod 755 /etc/init.d/mqtt-to-bluetooth).
    4. Set the correct owner to your Script (sudo chown root:root /etc/init.d/mqtt-to-bluetooth).
    5. Customize the path inside the Script (sudo nano /etc/init.d/mqtt-to-bluetooth).
    6. Activate the Script and implement it your system start process with (sudo systemctl enable mqtt-to-bluetooth).
  5. Start the Service Script (sudo service mqtt-to-bluetooth start) to run the application.
  6. Or start the MQTT_To_Bluetooth Jar file (/usr/bin/java -jar Path/MQTT_To_Bluetooth.jar &) to run the application.

Download

Donations

If you want you can support my work. The corresponding PayPal link will follow shortly.

License Agreement

You can find the license agreement here.

Support

Please, contact me if you find a bug or you need help!