method.exec

The method.exec command is used to execute a method call for a Thing.

TR50 Request
{
  "cmd": {
    "command": "method.exec",
    "params": {
      "thingKey": "mything",
      "method": "methodName",
      "ackTimeout": 30,
      "params": {
        "paramKey": "paramValue" 
      }
    }
  }
}
  • If ackTimeout is not set in the method.exec then the Default method timeout is used as the ackTimeout. The Default method timeout (defaultAckTimeout)is set while creating the Thing Definition. For more information, see thing_def.create.

Request Parameters

Name Type Required Description
thingKey String Yes Identifies the thing to which the method call is to be associated. This parameter may also contain a mailbox alias.
method String Yes The method you wish to execute on the thing.
ackTimeout Integer Acknowledge timeout duration in seconds (maximum of 300).
ttl Integer The time to live of the message. Defaults to the ackTimeout.
params Object Notification variables or method parameters to be executed with the method.

If you want this command to return the results directly, the ackTimeout value must be specified, either directly as a parameter, or as a default in the Thing Definition configuration for the method.

TR50 Response

If the command is sent successfully (and the command executes via the mailbox system with an ackTimeout value greater than zero), a success message is returned along with any results from the mailbox interaction. Otherwise, an error and error message will be returned.

{
    "data": {
        "success": true,
        "params": {
            ...
        }
    }
}

If the command is sent successfully (and the command executes via the mailbox system with an ackTimeout value less than 1), a success message is returned along with the mailbox ID. Otherwise, an error and error message will be returned.

{
    "data": {
        "success": true,
        "params": {
            "id": "64dbaf0a14c9781016451510"
        }
    }
}

If the command is sent successfully (and the command executes via the trigger system), a success message is returned along with any results from the trigger execution. Otherwise an error and error message will be returned.

{
    "data": {
        "success": true,
        "params": {
            ...
        }
    }
}

Response Parameters

Name Type Description
params Object The completion variables returned by the method's execution if any.
C API
// basic API
int tr50_method_exec(void *tr50, const char *method, JSON* params);
 
// extended API
int tr50_method_exec_ex_sync(void *tr50, const char *method, JSON* req_params, void* optional_params, void** optional_reply);
JAVA API
// Synchronous
int exec(String thingKey, String method, Boolean singleton, Integer ackTimeout, LinkedHashMap<String, Object> params, Object response);
 
// Asynchronous
int exec(String thingKey, String method, Boolean singleton, Integer ackTimeout, LinkedHashMap<String, Object> 
params, DwOpenReceiveActionListener recv, Object response);

Response Objects:  StringReplyDwOpenResponse, DwOpenMethodExec

PHP API
bool TR50httpWorker::methodExec($thingKey, $method[, $ackTimeout[, $parameters]]);