命令
The command object represents a command to be sent to a device or endpoint. This object is normally received as a parameter in the buildDownlink method as part of a LoRaWAN or MQTT data conversion script.
属性
commandId (int) The commandId property indicates an internal number that uniquely identifies the command. If the device is capable of responding to the command, the response must contain the same commandId.
示例
The following is an example based on the buildDownlink method documentation in the LoRaWAN or MQTT data conversion section.
function buildDownlink(device, endpoint, command, payload)
{
payload.port = 25; // This device receives commands on LoRaWAN port 25
payload.buildResult = downlinkBuildResult.ok;
switch (command.type) {
case commandType.onOff:
switch (command.onOff.type) {
case onOffCommandType.turnOn:
payload.setAsBytes([30]); // Command ID 30 is "turn on"
break;
case onOffCommandType.turnOff:
payload.setAsBytes([31]); // Command ID 31 is "turn off"
break;
case onOffCommandType.toggle:
payload.setAsBytes([32]); // Command ID 32 is "toggle"
break;
default:
payload.buildResult = downlinkBuildResult.unsupported;
break;
}
break;
default:
payload.buildResult = downlinkBuildResult.unsupported;
break;
}
}type (int, enum)
The type property indicates the command type. The possible values are as follows:
- commandType.onOff (1): indicates that the command is of on/off type, meaning it is for turning on, turning off, or toggling an endpoint.
- commandType.dimmer (2): indicates that the command is for altering the level of a dimmer.
- commandType.closure (3): indicates that the command is for controlling a closure, such as a curtain or blind.
- commandType.thermostat (4): indicates that the command is for controlling a thermostat.
- commandType.management (5): indicates that the command is for managing the device (reboot, firmware upgrade, etc.).
- commandType.custom (6): indicates that it is a user-defined command.
示例
本节开头提供了完整的示例。
onOff (object)
The onOff property is an object containing the command parameters when it is of type commandType.onOff. The object has the following properties:
- type (int enum): indicates the on/off command type, among the following:
- onOff命令Type.turnOn (0): indicates that the command is to turn on the endpoint.
- onOff命令Type.turnOff (1): indicates that the command is to turn off the endpoint.
- onOff命令Type.toggle (2): indicates that the command is to toggle the endpoint.
示例
本节开头提供了完整的示例。
dimmer (object)
The dimmer property is an object containing the command parameters when it is of type commandType.dimmer. The object has the following properties:
- level (double): indicates the dimming level as a percentage, from zero to 100%.
示例
本节开头提供了完整的示例。
thermostat (object)
The thermostat property is an object containing the command parameters when it is of type commandType.thermostat. The object has the following properties:
- type (int enum): indicates the type of command sent to the thermostat, among the following:
- thermostat命令Type.setMode (0): the command is to change the thermostat mode.
- thermostat命令Type.setFanMode (1): the command is to change the thermostat fan mode.
- thermostat命令Type.setSetpoint (2): the command is to change the setpoint.
- thermostat命令Type.setAll (3): the command is to change all parameters simultaneously.
- mode (int enum): indicates the mode the thermostat should switch to, when the type is thermostat命令Type.setMode or thermostat命令Type.setAll. The possible values are as follows:
- thermostatMode.off (1): the thermostat should be turned off.
- thermostatMode.auto (2): the thermostat should switch to auto mode.
- thermostatMode.heat (3): the thermostat should switch to heat mode.
- thermostatMode.cool (4): the thermostat should switch to cool mode.
- thermostatMode.dry (5): the thermostat should switch to dehumidification (dry) mode.
- thermostatMode.fan (6): the thermostat should switch to fan mode.
- fanMode (int enum): indicates the fan mode the thermostat should switch to, when the type is thermostat命令Type.setFanMode or thermostat命令Type.setAll. The possible values are as follows:
- thermostatFanMode.auto (1): the fan should switch to auto mode.
- thermostatFanMode.low (2): the fan should switch to low mode.
- thermostatFanMode.mid (3): the fan should switch to mid mode.
- thermostatFamMode.high (4): the fan should switch to high mode.
- setpoint (double): indicates the setpoint in degrees Celsius, when the type is thermostat命令Type.setSetpoint or thermostat命令Type.setAll.
示例
本节开头提供了完整的示例。
closure (object)
The closure property is an object containing the command parameters when it is of type commandType.closure. The object has the following properties:
- type (int enum): indicates the type of command sent to the closure, among the following:
- closure命令Type.open (0): the command is for the closure to open.
- closure命令Type.close (1): the command is for the closure to close.
- closure命令Type.position (2): the command is to change the position of the closure.
- closure命令Type.stop (3): the command is to stop the closure movement.
- closure命令Type.openStop (4): the command is to open the closure, or stop it if it is moving.
- closure命令Type.closeStop (5): the command is to close the closure, or stop it if it is moving.
- position (int): indicates the position to which the closure should move, when the type is closure命令Type.position, as a percentage, between 0% (closed) and 100% (open).
示例
本节开头提供了完整的示例。
management (object)
The management property is an object containing the command parameters when it is of type commandType.management. The object has the following properties:
- type (int enum): indicates the type of command sent to the device, among the following:
- management命令Type.identify (0): requests the device to identify itself. This is used on some devices to have the device activate a visual or audible indicator.
- management命令Type.reboot (1): requests the device to restart.
- management命令Type.powerOff (2): requests the device to power off.
- management命令Type.poll (3): requests the device to send updated information as soon as possible.
- management命令Type.updateFirmware (4): requests the device to update its firmware.
- management命令Type.setValue (5): requests the device to change a value.
- updateFirmware (object): indicates the firmware update parameters, when the value of the type field is management命令Type.updateFirmware. The properties of this object are as follows:
- downloadUrl (string): indicates the URL from which the device should download the firmware update.
- setValue (object): the setValue object contains the necessary information to change the value, when the value of the type field is management命令Type.setValue. The properties of this object are as follows:
- newValue (double): indicates the new value to be assigned.
示例
本节开头提供了完整的示例。
custom (object)
The custom property is an object containing the command parameters when it is of type commandType.custom. The object has the following properties:
- type (int): arbitrary value indicating the custom command type.
- data (string): arbitrary value to be sent to the device.
示例
本节开头提供了完整的示例。
RSSI status
The RSSI status object represents the signal level of a wireless connection of a device. This object is normally used to update the signal level through the updateDeviceRssi method...
多语言文字
The multi-language literal object allows constructing messages in multiple languages, especially for error or informational messages. 属性 en (string)...