Database Reference
In-Depth Information
bound to a specific UDP port. An instance of CoapProvider canbecreatedby
specifying which UDP port to use. This can be made by providing one or no
argument: in the former case the provided UDP port number is used (this is the
best choice for server-side applications), while in the latter a random available
port is used (this is the best choice for client-side applications). An instance of
CoapProvider can then be bound to one or more instances of CoapProviderLis-
tener s through the setListener() method. The CoapProviderListener interface
defines just one method ( onReceivedMessage() ), which is called any time the
CoapProvider receives a message that matches the filtering options that the
listener has specified. For instance, a specific listener might be interested in
processing only
requests. In order to
send a CoAP message, the CoapProvider 's send() method can be used.
The simplest and most common way to integrate mjCoAP is to use the high-
level APIs provided by the Transact ion layer, since, at this layer, the library takes
care of matching requests with their corresponding response, while also providing
reliable transmissions in case of
GET
requests, while another only
POST
messages. The Transact ion layer provides
server-side and client-side APIs for managing request-response pairs. In order to
create a client-side transaction, a new instance of CoapTransactionClient must
be created by providing two arguments: the CoapProvider object (which will
handle the messaging over a datagram socket) and an instance of a CoapTrans-
actionClientListener (which is the object which will be notified when the corre-
sponding response will be received). Requests can then be sent with the request()
method. The listener's onReceivedResponse() method will be executed when the
corresponding response is received. If the sent request is
CON
and the client
does not receive a response, the onTransactionFailure() method is called. On the
server side, an incoming CoAP message dispatched to a CoapProviderListener
can be handled by a CoapTransactionServer . In order to do so, a new instance
of CoapTransactionServer must be created by providing three arguments: the
CoapProvider object (which will handle the messaging over a datagram socket),
the received CoapMessage , and an instance of a CoapTransactionServerListener
(which is the object which will be notified in case the response delivery fails - for
CON
CON
messages only). Responses can then be sent with the respond() method.
5 CoAP Application Scenarios
The mjCoAP library has been used extensively to build a IoT application for
real-time environmental monitoring involving highly heterogeneous devices and
connectivity. An illustrative representation of the reference application scenario
is shown in Fig. 2 . The environmental monitoring application, which was used to
sense noise, light, temperature, and humidity, has been setup in order to assess
the interoperability of the mjCoAP library and other CoAP implementations,
as well as the integration of different networks through the use of IP.
The experimental setup consists in the following hardware: Raspberry Pi,
Arduino Yun, Intel Galileo, Zolertia Z1, and Android smartphones. Table 2 shows
the list of hardware and software used for the demonstrative IoT application.
Search WWH ::




Custom Search