本文整理汇总了Golang中git/eclipse/org/gitroot/paho/org/eclipse/paho/mqtt/golang/git.Message类的典型用法代码示例。如果您正苦于以下问题:Golang Message类的具体用法?Golang Message怎么用?Golang Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: HandleMqttMessage
func HandleMqttMessage(client *MQTT.Client, msg MQTT.Message) {
var r message.Response
if err := json.Unmarshal(msg.Payload(), &r); err != nil {
log.Println(err)
return
}
log.Printf("Incoming: %v", r)
if ch, ok := chanMap[r.RequestId]; ok {
ch <- r
}
}
开发者ID:callumj,项目名称:iot-router,代码行数:11,代码来源:http.go
示例2: NewEvent
// NewEvent -
func NewEvent(msg MQTT.Message) (Event, error) {
e := Event{Message: msg}
decoder := json.NewDecoder(bytes.NewReader(msg.Payload()))
if err := decoder.Decode(&e); err != nil {
return e, err
}
if err := e.Validate(); err != nil {
return e, err
}
return e, nil
}
开发者ID:powerunit-io,项目名称:platform,代码行数:16,代码来源:event.go
示例3: commandHandler
func (d *Device) commandHandler(client *MQTT.Client, msg MQTT.Message) {
cmd := protocol.Command{}
err := cmd.UnMarshal(msg.Payload())
if err != nil {
fmt.Println(err)
return
}
switch cmd.Head.No {
case commonCmdGetStatus:
d.reportStatus(client)
default:
fmt.Printf("received command : %v: %v", cmd.Head.No, cmd.Params)
}
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:16,代码来源:device.go
示例4: publishHandler
func (self *Subscriber) publishHandler(client *MQTT.MqttClient, msg MQTT.Message) {
body := string(msg.Payload())
event := pubsub.Parse(body)
if event == nil {
return
}
self.channelsLock.Lock()
// fmt.Printf("Event: %+v\n", event)
for _, ch := range self.channels {
if ch.filter(event) {
// fmt.Printf("Sending to: %+v\n", ch.topics)
ch.C <- event
}
}
self.channelsLock.Unlock()
}
开发者ID:kienhung,项目名称:gohome,代码行数:16,代码来源:subscriber.go
示例5: BrokerHandler
// BrokerHandler -
func (c *Connection) BrokerHandler(client *MQTT.Client, msg MQTT.Message) {
c.Info(
"Received new mqtt (worker: %s) - (message: %s) for (topic: %s). Building event now ...",
c.Name(), msg.Payload(), msg.Topic(),
)
event, err := events.NewEvent(msg)
if err != nil {
c.Error("Could not handle received event due to (err: %s)", err)
return
}
c.Info("Event successfully created (data: %v)", event)
c.events <- event
}
开发者ID:powerunit-io,项目名称:platform,代码行数:17,代码来源:connection.go
示例6: statusHandler
func (d *Device) statusHandler(client *MQTT.Client, msg MQTT.Message) {
status := protocol.Data{}
err := status.UnMarshal(msg.Payload())
if err != nil {
fmt.Println(err)
return
}
fmt.Println("device receiving status set : ")
for _, one := range status.SubData {
fmt.Println("subdeviceid : ", one.Head.SubDeviceid)
fmt.Println("no : ", one.Head.PropertyNum)
fmt.Println("params : ", one.Params)
}
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:17,代码来源:device.go
示例7: onMessageReceived
func (b *Broker) onMessageReceived(client *MQTT.Client, m MQTT.Message) {
log.Debugf("topic:%s / msg:%s", m.Topic(), m.Payload())
msg := message.Message{
Sender: b.Name,
Type: message.TypeSubscribed,
Body: m.Payload(),
Topic: m.Topic(),
}
b.GwChan <- msg
}
开发者ID:chansuke,项目名称:fuji,代码行数:11,代码来源:broker.go
示例8: handleMessage
// messageHandler is called when a new message arrives
func handleMessage(client *MQTT.Client, msg MQTT.Message) {
// Unmarshal JSON to RxPacket
var packet shared.RxPacket
err := json.Unmarshal(msg.Payload(), &packet)
if err != nil {
log.WithField("topic", msg.Topic()).WithError(err).Warn("Failed to unmarshal JSON.")
return
}
// Filter messages by gateway
if gateway != "" && packet.GatewayEui != gateway {
return
}
// Decode payload
data, err := base64.StdEncoding.DecodeString(packet.Data)
if err != nil {
log.WithField("topic", msg.Topic()).WithError(err).Warn("Failed to decode Payload.")
return
}
ctx := log.WithFields(log.Fields{
"devAddr": packet.NodeEui,
})
if showMeta {
ctx = ctx.WithFields(log.Fields{
"gatewayEui": packet.GatewayEui,
"time": packet.Time,
"frequency": *packet.Frequency,
"dataRate": packet.DataRate,
"rssi": *packet.Rssi,
"snr": *packet.Snr,
})
}
if showRaw {
ctx = ctx.WithField("data", fmt.Sprintf("%x", data))
}
if showTiming {
rawData, err := base64.StdEncoding.DecodeString(packet.Data)
if err == nil {
airtime, err := util.CalculatePacketTime(len(rawData), packet.DataRate)
if err == nil {
ctx = ctx.WithField("airtime", fmt.Sprintf("%.1f ms", airtime))
}
}
}
// Check for unprintable characters
unprintable, _ := regexp.Compile(`[^[:print:]]`)
if unprintable.Match(data) {
ctx.Debug("Received Message")
} else {
ctx.WithField("message", fmt.Sprintf("%s", data)).Info("Received Message")
}
}
开发者ID:batulzii,项目名称:ttntool,代码行数:61,代码来源:follow.go
示例9: mqttMsgToWolfMsg
func mqttMsgToWolfMsg(msg MQTT.Message) models.IncomingPacket {
inMsg := models.IncomingPacket{}
inMsg.Message = string(msg.Payload())
inMsg.Topic = msg.Topic()
inMsg.QoS = int(msg.Qos())
return inMsg
}
开发者ID:shalinlk,项目名称:wolf,代码行数:7,代码来源:connection.go
示例10: MsgRecvfun
func MsgRecvfun(client *MQTT.Client, msg MQTT.Message) {
appUpChan <- msg.Topic()
fmt.Printf("appUp")
fmt.Printf("topic:[%s] ", msg.Topic())
fmt.Printf("Mesg:%s\n", msg.Payload())
}
开发者ID:huoyan108,项目名称:dataRelayGo,代码行数:7,代码来源:routing.go
示例11: messageHandler
func messageHandler(client *mqtt.MqttClient, message mqtt.Message) {
var data interface{}
if strings.HasSuffix(options.ContentType, "json") {
err = json.Unmarshal(message.Payload(), &data)
if err != nil {
log.Println("ERROR unmarshaling the JSON message:", err.Error())
return
}
} else {
// TODO: support other content-types
log.Printf("WARNING processing of %s is not supported", options.ContentType)
return
}
prop, err := propTemplate.Fill(data)
if err != nil {
log.Println("ERROR filling template with data: ", err.Error())
return
}
out, _ := json.Marshal(prop)
propPort.SendMessage(runtime.NewPacket(out))
}
开发者ID:voxadam,项目名称:cascades-caf,代码行数:22,代码来源:main.go
示例12: onMessageReceived
func onMessageReceived(client *MQTT.MqttClient, message MQTT.Message) {
fmt.Printf("Received message on topic: %s\n", message.Topic())
fmt.Printf("Message: %s\n", message.Payload())
if string(message.Payload()) == "ぬるぽ" {
Publish(client, "say", "ガッ")
}
}
开发者ID:kyokomi-sandbox,项目名称:sandbox,代码行数:8,代码来源:mqtt.go
示例13: onMessageReceived
func (m *MqttClient) onMessageReceived(client *MQTT.Client, message MQTT.Message) {
log.Infof("topic:%s", message.Topic())
// Remove topic root
ct := strings.TrimRight(m.Config.Topic, "#")
topic := strings.Replace(message.Topic(), ct, "", 1)
chun := Message{
Topic: topic,
Payload: message.Payload(),
}
m.mqttChan <- chun
}
开发者ID:wolfeidau,项目名称:mqforward,代码行数:14,代码来源:mqtt.go
示例14: actionHandler
func actionHandler(client *MQTT.Client, message MQTT.Message) {
fmt.Println("Received action message on", message.Topic(), "-", string(message.Payload()))
action := strings.ToLower(string(message.Payload()))
switch action {
case "off":
host.LedsOff()
case "on":
host.LedsOn()
case "toggle":
host.LedsToggle()
case "slide":
host.LedsCycle(3)
}
}
开发者ID:alsm,项目名称:goIoT,代码行数:14,代码来源:main.go
示例15: messageHandler
func (d *Device) messageHandler(client *MQTT.Client, msg MQTT.Message) {
fmt.Printf("TOPIC: %s\n", msg.Topic())
fmt.Printf("MSG: %x\n", msg.Payload())
msgtype := msg.Topic()
fmt.Println(msgtype)
switch msgtype {
case "c":
d.commandHandler(client, msg)
case "s":
d.statusHandler(client, msg)
default:
fmt.Println("unsuported message type :", msgtype)
}
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:15,代码来源:device.go
示例16: messageReceived
func messageReceived(client *MQTT.Client, msg MQTT.Message) {
topics := strings.Split(msg.Topic(), "/")
msgFrom := topics[len(topics)-1]
fmt.Print(msgFrom + ": " + string(msg.Payload()))
}
开发者ID:zhoudianyou,项目名称:gochat-mqtt,代码行数:5,代码来源:gochat-mqtt.go
示例17: brokerClientsHandler
func brokerClientsHandler(client *MQTT.Client, msg MQTT.Message) {
brokerClients <- true
fmt.Printf("BrokerClientsHandler ")
fmt.Printf("[%s] ", msg.Topic())
fmt.Printf("%s\n", msg.Payload())
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:6,代码来源:routing.go
示例18: onMessageReceived
func onMessageReceived(client *MQTT.MqttClient, message MQTT.Message) {
log.Infof("topic:%s / msg:%s", message.Topic(), message.Payload())
fmt.Println(string(message.Payload()))
}
开发者ID:kgbu,项目名称:mqttcli,代码行数:4,代码来源:mqtt.go
示例19: onMessageReceived
func onMessageReceived(client *MQTT.MqttClient, message MQTT.Message) {
fmt.Printf("Received message on topic: %s\n", message.Topic())
fmt.Printf("Message: %s\n", message.Payload())
}
开发者ID:BlackbeansSoft,项目名称:org.eclipse.paho.mqtt.golang,代码行数:4,代码来源:stdoutsub.go
示例20: decodeRequest
func (b *Bus) decodeRequest(msg *mqtt.Message, data interface{}) error {
return json.NewDecoder(bytes.NewBuffer(msg.Payload())).Decode(data)
}
开发者ID:ninjasphere,项目名称:mqtt-bridgeify,代码行数:3,代码来源:bus.go
注:本文中的git/eclipse/org/gitroot/paho/org/eclipse/paho/mqtt/golang/git.Message类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论