Class: TEF::FurComs::SerialToMQTT
- Defined in:
- lib/tef/furcoms/serial_to_mqtt.rb
Overview
Instance Method Summary collapse
-
#initialize(port, mqtt, topic = nil) ⇒ SerialToMQTT
constructor
Initialize a Serial To MQTT bridge instance.
Methods inherited from Serial
Methods inherited from Base
Constructor Details
#initialize(port, mqtt, topic = nil) ⇒ SerialToMQTT
Note:
This class can not provide full arbitration handling. This may cause issues in busy bus conditions!
Initialize a Serial To MQTT bridge instance.
This will open the given Serial port and begin reading/writing onto the FurComs bus. It will additionally subscribe to the MQTT ‘topic’, or ‘FurComs/#topic/Send/#’ using the /dev/DEVICE part of the port argument if topic is left nil. Any message received on this topic will be sent as FurComs messages.
Received messages are first handed out to internal callbacks, and will then be sent off to ‘FurComs/#topic/Received/#msg_topic’
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tef/furcoms/serial_to_mqtt.rb', line 35 def initialize(port, mqtt, topic = nil) super(port); @mqtt = mqtt; @mqtt_topic = topic || "FurComs/#{port.sub('/dev/', '')}/"; @mqtt.subscribe_to @mqtt_topic + 'Send/#' do |data, msg_topic| msg_topic = msg_topic.join('/') next if data.length + msg_topic.length > 250 next unless msg_topic =~ /^[\w\s\/]*$/ msg_topic, data end end |