Welcome to the Spring MQTT Project! This project demonstrates how to use Spring Boot with MQTT to simulate automotive electronic injection system sensors, specifically a rotation sensor, maf sensor, trottle postion sensor and a temperature sensor. The sensors send MQTT messages to a Mosquitto broker, and a consumer subscribes to these messages for processing.
Before you begin, ensure you have the following installed on your system:
Follow these steps to set up the project:
-
Clone the repository:
git clone https://github.com/acbueno/spring-mqtt.git cd spring-mqtt
-
Build the project:
Use Maven to clean and build the project:
mvn clean install
-
Set up and start the Mosquitto broker:
Use Docker Compose to start the Mosquitto MQTT broker:
docker-compose up -d
You can run the rotation sensor and temperature sensor simulators to start publishing MQTT messages:
-
Start the rotation sensor simulator:
mvn exec:java -Dexec.mainClass="br.acbueno.rotation.sensor.App"
-
Start the temperature sensor simulator:
mvn exec:java -Dexec.mainClass="br.acbueno.temperature.sensor.App"
-
Start the maf sensor simulator:
mvn exec:java -Dexec.mainClass="br.acbueno.maf.sensor.App"
-
Start the the trottle position sensor:
mvn exec:java -Dexec.mainClass="br.acbueno.maf.trottle.postion.sensor.App"
To consume the messages published by the sensors, run the consumer:
mvn exec:java -Dexec.mainClass="br.acbueno.mqtt.consumer.MessageConsumer"
Here's an overview of the project's structure:
- src/main/java/br/acbueno/rotation/sensor/RotationSensor.java: Simulates a rotation sensor that publishes rotation data to an MQTT topic.
- src/main/java/br/acbueno/temperature/sensor/TemperatureSensor.java: Simulates a temperature sensor that publishes temperature data to an MQTT topic.
- src/main/java/br/acbueno/maf/sensor/MafSensor.java: Simulates air flow meter sensor that publishes air flow meter data to an MQTT topic.
- src/main/java/br/acbueno/trottle/position/sensor/TrottlePostionSensor.java: Simulates accelerator throttle position sensor that publishes throttle position data to an MQTT topic.
- src/main/java/br/acbueno/mqtt/consumer/MessageConsumer.java: Subscribes to the MQTT topics and processes the incoming sensor data.
- src/main/java/br/acbueno/mqtt/config/ConnectionBroker.java: Manages the MQTT connection configuration, including broker URL, client ID, username, and password.
The MQTT broker connection settings are defined in the ConnectionBroker class. You can adjust these settings as needed:
private static final String BROKER_URL = "tcp://127.0.0.1:1883";
private static final String CLIENT_ID = "mqttClient";
private static final String USERNAME = "your-username";
private static final String PASSWORD = "your-password";
Make sure to replace your-username and your-password with the actual credentials configured for your Mosquitto broker.
Contributions are welcome! If you would like to contribute to this project, please follow these steps:
- Fork the repository
- Create a new feature branch (git checkout -b feature/your-feature)
- Make your changes and commit them (git commit -am 'Add new feature')
- Push to the branch (git push origin feature/your-feature)
- Open a new Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.