示例#1
0
        public async Task HandleNotificationAsync(CoAP.Server.Resources.CoapExchange exchange)
        {
            var request = exchange.Request;
            var body    = request.PayloadString;

            Trace.WriteLine("\n!!!!!!!!!!!!!!!!");
            foreach (var option in request.GetOptions())
            {
                Trace.WriteLine($"{option.Name}: ({option.Type}) {option.Value}");
            }

            Trace.WriteLine("");
            if (body != null)
            {
                try
                {
                    Trace.WriteLine(JsonConvert.SerializeObject(JsonConvert.DeserializeObject(body), Formatting.Indented));
                }
                catch
                {
                    Trace.WriteLine(body);
                }
            }

            var notification = ParseNotification(request);

            if (notification != null)
            {
                _notifications.OnNext(notification);

                var response = Response.CreateResponse(request, StatusCode.Content);

                /*
                 * foreach(var uri in notification.NotificationEvent.PrimitiveRepresentation.ResponseType?.NotificationURI ?? Array.Empty<string>())
                 *      response.SetOption(Option.Create((CoAP.OptionType) OneM2mRequestOptions.RTURI, uri));
                 *
                 */
                //response.SetOption(Option.Create((CoAP.OptionType) OneM2mRequestOptions.RQI, notification.RequestIdentifier));
                exchange.Respond(response);
            }
        }
示例#2
0
 protected override void DoPut(CoAP.Server.Resources.CoapExchange exchange)
 {
     exchange.Respond(payload);
 }
示例#3
0
 protected override void DoPost(CoAP.Server.Resources.CoapExchange exchange)
 {
     _postHandler(exchange).Wait();
 }