eclipse-paho / paho.mqtt.ruby

Eclipse Public License 1.0
34 stars 8 forks source link

Binary Support in Last Will and Testament #14

Open reedleoneil opened 4 years ago

reedleoneil commented 4 years ago

I'm having an error when connecting to the broker if I have a binary LWT.

../paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:116:in `connect'
../paho-mqtt-1.0.12/lib/paho_mqtt/connection_helper.rb:136:in `send_connect'
../paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:34:in `send_packet'
../paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:41:in `rescue in send_packet': PahoMqtt::WritingException

Here is my sample code:

require 'paho-mqtt'
require 'msgpacker'
require 'json'

last_will = {
    :id => 1,
    :data => "test data"
}

mqtt_settings = {
    :host => 'localhost',
    :port => 1883,
    :persistent => true,
    :reconnect_limit => 3,
    :reconnect_delay => 60,
    :will_topic => 'test_topic',
    :will_payload => last_will.to_msgpack,                  # will not work
    #:will_payload => File.binread('test_file', 32, 0),             # will not work
    #:will_payload => last_will.to_json,                    # will work
    :will_qos => 2,
    :will_retain => false
}

mqtt_client = PahoMqtt::Client.new(mqtt_settings)
mqtt_client.connect

loop do
    mqtt_client.loop_read
    mqtt_client.loop_write
end

I am using msgpacker to serialize my data into binary for the :will_topic but I am having error. I tried to read a binary file for the :will_topic but it also have the same error.

Thanks in advance!