emqx-agent.go 583 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "fmt"
  4. "sparrow/pkg/protocol"
  5. )
  6. type Agent struct {
  7. }
  8. // Message 收到设备上报消息处理
  9. func (a *Agent) Message(topic string, payload []byte) error {
  10. fmt.Printf("%s, %s\r\n", topic, payload)
  11. return nil
  12. }
  13. // Connected 设备接入时
  14. func (a *Agent) Connected(status *protocol.DevConnectStatus) error {
  15. fmt.Printf("%v\r\n", status)
  16. return nil
  17. }
  18. // Disconnected 设备断开连接时
  19. func (a *Agent) Disconnected(status *protocol.DevConnectStatus) error {
  20. fmt.Printf("%v\r\n", status)
  21. return nil
  22. }
  23. func NewAgent() *Agent {
  24. return &Agent{}
  25. }