Apama 10.1 | Apama Documentation | Connecting Apama Applications to External Components | Standard Connectivity Plug-ins | The Cumulocity IoT Transport Connectivity Plug-in | Using Cumulocity IoT connectivity from EPL | Sending control events to Cumulocity IoT
 
Sending control events to Cumulocity IoT
The Cumulocity IoT connectivity plug-in listens on the CumulocityIoT channel for most requests. For all events sent to the transport, a CHANNEL constant is defined on the event type with the correct channel to send the event to.
Refreshing the list of devices
See the com.apama.cumulocity.RequestAllDevices event for refreshing the list of devices. Note that the com.apama.cumulocity.RequestAllDevices event is sent to the channel defined by the CHANNEL constant on the RequestAllDevices event. The device events are sent to the channel specified in the RequestAllDevices event and followed by a com.apama.cumulocity.RequestAllDevicesComplete event with the requestId sent in the RequestAllDevices event.
Subscribing to measurements
The com.apama.cumulocity.SubscribeMeasurements and com.apama.cumulocity.UnsubscribeMeasurements events control subscriptions to measurements from assets. Specify the asset identifier as either an asset identifier from a device event or as "*" for a wildcard (use the WILDCARD constant). Subscriptions are reference counted by the transport, so send as many unsubscribe events as subscribe events have been sent to completely unsubscribe. Unless the subscribeToMeasurements configuration property is false, the transport automatically subscribes as if SubscribeMeasurements("*") had been sent at applicationInitialized time. Subscriptions to measurements also subscribe to events and alarms.
Sending device operations
Send a com.apama.cumulocity.Operation event to send an operation to a device. For example, to set a device's display and modify a set of relays, send:
com.apama.cumulocity.Operation("12345",{"c8y_Meassage":<any>
{<any>"text":<any>"Hello Cumulocity device"}},
new dictionary<string, any>)

com.apama.cumulocity.Operation("12345",{"c8y_RelayArray":<any>
["CLOSED","OPEN","CLOSED","OPEN"]},
new dictionary<string, any>)

com.apama.cumulocity.Operation("12345",{"c8y_Meassage":<any>
{<any>"text":<any>"Hello cumulocity"},
"c8y_Relay":<any>{<any>"relayState":<any>"CLOSED"}},
new dictionary<string, any>)
Sending events, alarms and measurements
The Cumulocity IoT connectivity plug-in also provides a mechanism to create a new alarm, update an existing alarm, publish a new measurement and send an event to Cumulocity IoT.
*For sending an event:
send Event("","c8y_SampleEvent","<SOURCE>", <TIME>,
"Event text",{}) to Event.CHANNEL;
Where
*<SOURCE> is the source of the alarm (same as the ManagedObject identifier).
*<TIME> is the time at which the alarm was generated.
*For creating a new alarm:
send Alarm("","c8y_SampleAlarm","<SOURCE>",<TIME>,
"Alarm text", "<STATUS>","<SEVERITY>",1,{}) to Alarm.CHANNEL;
Where
*<SOURCE> is the source of the alarm (same as the ManagedObject identifier).
*<TIME> is the time at which the alarm was generated.
*<STATUS> is the status of the alarm. This can be ACTIVE, ACKNOWLEDGED or CLEARED.
*<SEVERITY> is the severity of the alarm. This can be CRITICAL, MAJOR, MINOR or WARNING.
*For updating an existing alarm:
send Alarm("<ALARM_ID>","c8y_SampleAlarm","<SOURCE>",<TIME>,
"Alarm Updated", "<STATUS>","<SEVERITY>",1,{}) to Alarm.CHANNEL;
Where
*<ALARM_ID> is the identifier of the previously created alarm. The presence of <ALARM_ID> indicates that the request is for updating an existing alarm.
*For sending a measurement:
Measurement m := new Measurement;
m.type := <MEASUREMENT_TYPE>;
m.source := <SOURCE>;
m.time := currentTime;
MeasurementValue mv := new MeasurementValue;
mv.value := 1.0;
mv.unit := "V";
dictionary<string, MeasurementValue> dict := {"voltage": mv};
m.measurements.add(m.type, dict);
send m to Measurement.CREATE_CHANNEL;
Where
*<SOURCE> is the source of the alarm (same as the ManagedObject identifier).
*<MEASUREMENT_TYPE> is the type of the measurement. For example, c8y_VoltageMeasurement.

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.