SPL File command.spl
SPL standard and specialized toolkits > com.ibm.streamsx.iot 1.1.0.commit_67acf7a > com.ibm.streamsx.iot > command.spl
Content
- Operators
- CommandTupleToPayload: Convert tuples to device commands.
Composites
composite CommandTupleToPayload(output stream<DeviceCmd> DeviceCommands; input Commands)
- Attributes defining the device to receive a command matching DeviceCmdId.
- A nested tuple with attribute name specified by the payload parameter.
The contents of the nested tuple are converted to JSON and used as the payload of the device command.
An example of how to invoke this operator. First have an SPL type that forms the content of the command's payload. The values in the type will be converted to JSON and used as the command's payload.
type StatusMsg = rstring message, rstring severity;
The input schema to this operator requires DeviceCmdId and the payload type as a nested tuple, for example:
stream<DeviceCmdId, tuple<StatusMsg msgs>> StatusMsgCommands = ...
Stream StatusMsgCommands is fed into this operator and then CommandPublish or SendCommandToDevice. The invocation of this operator specifies which nested tuple attribute maps to the command payload using the payload parameter. In this case setting payload to msgs.
// Convert them into the required schema
stream<DeviceCmd> StatusMsgCommandsJson = CommandTupleToPayload(StatusMsgCommands)
{
param
payload: msgs;
}
// And then publish them
() as PublishStatusMsgCmds = CommandPublish(StatusMsgCommandsJson) {}
This will result in a device command payload of:
{"message": "Warning Black Ice Ahead", "severity": "HIGH"}
Parameters
- payload: Attribute of nested tuple that will be the command payload.
Input Ports
- Commands: Input stream of commands, must be a super-set of DeviceCmdId.
Output Ports
- DeviceCommands: Device commands that can be submitted to CommandPublish or SendCommandToDevice. Must be of type DeviceCmd.