Class: SpsMqttBridge
- Inherits:
-
Object
- Object
- SpsMqttBridge
- Defined in:
- lib/sps_mqtt_bridge.rb
Instance Method Summary collapse
-
#initialize(mqtt: {address: 'mqtt', port: '1883'}, sps: {address: 'sps', port: '59000'}) ⇒ SpsMqttBridge
constructor
A new instance of SpsMqttBridge.
- #mqtt_to_sps(topic: '#') ⇒ Object
- #sps_to_mqtt(topic: '#') ⇒ Object
Constructor Details
#initialize(mqtt: {address: 'mqtt', port: '1883'}, sps: {address: 'sps', port: '59000'}) ⇒ SpsMqttBridge
Returns a new instance of SpsMqttBridge.
12 13 14 15 |
# File 'lib/sps_mqtt_bridge.rb', line 12 def initialize(mqtt: {address: 'mqtt', port: '1883'}, sps:{address: 'sps', port: '59000'}) @mqtt, @sps = mqtt, sps end |
Instance Method Details
#mqtt_to_sps(topic: '#') ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sps_mqtt_bridge.rb', line 17 def mqtt_to_sps(topic: '#') MQTT::Client.connect(@mqtt[:address], @mqtt[:port]) do |client| client.get(topic) do |t, | SPSPub.notice [t, ].join(': '), address: @sps[:address], port: @sps[:port] end end end |
#sps_to_mqtt(topic: '#') ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sps_mqtt_bridge.rb', line 28 def sps_to_mqtt(topic: '#') SimplePubSub::Client.connect(@sps[:address], @sps[:port]) do |client| client.get(topic) do |t, | MQTT::Client.connect(@mqtt[:address], @mqtt[:port]) do |client| client.publish(t, ) end end end end |