User Tools

Site Tools


This is an old revision of the document!

Resource Observe

Observe happens at Resource level and operates in server/client model. Handling of observation registration is application specific. Server application decides whether resource is observable and when to send the observe notification. Client application fetches and registers as an observer for the resource. Notifications from the server to the client may be confirmable or non-confirmable, which can be specified in application via QoS levels.

Sequence Diagram

Call Flow

Once initialization has been setup server side, server can declare resource property attributes to be observable to enable remote devices to subscribe to changes.

Sample Application :

The following Samples in resource directory provide good examples to use observe APIs.

  • Sample with basic observe feature for server side: resource/examples/simpleserver.cpp
  • Sample with basic observe feature for client side: resource/examples/simpleclient.cpp

Step 1: Server declares the resource attribute as “OC_OBSERVABLE” while creating resource.

  uint8_t resourceFlag = OC_DISCOVERABLE | OC_OBSERVABLE;
  result = OCPlatform::registerResource//
                 ( handle,
                   resourceInterface, //
                   resourceFlag); //

Step 2: Client sets observation on the resource.

OCResource::observe(OBSERVE_TYPE_TO_USE, QueryParamsMap(), &observeHandler, qos);

The client specifies how it wants to observe via OBSERVE_TYPE_TO_USE. QueryParamsMap() us the map which can have the query parameter name and value. observeHandler is the callback handling observation result. qos is to specify the communication quality, e.g. specifying the notification to be confirmable or non-confirmable.

An example of observehandler can look like -

void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& rep,
                    const int& eCode, const int& sequenceNumber)
  * Function body

References :

Previously published documentation which this (living) wiki page is based on :

resource_observe.1469444312.txt.gz · Last modified: 2016/07/25 10:58 by Ziran Sun