當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Message.Topic方法代碼示例

本文整理匯總了Golang中git/eclipse/org/gitroot/paho/org/eclipse/paho/mqtt/golang/git.Message.Topic方法的典型用法代碼示例。如果您正苦於以下問題:Golang Message.Topic方法的具體用法?Golang Message.Topic怎麽用?Golang Message.Topic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在git/eclipse/org/gitroot/paho/org/eclipse/paho/mqtt/golang/git.Message的用法示例。


在下文中一共展示了Message.Topic方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例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())
}
開發者ID:BlackbeansSoft,項目名稱:org.eclipse.paho.mqtt.golang,代碼行數:4,代碼來源:stdoutsub.go

示例13: 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


注:本文中的git/eclipse/org/gitroot/paho/org/eclipse/paho/mqtt/golang/git.Message.Topic方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。