forked from OpenPDU/openpdu
mqtt mockup
This commit is contained in:
37
poc/mqtt.go
Normal file
37
poc/mqtt.go
Normal 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")
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user