How to create and send commands

Commands

Access to commands is carried out through the context menu of the object. The command is transmitted to the device either if it is online, or in response to an incoming message. The command is in the queue until the device communicates. Currently, the system does not allow sending a chain of commands to the device. In order to send a new command, it is necessary that the commands queue is empty. Some types of devices have predefined command sets. These commands, unlike those created by users, cannot be edited or deleted. To change the set of user commands in the "Command" panel, click on the "Create / Edit" button. Only the device owner can create, delete, and modify commands. The created commands can be applied to all devices of the same type within the user account.

When creating a command, you must specify its name and body. Commands of two types are provided: simple and command with parameters. In simple commands, the content specified in the body of the command is sent to the device as is. Commands with parameters should be issued in the form of a JSON block. If the body of the command begins with the symbol "{" and ends with the symbol "}", the system treats this command as a command with parameters. Mandatory attributes of the root JSON are:

  • body - template of the body of the command, which before sending is filled with the values ​​of the command parameters.
  • params - an array that defines the parameters of the command.

An optional attribute in the root JSON is the help attribute. It allows you to display additional information text in the "parameters filling" window.

Each element of the parameter array must contain the required attributes:

  • id - defines the identifier of the parameter. A substring with such id must be present in the command body template. Example: if “id”=“prm1”, then the substring %prm1 should be present in the template.
  • type - valid values: "text", "number”, "select". This attribute defines the rules for processing the parameter. When specifying "select", the element must also contain the "options" attribute. The options element defines the composition of the selection list. Format: “val1:text1; ... valN:textN”. When substituting into the template, valX will be selected for the corresponding selected option.
  • name - sets the name of the parameter displayed in the parameter filling panel.

Elements of the parameter array may contain optional attributes:

  • help - text (placeholder) that appears in the field if it is not filled.
  • def - the value that is substituted into the field when the panel is opened (applies only to the types of "text" and "number").
  • range - a rule that is checked before filling out the template. The format is “range”:”min:max”. For a "text" type, this means that the string must contain at least "min" characters and at most "max" characters. For type "number", this means that the value entered must be a number in the range from "min" to "max"

Example:

{"body":"display %p1 color=%p3, int:%p2",
"help":"This is complex command",
"params":[
{ "id":"p1", "type":"text", "name":"Message","help":"min 1 max 10 symbols","range":"1:10"},
{ "id":"p2", "type":"number", "def":"3","name":"Interval","range":"2:5","help":"number from 2 to 5"},
{ "id":"p3", "type":"select", "name":"Color","options":"R:Red;G:Green;B:Blue"}
]}

Some types of devices require sending IMEI or password in the command. In this case, the substrings %IMEI and/or %PSW must be included in the template. Parameters for them do not need to be defined. These values ​​will be automatically filled by the system when sending commands to the device.

On the Vialam service YouTube channel, a short video presentation is available.