`
男人50
  • 浏览: 239193 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

gobot.io/x/gobot/platforms/mqtt

    博客分类:
  • go
 
阅读更多
package main

import (
  "gobot.io/x/gobot"
  "gobot.io/x/gobot/platforms/mqtt"
  "fmt"
  "time"
)

func main() {
  mqttAdaptor := mqtt.NewAdaptor("tcp://0.0.0.0:1883", "pinger")

  work := func() {
    mqttAdaptor.On("hello", func(msg mqtt.Message) {
      fmt.Println(msg)
    })
    mqttAdaptor.On("hola", func(msg mqtt.Message) {
      fmt.Println(msg)
    })
    data := []byte("o")
    gobot.Every(1*time.Second, func() {
      mqttAdaptor.Publish("hello", data)
    })
    gobot.Every(5*time.Second, func() {
      mqttAdaptor.Publish("hola", data)
    })
  }

  robot := gobot.NewRobot("mqttBot",
    []gobot.Connection{mqttAdaptor},
    work,
  )

  robot.Start()
}
使用 mqttAdaptor.Publish可以发送消息 mqttAdaptor.On 可以订阅消息,如果有用户验证可以使用如下方式:

mqttAdaptor = mqtt.NewAdaptorWithAuth(
"EMQ.host",
"EMQ.clientID",
"EMQ.userName",
"EMQ.passWordActive",
)
断开也可以配置重连规则自动重连(默认未开启,作为服务端强烈建议开启)

mqttAdaptor.SetAutoReconnect(true)
以及消息清理机制(默认断开连接清理消息)

mqttAdaptor.SetCleanSession(false)
也可以指定使用TLS证书连接

mqttAdaptor.SetUseSSL(true)
# 下面可以指定证书(如果EMQ使用了标准的CA证书下面就不用配置了)
mqttAdaptor.SetClientKey(`/client/client-key.pem`)
mqttAdaptor.SetClientCert(`/client/client-cert.pem`)
分享到:
评论

相关推荐

    14.0真机调试包 安装路径:/应用程序/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/De

    Xcode的安装路径在描述中给出,位于"/应用程序/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/De"。这个路径揭示了Xcode的内部结构,其中“/应用程序/”是MacOS系统的应用程序目录,“Xcode.app”是...

    13.6真机调试包 安装路径:/应用程序/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/De

    每个版本的iOS都会有一个对应的子目录,例如,针对iOS 13.6的子目录可能是 `./DeviceSupport/13.6 (17G70)`,其中包含了用于真机调试的固件信息和模拟器所需的数据。 四、设备支持文件的作用 设备支持文件包含了与...

    解决Xcode10以上编译报错 library not found for "-lstdc++.6"

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/ 模拟器 dylib放到这个路径 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS....

    gobot:用于机器人技术,无人机和物联网(IoT)的Golang框架

    "gobot.io/x/gobot/platforms/firmata" ) func main () { firmataAdaptor := firmata . NewAdaptor ( "/dev/ttyACM0" ) led := gpio . NewLedDriver ( firmataAdaptor , "13" ) work := func () { gobot . ...

    paho.mqtt.embedded-c-1.0.0

    # Eclipse Paho MQTT C/C++ client for Embedded platforms This repository contains the source code for the [Eclipse Paho](http://eclipse.org/paho) MQTT C/C++ client library for Embedded platorms.

    xcode ios12.4真机调试包12.4 (16G73).zip

    xcode ios12.4真机调试包 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport

    ios12.3真机调试包.zip

    IOS12.3 beta版真机调试包,真机运行的支持包的位置位于:Xcode.app//Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport,直接解压拷贝进去即可使用

    iOS SDK 14.0真机调试包

    打开Finder 按下: command+shift+g 输入: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport 把文件解压到这个文件夹下,重新启动Xcode,连上真机运行 This iPhone X is ...

    libstdc++.6.0.9.tbd

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libstdc++.6.0.9.dylib ...

    https://ieeexplore.ieee.org/document/7442371

    An Open Source Content Decryption Module to Improve DRM Integration with HTML5 Platforms https://ieeexplore.ieee.org/document/7442371

    Xcode12 libsted++

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/ //模拟器 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/...

    xcode iOS12.3 真机镜像DeveloperDiskImage.sig

    路径/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/对应版本/: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/10.3.1\ \(14E...

    xcode iOS12.3 DeveloperDiskImage真机调试镜像

    路径参考/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/对应版本/: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/10.3.1\ \...

    xcode iOS12.4 DeveloperDiskImage真机调试镜像

    路径参考/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/对应版本/: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/10.3.1\ \...

    Libstdc-.6.0.9-files-master.zip

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/ For Simulator Put dylib copy to the path: /Applications/Xcode.app/Contents/Developer/...

    libstdc++.6.0.9.tbd相关文件.zip

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/...

    Xcode10中删除的`libstdc++`库

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/ /Applications/Xcode.app...

    DeviceSupport 支持6.0 -11.3

    devzkndeMacBook-Pro:Platforms devzkn$ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport devzkndeMacBook-Pro:Platforms devzkn$ open /Applications/Xcode8.3.3.app/...

    -libstdc++.zip

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/ 模拟器 将tdb副本放到下面路径中: /Applications/Xcode.app/Contents/Developer/Platforms/...

Global site tag (gtag.js) - Google Analytics