Ruby MQTT Client

The Losant Ruby MQTT Client is a gem for Ruby compatible IoT modules (such as the Raspberry Pi or Edison). The library is open source and available on GitHub.

Below is a basic example demonstrating how to connect, send state, and subscribe to commands.

require "losant_mqtt" do

  # Construct device
  device =
    device_id: "my-device-id"
    key: "my-app-access-key",
    secret: "my-app-access-secret")

  # Connect to Losant.

  # Listen for commands.
  device.on(:command) do |d, command|
    puts "#{d.device_id}: Command received."
    puts command["name"]
    puts command["payload"]

  # Send temperature once every second. do
    temp = call_out_to_your_sensor_here()
    device.send_state({ temperature: temp })


Please refer to the repository for detailed documentation and examples.