/// <summary> /// Load resources associated with a specific device. /// </summary> /// <returns>a collection of CoApResource objects</returns> public override CoApResources LoadResources() { this.Send(); CoApDiscoveryResponse response = this.DiscoveryResponse; return(response.Resources); }
/// <summary> /// Load resources associated with a specific device. /// This is the CoAP Gateway implementation of CoApDiscovery. /// </summary> /// <returns>a collection of CoApResource objects</returns> /// public override CoApResources LoadResources() { // If we can't establish a socket with a good login to the gateway api, then just return; bool gotSession = false; try { gotSession = CoApGatewaySessionManager.Instance.EstablishSession(); } catch (Exception noSession) { FileLogger.Write("Error obtaining session"); FileLogger.Write(noSession.Message); FileLogger.Write(noSession.StackTrace); this.ErrorResult = "Error obtaining session" + noSession.Message; } if (!gotSession) { FileLogger.Write("Session NOT Established"); return(null); } // This represents the device being examined. string serverIP = __IpAddress; // Set up the notification handlers. CoApGatewaySessionManager.Instance.Client.CoAPResponseReceived += new CoAPResponseReceivedHandler(OnCoAPDiscoveryResponseReceived); CoApGatewaySessionManager.Instance.Client.CoAPError += new CoAPErrorHandler(OnCoAPDiscoveryError); __TimedOut = true; // Discovery requires confirmation and a message type of GET coapReq = new CoAPRequest(this.ConfirmableMessageType, CoAPMessageCode.GET, HdkUtils.MessageId()); string uriToCall = "coap://" + UriFromMac(__IpAddress) + ":" + __ServerPort + "/.well-known/core";//"/.well-known/core"; coapReq.SetURL(uriToCall); SetToken(); // Send out the coap request // JJK - Change in v2.0.7 //coapReq.Options.AddOption(CoAPHeaderOption.PROXY_SCHEME, "coap"); // make Proxy packet Change in v2.0.7 coapReq.Options.AddOption(CoAPHeaderOption.BLOCK2, new byte[] { CoAPBlockOption.BLOCK_SIZE_128 }); //coapReq.Options.AddOption(CoAPHeaderOption.PROXY_URI, "coap://SSN001350050047dc9a.SG.YEL01.SSN.SSNSGS.NET:4849/.well-known/core"); coapReq.Options.AddOption(CoAPHeaderOption.PROXY_URI, "coap://" + UriFromMac(__IpAddress) + ":" + "4849" + "/.well-known/core"); coapReq.Options.RemoveOption(CoAPHeaderOption.URI_HOST); coapReq.Options.RemoveOption(CoAPHeaderOption.URI_QUERY); coapReq.Options.RemoveOption(CoAPHeaderOption.URI_PATH); coapReq.Options.RemoveOption(CoAPHeaderOption.URI_PORT); coapReq.Options.RemoveOption(CoAPHeaderOption.CONTENT_FORMAT); // end of Changes in v2.0.7 FileLogger.Write("About to send Gateway resource request"); FileLogger.Write(coapReq.ToString()); CoApGatewaySessionManager.Instance.Client.Send(coapReq); CoApDiscoveryResponse response = null; // Wait for a response from the discovery request. // Time out after the pre-defined maximum wait time. __Done.WaitOne(GatewaySettings.Instance.RequestTimeout); response = this.DiscoveryResponse; // Reset the wait object __Done.Reset(); if (__TimedOut) { this.ErrorResult = "Request timed out"; } // Remove event handlers. CoApGatewaySessionManager.Instance.Client.CoAPResponseReceived -= new CoAPResponseReceivedHandler(OnCoAPDiscoveryResponseReceived); CoApGatewaySessionManager.Instance.Client.CoAPError -= new CoAPErrorHandler(OnCoAPDiscoveryError); return(response.Resources); }