@@ -24,9 +24,78 @@ AWS IoT Events can trigger actions when it detects a specified event or transiti
2424
2525Currently supported are:
2626
27+ - Use timer
2728- Set variable to detector instanse
2829- Invoke a Lambda function
2930
31+ ## Use timer
32+
33+ The code snippet below creates an Action that creates the timer with duration in seconds.
34+
35+ ``` ts
36+ import * as iotevents from ' @aws-cdk/aws-iotevents' ;
37+ import * as actions from ' @aws-cdk/aws-iotevents-actions' ;
38+
39+ declare const input: iotevents .IInput ;
40+
41+ const state = new iotevents .State ({
42+ stateName: ' MyState' ,
43+ onEnter: [{
44+ eventName: ' test-event' ,
45+ condition: iotevents .Expression .currentInput (input ),
46+ actions: [
47+ new actions .SetTimerAction (' MyTimer' , {
48+ duration: cdk .Duration .seconds (60 ),
49+ }),
50+ ],
51+ }],
52+ });
53+ ```
54+
55+ Setting duration by [ IoT Events Expression] ( https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-expressions.html ) :
56+
57+ ``` ts
58+ new actions .SetTimerAction (' MyTimer' , {
59+ durationExpression: iotevents .Expression .inputAttribute (input , ' payload.durationSeconds' ),
60+ })
61+ ```
62+
63+ And the timer can be reset and cleared. Below is an example of general
64+ [ Device HeartBeat] ( https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-examples-dhb.html )
65+ Detector Model:
66+
67+ ``` ts
68+ const online = new iotevents .State ({
69+ stateName: ' Online' ,
70+ onEnter: [{
71+ eventName: ' enter-event' ,
72+ condition: iotevents .Expression .currentInput (input ),
73+ actions: [
74+ new actions .SetTimerAction (' MyTimer' , {
75+ duration: cdk .Duration .seconds (60 ),
76+ }),
77+ ],
78+ }],
79+ onInput: [{
80+ eventName: ' input-event' ,
81+ condition: iotevents .Expression .currentInput (input ),
82+ actions: [
83+ new actions .ResetTimerAction (' MyTimer' ),
84+ ],
85+ }],
86+ onExit: [{
87+ eventName: ' exit-event' ,
88+ actions: [
89+ new actions .ClearTimerAction (' MyTimer' ),
90+ ],
91+ }],
92+ });
93+ const offline = new iotevents .State ({ stateName: ' Offline' });
94+
95+ online .transitionTo (offline , { when: iotevents .Expression .timeout (' MyTimer' ) });
96+ offline .transitionTo (online , { when: iotevents .Expression .currentInput (input ) });
97+ ```
98+
3099## Set variable to detector instanse
31100
32101The code snippet below creates an Action that set variable to detector instanse
@@ -44,12 +113,10 @@ const state = new iotevents.State({
44113 eventName: ' test-event' ,
45114 condition: iotevents .Expression .currentInput (input ),
46115 actions: [
47- actions : [
48- new actions .SetVariableAction (
49- ' MyVariable' ,
50- iotevents .Expression .inputAttribute (input , ' payload.temperature' ),
51- ),
52- ],
116+ new actions .SetVariableAction (
117+ ' MyVariable' ,
118+ iotevents .Expression .inputAttribute (input , ' payload.temperature' ),
119+ ),
53120 ],
54121 }],
55122});
0 commit comments