v1.0.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2016 License: Apache-2.0, Apache-2.0 Imports: 2 Imported by: 0



MQTT is an Internet of Things connectivity protocol featuring a lightweight publish/subscribe messaging transport. It is useful for its small code footprint and minimal network bandwidth usage.

This repository contains the Gobot adaptor/drivers to connect to MQTT servers. It uses the Paho MQTT Golang client package ( created and maintained by the Eclipse Foundation ( thank you!

For more info about the MQTT machine to machine messaging standard, go to

How to Install

Install running:

go get -d -u && go install

How to Use

Before running the example, make sure you have an MQTT message broker running somewhere you can connect to

package main

import (

func main() {
  mqttAdaptor := mqtt.NewAdaptor("tcp://", "pinger")

  work := func() {
    mqttAdaptor.On("hello", func(data []byte) {
    mqttAdaptor.On("hola", func(data []byte) {
    data := []byte("o")
    gobot.Every(1*time.Second, func() {
      mqttAdaptor.Publish("hello", data)
    gobot.Every(5*time.Second, func() {
      mqttAdaptor.Publish("hola", data)

  robot := gobot.NewRobot("mqttBot",


Supported Features

  • Publish messages
  • Respond to incoming message events


For our contribution guidelines, please go to


Copyright (c) 2013-2016 The Hybrid Group. Licensed under the Apache 2.0 license.



Package mqtt provides Gobot adaptor for the mqtt message service.


go get

For further information refer to mqtt README:



This section is empty.


This section is empty.


This section is empty.


type Adaptor added in v1.0.0

type Adaptor struct {
	Host string
	// contains filtered or unexported fields

Adaptor is the Gobot Adaptor for MQTT

func NewAdaptor added in v1.0.0

func NewAdaptor(host string, clientID string) *Adaptor

NewAdaptor creates a new mqtt adaptor with specified host and client id

func NewAdaptorWithAuth added in v1.0.0

func NewAdaptorWithAuth(host, clientID, username, password string) *Adaptor

NewAdaptorWithAuth creates a new mqtt adaptor with specified host, client id, username, and password.

func (*Adaptor) Connect added in v1.0.0

func (a *Adaptor) Connect() (err error)

Connect returns true if connection to mqtt is established

func (*Adaptor) Disconnect added in v1.0.0

func (a *Adaptor) Disconnect() (err error)

Disconnect returns true if connection to mqtt is closed

func (*Adaptor) Finalize added in v1.0.0

func (a *Adaptor) Finalize() (err error)

Finalize returns true if connection to mqtt is finalized successfully

func (*Adaptor) Name added in v1.0.0

func (a *Adaptor) Name() string

Name returns the MQTT Adaptor's name

func (*Adaptor) On added in v1.0.0

func (a *Adaptor) On(event string, f func(s []byte)) bool

On subscribes to a topic, and then calls the message handler function when data is received

func (*Adaptor) Publish added in v1.0.0

func (a *Adaptor) Publish(topic string, message []byte) bool

Publish a message under a specific topic

func (*Adaptor) SetName added in v1.0.0

func (a *Adaptor) SetName(n string)

SetName sets the MQTT Adaptor's name

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL