Multiple Callback for GET_POST_Allowed object

I have created my new object under 3336/0/0, with following method.

static M2MResource location_res = add_resource(&obj_list, 3336, 0, 0, “Location_resource”, M2MResourceInstance::STRING,M2MBase::GET_POST_ALLOWED, “”, false, callback(&get_location));*

I have set callback for get_location.

once i use post option for this object from cloud page, my callback is triggered for 5 times.

I was expecting it should be for 1 time only.

I have analysed, every 2 sec my callback is triggered for 5 times.

if my callback is finished within 2 sec, i am not getting multiple trigger.

is it the right behaviour ??

If yes, Is there is any way , so i can send response to cloud, so that it can not trigger again and again ??

Hi, could you confirm which SDK you are using? Thanks

Hi ispacedroid,

I’ve seen similar behavior to this before. I believe the callback needs to finish quickly, otherwise Mbed Cloud will reissue the POST message to the device, triggering your callback again.

I’d recommend having your callback only set a flag by using some of the RTOS synchronization features to trigger your longer-running analyze step in a separate thread. Here’s the docs page on the RTOS apis: https://os.mbed.com/docs/v5.7/reference/rtos.html

Hope that helps, let me know if you have further questions!

Thanks,
Brian

So what Brian has said is correct, the retry mechanism kicks in when your callback does not finish fast enough. You can either use a Semaphore to switch from the callback back to main thread and execute there, or use mbed-events to do so.

F.e.:

static M2MResource location_res = add_resource(&obj_list, 3336, 0, 0, 
    "Location_resource", M2MResourceInstance::STRING,M2MBase::GET_POST_ALLOWED, 
    "", false, 
    queue.event(&get_location)); // <-- this is eventqueue magic

Will execute get_location on the event loop rather than blocking the POST. This should resolve any issues you see.