gobot.io/x/gobot@v1.16.0/platforms/mqtt/README.md (about) 1 # MQTT 2 3 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. 4 5 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! 6 7 For more info about the MQTT machine to machine messaging standard, go to http://mqtt.org/ 8 9 ## How to Install 10 11 Install running: 12 13 ``` 14 go get -d -u gobot.io/x/gobot/... 15 ``` 16 17 ## How to Use 18 19 Before running the example, make sure you have an MQTT message broker running somewhere you can connect to 20 21 ```go 22 package main 23 24 import ( 25 "gobot.io/x/gobot" 26 "gobot.io/x/gobot/platforms/mqtt" 27 "fmt" 28 "time" 29 ) 30 31 func main() { 32 mqttAdaptor := mqtt.NewAdaptor("tcp://0.0.0.0:1883", "pinger") 33 34 work := func() { 35 mqttAdaptor.On("hello", func(msg mqtt.Message) { 36 fmt.Println(msg) 37 }) 38 mqttAdaptor.On("hola", func(msg mqtt.Message) { 39 fmt.Println(msg) 40 }) 41 data := []byte("o") 42 gobot.Every(1*time.Second, func() { 43 mqttAdaptor.Publish("hello", data) 44 }) 45 gobot.Every(5*time.Second, func() { 46 mqttAdaptor.Publish("hola", data) 47 }) 48 } 49 50 robot := gobot.NewRobot("mqttBot", 51 []gobot.Connection{mqttAdaptor}, 52 work, 53 ) 54 55 robot.Start() 56 } 57 ``` 58 59 ## Supported Features 60 61 * Publish messages 62 * Respond to incoming message events 63 64 ## Contributing 65 66 For our contribution guidelines, please go to https://gobot.io/x/gobot/blob/master/CONTRIBUTING.md 67 68 ## License 69 70 Copyright (c) 2013-2018 The Hybrid Group. Licensed under the Apache 2.0 license.