This repository has been archived on 2025-02-01. You can view files and clone it, but cannot push or open issues or pull requests.
esp8266-temperature/messaging-mqtt/emitter-counter-pub.go
2018-04-20 09:43:56 +02:00

30 lines
663 B
Go

package main
import (
"fmt"
emitter "github.com/emitter-io/go"
"time"
)
func main() {
// Create the options with default values
o := emitter.NewClientOptions()
o.AddBroker("tcp://localhost:1883")
o.SetClientID("go-emitter-publish")
// Create a new emitter client and connect to the broker
c := emitter.NewClient(o)
sToken := c.Connect()
if sToken.Wait() && sToken.Error() != nil {
panic("Error on Client.Connect(): " + sToken.Error().Error())
}
for i := 0; i < 1000; i ++ {
text := fmt.Sprintf("Message %d", i)
token := c.Publish("abqGF3nbCeYIYzOckDrU1vOq6uuU16rb", "test/counter", text)
token.Wait()
time.Sleep(5 * time.Second)
}
}