Search code examples
iotgetresourcecoapcustom-receiver

COAP as a Streaming Source


I am currently working on IOT Coap protocol.I accessed server on local host through copper firefox plugin. Then i Added resouce having "GET" functionality in server. After that i made its client as a streaming source. Here is the code of client streaming

 class customReceiver(test:String) extends  Receiver[String](StorageLevel.MEMORY_AND_DISK_2) with Logging with Serializable { 
   @volatile private var stopped = false
   override def onStart() {

      val client = new CoapClient("ip/resource")
      var text = client.get().getResponseText();  
      store(text)
   }
   override def onStop(): Unit = synchronized { 
      try
      {
         stopped = true
      }
      catch
      {
         case e: Exception => println("exception caught: " + e);
      }
   }
 }

but i am facing a problem. During streaming it just read a resource once. after that it fetches all empty rdd and completes its batches. Meanwhile if resource changes its value it doesn't read that. are i doing something wrong? or is there exists any other functionality to read whenever resource get changed that i can handle in my Custom receiver.? or any idea about how to GET value continuously during streaming?

Any help is much awaited and appreciated. Thanks


Solution

  • Streaming of data is application implementation.

    • 1] You can subscribe the resource as observer. The observer functionality has to be implemented in your application.
    • 2] You can continuously send data in interval using PUT functionality.

    A good OBSERVE example is provided in libcoap, where client (firefox copper) observes the "time" resource of server (coap-server). coap-server continuously sends CON message of time and date to client, since time changes very second. In turn client send ACK message.

    Also CoAP combined with TCP functionality is better suitable for streaming of data.