@@ -66,7 +66,7 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
6666 if (is_initialized) {
6767 WS_DEBUG_PRINTLN (" Sensor found on OneWire bus and initialized" );
6868
69- // Set the sensor's pin name (non-logical)
69+ // Set the sensor's pin name (non-logical name )
7070 new_dsx_driver->setOneWirePinName (
7171 _DS18X20_model->GetDS18x20AddMsg ()->onewire_pin );
7272
@@ -88,16 +88,18 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
8888 wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT) {
8989 new_dsx_driver->is_read_temp_f = true ;
9090 } 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 ;
9394 }
9495 }
9596
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));
98100 } 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 ;
101103 }
102104
103105 // Encode and publish a Ds18x20Added message back to the broker
@@ -110,7 +112,8 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
110112
111113 if (!WsV2.PublishSignal (wippersnapper_signal_DeviceToBroker_ds18x20_added_tag,
112114 _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!" );
114117 return false ;
115118 }
116119
@@ -185,7 +188,8 @@ void DS18X20Controller::update() {
185188#endif
186189
187190 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" );
189193 continue ;
190194 }
191195
@@ -219,28 +223,27 @@ void DS18X20Controller::update() {
219223 pb_size_t event_count = event_msg->sensor_events_count ;
220224
221225 // Print the message's content out for debugging
222- WS_DEBUG_PRINT (" Sensor OneWire bus pin: " );
226+ WS_DEBUG_PRINT (" DS18x20: OneWire pin: " );
223227 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): " );
227229 for (int i = 0 ; i < event_count; i++) {
228- WS_DEBUG_PRINT (" Sensor value: " );
229230 WS_DEBUG_PRINT (event_msg->sensor_events [i].value .float_value );
230231 }
231232
232233 // Encode the Ds18x20Event message
233234 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" );
235237 continue ;
236238 }
237239
238240 // 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..." );
240242 if (!WsV2.PublishSignal (
241243 wippersnapper_signal_DeviceToBroker_ds18x20_event_tag,
242244 _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" );
244247 continue ;
245248 }
246249 WS_DEBUG_PRINTLN (" Published!" );
0 commit comments