hybridgroup.gobot/platforms/mqtt
deadprogram eb4ce6bda5 mqtt: increase test coverage for driver
Signed-off-by: deadprogram <ron@hybridgroup.com>
2017-04-19 10:59:33 +02:00
..
LICENSE license: update license year to include 2017 2017-01-02 22:25:17 +01:00
README.md mqtt: change the On handler to take mqtt.Message. 2017-04-18 19:49:17 +02:00
doc.go docs: correct MQTT README link 2016-12-21 10:53:41 +01:00
mqtt_adaptor.go mqtt: add documentation for Message. 2017-04-18 19:51:24 +02:00
mqtt_adaptor_test.go mqtt: increase test coverage for adaptor 2017-04-19 10:46:28 +02:00
mqtt_driver.go mqtt: change the On handler to take mqtt.Message. 2017-04-18 19:49:17 +02:00
mqtt_driver_test.go mqtt: increase test coverage for driver 2017-04-19 10:59:33 +02:00

README.md

MQTT

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/driver to connect to MQTT servers. It uses the Paho MQTT Golang client package (https://eclipse.org/paho/) created and maintained by the Eclipse Foundation (https://github.com/eclipse) thank you!

For more info about the MQTT machine to machine messaging standard, go to http://mqtt.org/

How to Install

Install running:

go get -d -u gobot.io/x/gobot/... && go install gobot.io/x/gobot/platforms/mqtt

How to Use

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

package main

import (
  "gobot.io/x/gobot"
  "gobot.io/x/gobot/platforms/mqtt"
  "fmt"
  "time"
)

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

  work := func() {
    mqttAdaptor.On("hello", func(msg mqtt.Message) {
      fmt.Println(msg)
    })
    mqttAdaptor.On("hola", func(msg mqtt.Message) {
      fmt.Println(msg)
    })
    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",
    []gobot.Connection{mqttAdaptor},
    work,
  )

  robot.Start()
}

Supported Features

  • Publish messages
  • Respond to incoming message events

Contributing

For our contribution guidelines, please go to https://gobot.io/x/gobot/blob/master/CONTRIBUTING.md

License

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