@@ -66,7 +66,7 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
66
66
if (is_initialized) {
67
67
WS_DEBUG_PRINTLN (" Sensor found on OneWire bus and initialized" );
68
68
69
- // Set the sensor's pin name (non-logical)
69
+ // Set the sensor's pin name (non-logical name )
70
70
new_dsx_driver->setOneWirePinName (
71
71
_DS18X20_model->GetDS18x20AddMsg ()->onewire_pin );
72
72
@@ -88,16 +88,18 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
88
88
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT) {
89
89
new_dsx_driver->is_read_temp_f = true ;
90
90
} else {
91
- WS_DEBUG_PRINTLN (" ERROR | DS18x20: Unknown SensorType, failed to add sensor!" );
92
- return false ;
91
+ WS_DEBUG_PRINTLN (
92
+ " ERROR | DS18x20: Unknown SensorType, failed to add sensor!" );
93
+ is_initialized = false ;
93
94
}
94
95
}
95
96
96
- // Add the DS18X20Hardware object to the vector of hardware objects
97
- _DS18X20_pins.push_back (std::move (new_dsx_driver));
97
+ // If the sensor was successfully initialized, add it to the controller
98
+ if (is_initialized == true )
99
+ _DS18X20_pins.push_back (std::move (new_dsx_driver));
98
100
} else {
99
- WS_DEBUG_PRINTLN (
100
- " ERROR | DS18x20: Unable to get sensor ID! " ) ;
101
+ WS_DEBUG_PRINTLN (" ERROR | DS18x20: Unable to get sensor ID! " );
102
+ is_initialized = false ;
101
103
}
102
104
103
105
// Encode and publish a Ds18x20Added message back to the broker
@@ -110,7 +112,8 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
110
112
111
113
if (!WsV2.PublishSignal (wippersnapper_signal_DeviceToBroker_ds18x20_added_tag,
112
114
_DS18X20_model->GetDS18x20AddedMsg ())) {
113
- WS_DEBUG_PRINTLN (" ERROR | DS18x20: Unable to publish Ds18x20Added message!" );
115
+ WS_DEBUG_PRINTLN (
116
+ " ERROR | DS18x20: Unable to publish Ds18x20Added message!" );
114
117
return false ;
115
118
}
116
119
@@ -185,7 +188,8 @@ void DS18X20Controller::update() {
185
188
#endif
186
189
187
190
if (!temp_dsx_driver.ReadTemperatureC ()) {
188
- WS_DEBUG_PRINTLN (" ERROR | DS18x20: Unable to read temperature in Celsius" );
191
+ WS_DEBUG_PRINTLN (
192
+ " ERROR | DS18x20: Unable to read temperature in Celsius" );
189
193
continue ;
190
194
}
191
195
@@ -219,28 +223,27 @@ void DS18X20Controller::update() {
219
223
pb_size_t event_count = event_msg->sensor_events_count ;
220
224
221
225
// Print the message's content out for debugging
222
- WS_DEBUG_PRINT (" Sensor OneWire bus pin: " );
226
+ WS_DEBUG_PRINT (" DS18x20: OneWire pin: " );
223
227
WS_DEBUG_PRINT (temp_dsx_driver.GetOneWirePin ());
224
- WS_DEBUG_PRINT (" got " );
225
- WS_DEBUG_PRINT (event_count);
226
- WS_DEBUG_PRINTLN (" sensor events" );
228
+ WS_DEBUG_PRINT (" got value(s): " );
227
229
for (int i = 0 ; i < event_count; i++) {
228
- WS_DEBUG_PRINT (" Sensor value: " );
229
230
WS_DEBUG_PRINT (event_msg->sensor_events [i].value .float_value );
230
231
}
231
232
232
233
// Encode the Ds18x20Event message
233
234
if (!_DS18X20_model->EncodeDs18x20Event ()) {
234
- WS_DEBUG_PRINTLN (" ERROR | DS18x20: Failed to encode Ds18x20Event message" );
235
+ WS_DEBUG_PRINTLN (
236
+ " ERROR | DS18x20: Failed to encode Ds18x20Event message" );
235
237
continue ;
236
238
}
237
239
238
240
// Publish the Ds18x20Event message to the broker
239
- WS_DEBUG_PRINT (" Publishing Ds18x20Event message to broker..." );
241
+ WS_DEBUG_PRINT (" DS18x20: Publishing event to broker..." );
240
242
if (!WsV2.PublishSignal (
241
243
wippersnapper_signal_DeviceToBroker_ds18x20_event_tag,
242
244
_DS18X20_model->GetDS18x20EventMsg ())) {
243
- WS_DEBUG_PRINTLN (" ERROR | DS18x20: Failed to publish Ds18x20Event message" );
245
+ WS_DEBUG_PRINTLN (
246
+ " ERROR | DS18x20: Failed to publish Ds18x20Event message" );
244
247
continue ;
245
248
}
246
249
WS_DEBUG_PRINTLN (" Published!" );
0 commit comments