mqtt mockup

This commit is contained in:
2019-09-20 22:14:41 +02:00
parent 56ad55b967
commit c4567d780c
2 changed files with 153 additions and 0 deletions

37
poc/mqtt.go Normal file
View File

@@ -0,0 +1,37 @@
package main
import (
"fmt"
"time"
MQTT "github.com/eclipse/paho.mqtt.golang"
)
func main() {
opts := MQTT.NewClientOptions()
opts.AddBroker("tcp://127.0.0.1:1883")
opts.SetClientID("ortobio")
opts.SetUsername("DVES_USER")
opts.SetPassword("DVES_PASS")
opts.SetCleanSession(false)
client := MQTT.NewClient(opts)
if token := client.Connect(); token.Wait() && token.Error() != nil {
panic(token.Error())
}
fmt.Println("Sample Publisher Started")
qos := 0
for i := 0; i < 3; i++ {
fmt.Println("---- doing publish ----", i)
token := client.Publish("ciaouno", byte(qos), false, fmt.Sprintf("%d", i))
token.Wait()
time.Sleep(300 * time.Millisecond)
}
client.Disconnect(250)
fmt.Println("Sample Publisher Disconnected")
}