package main import ( "net" "sparrow/pkg/coap" "sparrow/pkg/server" ) type Access struct { CoAPBroker *coap.Broker } func NewAccess() (*Access, error) { broker := coap.NewBroker() broker.Handle("/topic/s", broker.Mgr.FuncHandler(HandlerDeviceStatus)) return &Access{ CoAPBroker: broker, }, nil } func HandlerDeviceStatus(l *net.UDPConn, a *net.UDPAddr, m coap.Message) coap.Message { server.Log.Debugf("Got message in handleA: path=%q: %#v from %v", m.GetMessageID(), m, a) if m.IsConfirmable() { res := &coap.BaseMessage{ Type: coap.ACK, Code: coap.Content, MessageID: m.GetMessageID(), Token: m.GetToken(), Payload: []byte("hello to you!"), } return res } return nil }