/// <summary>
        /// Entry point
        /// </summary>
        public static void Main()
        {
            NetworkHelpers.SetupAndConnectNetwork();

            string serverIP   = "localhost";
            int    serverPort = 5683;

            coapClient = new CoAPClientChannel();
            coapClient.Initialize(serverIP, serverPort);
            coapClient.CoAPResponseReceived += new CoAPResponseReceivedHandler(OnCoAPResponseReceived);
            coapClient.CoAPRequestReceived  += new CoAPRequestReceivedHandler(OnCoAPRequestReceived);
            coapClient.CoAPError            += new CoAPErrorHandler(OnCoAPError);
            //Send a NON request to get the temperature...in return we will get a NON request from the server
            CoAPRequest coapReq = new CoAPRequest(CoAPMessageType.NON,
                                                  CoAPMessageCode.GET,
                                                  100);//hardcoded message ID as we are using only once
            string uriToCall = "coap://" + serverIP + ":" + serverPort + "/sensors/temp";

            coapReq.SetURL(uriToCall);
            _mToken       = DateTime.Today.ToString("HHmmss"); //Token value must be less than 8 bytes
            coapReq.Token = new CoAPToken(_mToken);            //A random token
            coapClient.Send(coapReq);
            Thread.Sleep(Timeout.Infinite);                    //blocks
            while (true)
            {
                Thread.Sleep(3000);
            }
        }
        public override void Send()
        {
            string serverIP = __IpAddress;

            __coapClient = new CoAPClientChannel();

            __coapClient.Initialize(serverIP, __ServerPort);
            __coapClient.CoAPResponseReceived += new CoAPResponseReceivedHandler(OnCoAPResponseReceived);
            __coapClient.CoAPRequestReceived  += new CoAPRequestReceivedHandler(OnCoAPRequestReceived);
            __coapClient.CoAPError            += new CoAPErrorHandler(OnCoAPError);
            //Send a NON request to get the temperature...in return we will get a NON request from the server
            coapReq = new CoAPRequest(CoAPMessageType.RST,
                                      CoAPMessageCode.GET,
                                      HdkUtils.MessageId());          //hardcoded message ID as we are using only once
            string uriToCall = "coap://" + serverIP + ":" + __ServerPort + __URI;

            coapReq.SetURL(uriToCall);
            __Token       = DateTime.Now.ToString("HHmmss"); //Token value must be less than 8 bytes
            coapReq.Token = new CoAPToken(__Token);          //A random token
            __coapClient.Send(coapReq);
            __Done.WaitOne();
            __Done.Reset();
            __Done.Close();
            __Done = null;
            __coapClient.Shutdown();
            __coapClient = null;
        }
 private void InitializeClient()
 {
     _coapClient = new CoAPClientChannel();
     _coapClient.Initialize(serverIP, serverPort);
     _coapClient.CoAPResponseReceived += new CoAPResponseReceivedHandler(OnCoAPResponseReceived);
     _coapClient.CoAPRequestReceived  += new CoAPRequestReceivedHandler(OnCoAPRequestReceived);
     _coapClient.CoAPError            += new CoAPErrorHandler(OnCoAPError);
 }
Beispiel #4
0
 /// <summary>
 /// Setup the client
 /// </summary>
 private static void SetupClient()
 {
     coapClient = new CoAPClientChannel();
     coapClient.Initialize("localhost", 5683);
     coapClient.CoAPError            += new CoAPErrorHandler(OnCoAPError);
     coapClient.CoAPRequestReceived  += new CoAPRequestReceivedHandler(OnCoAPRequestReceived);
     coapClient.CoAPResponseReceived += new CoAPResponseReceivedHandler(OnCoAPResponseReceived);
 }
 /// <summary>
 /// Default constructor.
 /// </summary>
 public CoApBase()
 {
     __coapClient = new CoAPClientChannel();
 }