一个基于控制台的GUI界面,输入文本框和显示界面
Console GUI :https://www.jianshu.com/p/b9f686f5a317
一个MQTT SDK
MQTT SDK :https://github.com/eclipse/paho.mqtt.golang 参考代码:
package main
import (
"fmt"
//import the Paho Go MQTT library
MQTT "github.com/eclipse/paho.mqtt.golang"
"os"
"time"
)
//define a function for the default message handler
var f MQTT.MessageHandler = func(client MQTT.Client, msg MQTT.Message) {
fmt.Printf("TOPIC: %s\n", msg.Topic())
fmt.Printf("MSG: %s\n", msg.Payload())
}
func main() {
//create a ClientOptions struct setting the broker address, clientid, turn
//off trace output and set the default message handler
opts := MQTT.NewClientOptions().AddBroker("tcp://192.168.3.102:1883")
opts.SetClientID("go-simple")
opts.SetDefaultPublishHandler(f)
//create and start a client using the above ClientOptions
c := MQTT.NewClient(opts)
if token := c.Connect(); token.Wait() && token.Error() != nil {
panic(token.Error())
}
//subscribe to the topic /go-mqtt/sample and request messages to be delivered
//at a maximum qos of zero, wait for the receipt to confirm the subscription
if token := c.Subscribe("go-mqtt/sample", 0, nil); token.Wait() && token.Error() != nil {
fmt.Println(token.Error())
os.Exit(1)
}
//Publish 5 messages to /go-mqtt/sample at qos 1 and wait for the receipt
//from the server after sending each message
for i := 0; i < 5; i++ {
text := fmt.Sprintf("this is msg #%d!", i)
token := c.Publish("go-mqtt/sample", 0, false, text)
token.Wait()
}
time.Sleep(3 * time.Second)
//unsubscribe from /go-mqtt/sample
if token := c.Unsubscribe("go-mqtt/sample"); token.Wait() && token.Error() != nil {
fmt.Println(token.Error())
os.Exit(1)
}
c.Disconnect(250)
}
一个GO语言的跨平台GUI界面库
GUI :https://github.com/fyne-io/fyne
如果这篇文章对您很有帮助,不妨
----- 本文结束 ❤ 感谢您的阅读 ----
上一篇
C# 多线程操作
下一篇
MQTT 服务器搭建基于树莓派
- 本文作者: Memory
- 本文链接: https://www.mzpkz.top/post/2019-08-02/
- 版权声明: 本博客所有文章除特别声明外,转载请注明出处!