@@ -118,6 +118,7 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
118
118
*/
119
119
/* **********************************************************************/
120
120
bool DS18X20Controller::Handle_Ds18x20Remove (pb_istream_t *stream) {
121
+ WS_DEBUG_PRINT (" Removing DS18X20 sensor..." );
121
122
// Attempt to decode the stream
122
123
if (!_DS18X20_model->DecodeDS18x20Remove (stream)) {
123
124
WS_DEBUG_PRINTLN (" ERROR: Unable to decode Ds18x20Remove message" );
@@ -135,8 +136,7 @@ bool DS18X20Controller::Handle_Ds18x20Remove(pb_istream_t *stream) {
135
136
return true ;
136
137
}
137
138
}
138
- WS_DEBUG_PRINT (" Removed OneWire Pin: " );
139
- WS_DEBUG_PRINTLN (pin_name);
139
+ WS_DEBUG_PRINT (" Removed!" );
140
140
return true ;
141
141
}
142
142
@@ -186,25 +186,34 @@ void DS18X20Controller::update() {
186
186
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT,
187
187
temp_f);
188
188
}
189
- // Print out the SensorEvent message's contents for debugging
190
- // TODO: After debugging, maybe remove this
189
+ // Get and print out the SensorEvent message's contents
191
190
wippersnapper_ds18x20_Ds18x20Event event_msg =
192
191
*_DS18X20_model->GetDS18x20EventMsg ();
193
- WS_DEBUG_PRINTLN (" SensorEvent message:" );
194
- WS_DEBUG_PRINT (" Sensor OneWire bus pin: " );
195
- WS_DEBUG_PRINTLN (event_msg.onewire_pin );
196
- WS_DEBUG_PRINT (" Sensor events count: " );
197
- WS_DEBUG_PRINTLN (event_msg.sensor_events_count );
192
+ pb_size_t event_count = event_msg.sensor_events_count ;
198
193
199
- for (int i = 0 ;
200
- i < _DS18X20_model->GetDS18x20EventMsg ()->sensor_events_count ; i++) {
201
- WS_DEBUG_PRINT (" Sensor type: " );
202
- WS_DEBUG_PRINTLN (event_msg.sensor_events [i].type );
194
+ WS_DEBUG_PRINT (" Sensor OneWire bus pin: " );
195
+ WS_DEBUG_PRINT (temp_dsx_driver.GetOneWirePin ());
196
+ WS_DEBUG_PRINT (" got " );
197
+ WS_DEBUG_PRINT (event_count);
198
+ WS_DEBUG_PRINTLN (" sensor events" );
199
+ for (int i = 0 ; i < event_count; i++) {
203
200
WS_DEBUG_PRINT (" Sensor value: " );
204
201
WS_DEBUG_PRINTLN (event_msg.sensor_events [i].value .float_value );
205
- WS_DEBUG_PRINT (" Sensor value type: " );
206
- WS_DEBUG_PRINTLN (event_msg.sensor_events [i].which_value );
207
202
}
203
+
204
+ // Encode the Ds18x20Event message
205
+ if (!_DS18X20_model->EncodeDs18x20Event ()) {
206
+ WS_DEBUG_PRINTLN (" ERROR: Failed to encode Ds18x20Event message" );
207
+ continue ;
208
+ }
209
+ // Publish the Ds18x20Event message to the broker
210
+ WS_DEBUG_PRINT (" Publishing Ds18x20Event message to broker..." );
211
+ if (!WsV2.PublishSignal (
212
+ wippersnapper_signal_DeviceToBroker_ds18x20_event_tag,
213
+ _DS18X20_model->GetDS18x20EventMsg ())) {
214
+ WS_DEBUG_PRINTLN (" ERROR: Failed to publish Ds18x20Event message" );
215
+ continue ;
216
+ }
217
+ WS_DEBUG_PRINTLN (" Published!" );
208
218
}
209
- // TODO: Encode and publish the Ds18x20Event message to the broker
210
219
}
0 commit comments