Skip to content

Commit

Permalink
Merge pull request #245 from fablabbcn/enhancement/mqtt_ssl_support
Browse files Browse the repository at this point in the history
Add possibility to connect via ssl to broker
  • Loading branch information
oscgonfer authored Jul 6, 2023
2 parents f25f8c1 + c04ff31 commit 94e3688
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ REDIS_STORE=redis://redis:6379/3
MQTT_HOST=mqtt
#MQTT_CLEAN_SESSION=true
#MQTT_CLIENT_ID=some_id

#MQTT_PORT=port
#MQTT_SSL=false
aws_secret_key=123

# kairos Dockerized
Expand Down
8 changes: 7 additions & 1 deletion lib/tasks/mqtt_subscriber.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ namespace :mqtt do
mqtt_clean_session = ENV.has_key?('MQTT_CLEAN_SESSION') ? ENV['MQTT_CLEAN_SESSION'] == "true" : true
mqtt_client_id = ENV.has_key?('MQTT_CLIENT_ID') ? ENV['MQTT_CLIENT_ID'] : nil
mqtt_host = ENV.has_key?('MQTT_HOST') ? ENV['MQTT_HOST'] : 'mqtt'
mqtt_port = ENV.has_key?('MQTT_PORT') ? ENV['MQTT_PORT'] : 1883
mqtt_ssl = ENV.has_key?('MQTT_SSL') ? ENV['MQTT_SSL'] : false

mqtt_log.info('MQTT TASK STARTING')
mqtt_log.info("clean_session: #{mqtt_clean_session}")
mqtt_log.info("client_id: #{mqtt_client_id}")
mqtt_log.info("host: #{mqtt_host}")
mqtt_log.info("port: #{mqtt_port}")
mqtt_log.info("ssl: #{mqtt_ssl}")

begin
MQTT::Client.connect(
:host => mqtt_host,
:port => mqtt_port,
:clean_session => mqtt_clean_session,
:client_id => mqtt_client_id
:client_id => mqtt_client_id,
:ssl => mqtt_ssl
) do |client|

mqtt_log.info "Connected to #{client.host}"
Expand Down

0 comments on commit 94e3688

Please sign in to comment.