ARMmbed / mbed-client

DEPRECATED: C++ API for mbed-client
https://cloud.mbed.com/docs/current
Apache License 2.0
53 stars 85 forks source link

Put request handling for Lwm2m: No Api to read the data sent against a particular resource. #523

Closed UsmanKhan7171 closed 6 years ago

UsmanKhan7171 commented 6 years ago

I am implementating the lightning control use case. For this I need to send the PUT command from leshan to my target board. When I send "true" from Leshan, I need to have an Api in the M2MBase class to read this value for me so that I can turn my light ON and vice versa. But I don't find any Api which does this job for me, i.e extract the value sent in the payload from leshan against a particular resource. In the M2MBase class, I can get the name() , uri_path() as well as type() against an object when a PUT request is received, but not the value(true/false) sent in the payload against a particular resource. Therefore I had to incorporate a function that returns "_sn_resource->dynamic_resource_params->resource;" and implemented my On/Off logic for lightening control based on this. If there already is a function for this, kindly let me know. If there isn't pl incorporate.

ciarmcom commented 6 years ago

ARM Internal Ref: IOTCLT-2465

yogpan01 commented 6 years ago

There is a API in M2MResourceBase to read the values. In the application, you will get notification through callback value_updated() which will inform which Resource value is updated. Check mbed-os-example-client to see how it works.

UsmanKhan7171 commented 6 years ago

void value_updated(M2MBase *base, M2MBase::BaseType type) { printf("\r\nPUT Request Received!"); printf("\r\nName :'%s', \r\nPath : '%s', \r\nType : '%d' (0 for Object, 1 for Resource), \r\nType : '%s'\r\n", base->name(), base->uri_path(), type, base->resource_type() ); }

This is the body of callback, and in it, I can't see the value against the resource. What I can see in here are APIs for name, uri_path , type and resource_type. And if you I into a little detail, where these APIs are actually declared, I still can't find the API for the value sent against resource in the PUT payload from leshan. If there is any, can you please name it?

JanneKiiskila commented 6 years ago

Hi,

this might be useful;

https://github.com/ARMmbed/mbed-os-example-client/blob/master/main.cpp#L196-L199

You can get the value just by getting it.

       // values in mbed Client are all buffers, and we need a vector of int's
        uint8_t* buffIn = NULL;
        uint32_t sizeIn;
        res->get_value(buffIn, sizeIn);

In that case it is pulling in a string, but it should be the same for a bool as well.