@@ -45,17 +45,19 @@ function pickEndpoint( endpoints ) {
45
45
function secondPositiveListener ( resource ) {
46
46
secondPositiveCount ++ ;
47
47
console . log ( JSON . stringify ( { assertion : "ok" , arguments : [
48
- resource . properties . value > 0 , "Client: Second listener: sensor value is positive"
48
+ resource . properties . value > 0 ,
49
+ "Client: Second listener: sensor value is positive at observation " + secondPositiveCount
49
50
] } ) ) ;
50
- if ( secondNegativeCount >= 4 ) {
51
+ if ( secondPositiveCount >= 4 ) {
51
52
resource . removeListener ( "update" , secondPositiveListener ) ;
52
53
}
53
54
}
54
55
55
56
function positiveListener ( resource ) {
56
57
positiveCount ++ ;
57
58
console . log ( JSON . stringify ( { assertion : "ok" , arguments : [
58
- resource . properties . value > 0 , "Client: sensor value is positive"
59
+ resource . properties . value > 0 ,
60
+ "Client: sensor value is positive at observation " + positiveCount
59
61
] } ) ) ;
60
62
61
63
// After three notifications, hand over to the second listener, with two notifications where
@@ -86,7 +88,8 @@ function positiveListener( resource ) {
86
88
function secondNegativeListener ( resource ) {
87
89
secondNegativeCount ++ ;
88
90
console . log ( JSON . stringify ( { assertion : "ok" , arguments : [
89
- resource . properties . value < 0 , "Client: Second listener: sensor value is negative"
91
+ resource . properties . value < 0 ,
92
+ "Client: Second listener: sensor value is negative at observation " + secondNegativeCount
90
93
] } ) ) ;
91
94
if ( secondNegativeCount >= 5 ) {
92
95
resource . removeListener ( "update" , secondNegativeListener ) ;
@@ -96,13 +99,15 @@ function secondNegativeListener( resource ) {
96
99
function negativeListener ( resource ) {
97
100
negativeCount ++ ;
98
101
console . log ( JSON . stringify ( { assertion : "ok" , arguments : [
99
- resource . properties . value < 0 , "Client: sensor value is negative"
102
+ resource . properties . value < 0 ,
103
+ "Client: sensor value is negative at observation " + negativeCount
100
104
] } ) ) ;
101
105
102
106
// After two notifications, hand over to the second listener, with three notifications where
103
107
// both listeners are attached
104
108
if ( negativeCount > 1 && addSecondNegativeListener ) {
105
109
addSecondNegativeListener = false ;
110
+ resource . endpoint = pickEndpoint ( resource . endpoints ) ;
106
111
client . retrieve ( resource , { scale : - 1 } , secondNegativeListener )
107
112
. then (
108
113
function ( secondResource ) {
@@ -123,6 +128,7 @@ function negativeListener( resource ) {
123
128
}
124
129
125
130
function performObservation ( resource ) {
131
+ resource . endpoint = pickEndpoint ( resource . endpoints ) ;
126
132
resource . on ( "update" , positiveListener ) ;
127
133
128
134
client
0 commit comments