Mqttopia
Mqttopia is a Ruby-based project designed to facilitate interactions with MQTT protocols. It provides a modular architecture for handling MQTT clients, subscriptions, and data serialization, making it easier to integrate MQTT into your applications.
Features
- Configurable MQTT client with options for hosts, port, SSL, and authentication.
- Subscription handling for dynamic topics.
- Data serialization modules to standardize payloads.
- Custom Rake tasks for initializing configuration files.
Installation
Bundler
gem 'mqttopia', '~> 0.1.0'
Manual
gem install mqttopia
Usage
Configuring Mqttopia
You can create or update the mqttopia.rb file using the included Rake task:
bundle exec rails generate mqttopia:install
The generated mqttopia.rb will contain:
Mqttopia.configure do |config|
config.hosts = ["localhost"]
config.port = 1883
config.username = "user"
config.password = "xxxx"
config.ssl = true
end
Example: Subscribing and Publishing Messages
client = Mqttopia::Client.instance
# Subscribe to a topic
client.subscribe('test/#') do |response|
puts "Received: #{response}"
end
# Publish a message to a topic
client.publish('test/topic', 'Hello, MQTT')
MQTT subscriptions
Topic Name Structure
- send data :
illa/{entity}/{entity_id}/{operation}/send/user/{user_id} - ask data :
illa/{entity}/{entity_id}/{operation}/ask/user/{user_id} - operation :
trip_metrics,test_debug, ..etc. - entity:
trips user/{user_id}is optional
Rake Tasks
Available Tasks
- Initialize Configuration File:
Creates mqttopia_initialize.rb with default configurations.
bundle exec rake mqttopia:initialize
Project Structure
mqttopia/
Contributing
- Fork the repository.
- Create a feature branch:
git checkout -b feature-branch-name - Commit your changes:
git commit -m "Add new feature" - Push the branch:
git push origin feature-branch-name - Open a Pull Request.
License
This project is licensed under the MIT License. See the LICENSE file for more information.
Contact
If you have any questions or need further assistance, feel free to open an issue or contact the maintainer.
Acknowledgements
Special thanks to all contributors and users who have made this project possible.