@@ -44,7 +44,8 @@ Property::Property()
44
44
_last_cloud_change_timestamp(0 ),
45
45
_identifier(0 ),
46
46
_attributeIdentifier(0 ),
47
- _lightPayload(false ) {
47
+ _lightPayload(false ),
48
+ _update_requested(false ) {
48
49
}
49
50
50
51
/* *****************************************************************************
@@ -79,6 +80,11 @@ Property & Property::publishEvery(unsigned long const seconds) {
79
80
return (*this );
80
81
}
81
82
83
+ Property & Property::publishOnDemand () {
84
+ _update_policy = UpdatePolicy::OnDemand;
85
+ return (*this );
86
+ }
87
+
82
88
bool Property::shouldBeUpdated () {
83
89
if (!_has_been_updated_once) {
84
90
return true ;
@@ -93,11 +99,18 @@ bool Property::shouldBeUpdated() {
93
99
return (isDifferentFromCloud () && ((millis () - _last_updated_millis) >= (_min_time_between_updates_millis)));
94
100
} else if (_update_policy == UpdatePolicy::TimeInterval) {
95
101
return ((millis () - _last_updated_millis) >= _update_interval_millis);
102
+ } else if (_update_policy == UpdatePolicy::OnDemand) {
103
+ return _update_requested;
96
104
} else {
97
105
return false ;
98
106
}
99
107
}
100
108
109
+ void Property::requestUpdate ()
110
+ {
111
+ _update_requested = true ;
112
+ }
113
+
101
114
void Property::execCallbackOnChange () {
102
115
if (_update_callback_func != NULL ) {
103
116
_update_callback_func ();
@@ -119,6 +132,7 @@ void Property::append(CborEncoder *encoder, bool lightPayload) {
119
132
appendAttributesToCloudReal (encoder);
120
133
fromLocalToCloud ();
121
134
_has_been_updated_once = true ;
135
+ _update_requested = false ;
122
136
_last_updated_millis = millis ();
123
137
}
124
138
0 commit comments