Sha256: c4c6b11aaad9fd68a5edbd123a44cec0b9ded073cf01b63e41037abed1893983
Contents?: true
Size: 1.95 KB
Versions: 2
Compression:
Stored size: 1.95 KB
Contents
# frozen_string_literal: true require "mqtt" module DjiMqttConnect # Client for communicating with DJI Cloud API MQTT Messages # see: https://developer.dji.com/doc/cloud-api-tutorial/en/server-api-reference/mqtt/topic-definition.html class Client def self.build(mqtt_address, username:, password:, client_name: DjiMqttConnect.client_name, &block) mqtt_url = URI.parse(mqtt_address) mqtt_host = mqtt_url.host mqtt_port = mqtt_url.port.to_i mqtt_scheme = mqtt_url.scheme DjiMqttConnect.logger.tagged(name) do DjiMqttConnect.logger.info("Connecting to #{mqtt_scheme}://#{mqtt_host}:#{mqtt_port}...") mqtt_client = MQTT::Client.connect( host: mqtt_host, port: mqtt_port, client_id: MQTT::Client.generate_client_id(client_name), username: username, password: password, ssl: !%w[tcp mqtt ws].include?(mqtt_scheme) ) new(mqtt_client) end end def initialize(mqtt_client) @mqtt_client = mqtt_client end # Handles topic sys/product/#{pid}/status def sys_product_status_topic Sys::Product::StatusTopicRepository.new(self) end # Handles topic sys/product/#{pid}/status_reply def sys_product_status_reply_topic Sys::Product::StatusReplyTopicRepository.new(self) end # Handles topic thing/product/#{pid}/events def thing_product_events_topic Thing::Product::EventsTopicRepository.new(self) end # Handles topic thing/product/#{pid}/osd def thing_product_osd_topic Thing::Product::OsdTopicRepository.new(self) end # Handles topic thing/product/#{pid}/requests def thing_product_requests_topic Thing::Product::RequestsTopicRepository.new(self) end # Handles topic thing/product/#{pid}/requests_reply def thing_product_requests_reply_topic Thing::Product::RequestsReplyTopicRepository.new(self) end attr_reader :mqtt_client end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dji_mqtt_connect-0.1.9 | lib/dji_mqtt_connect/client.rb |
dji_mqtt_connect-0.1.8 | lib/dji_mqtt_connect/client.rb |