From 16787115fed30661d82130b15b2bde772b257ff3 Mon Sep 17 00:00:00 2001 From: ilcato Date: Wed, 11 Dec 2019 11:00:20 +0100 Subject: [PATCH 1/2] fix_boolean_management Manage the case to have boolean values received as integers 0/1 in the CBOR message. --- src/ArduinoCloudProperty.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ArduinoCloudProperty.cpp b/src/ArduinoCloudProperty.cpp index 2b8031c..3a65b0f 100644 --- a/src/ArduinoCloudProperty.cpp +++ b/src/ArduinoCloudProperty.cpp @@ -170,7 +170,22 @@ void ArduinoCloudProperty::setAttributesFromCloud(LinkedList *map void ArduinoCloudProperty::setAttributeReal(bool& value, String attributeName) { setAttributeReal(attributeName, [&value](CborMapData * md) { - value = md->bool_val.get(); + // Manage the case to have boolean values received as integers 0/1 + if (md->bool_val.isSet()) { + Serial.println("1"); + value = md->bool_val.get(); + } else if (md->val.isSet()) { + if (md->val.get() == 0) { + Serial.println("2"); + value = false; + } else if (md->val.get() == 1) { + Serial.println("3"); + value = true; + } else { + Serial.println("4"); + /* This should not happen. Leave the previous value */ + } + } }); } From 31e9e68b5f81257bfc9cc82f54f134e6b0ce9a66 Mon Sep 17 00:00:00 2001 From: ilcato Date: Wed, 11 Dec 2019 12:43:20 +0100 Subject: [PATCH 2/2] Removed debug statements --- src/ArduinoCloudProperty.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/ArduinoCloudProperty.cpp b/src/ArduinoCloudProperty.cpp index 3a65b0f..64a3dd6 100644 --- a/src/ArduinoCloudProperty.cpp +++ b/src/ArduinoCloudProperty.cpp @@ -172,17 +172,13 @@ void ArduinoCloudProperty::setAttributeReal(bool& value, String attributeName) { setAttributeReal(attributeName, [&value](CborMapData * md) { // Manage the case to have boolean values received as integers 0/1 if (md->bool_val.isSet()) { - Serial.println("1"); value = md->bool_val.get(); } else if (md->val.isSet()) { if (md->val.get() == 0) { - Serial.println("2"); value = false; } else if (md->val.get() == 1) { - Serial.println("3"); value = true; } else { - Serial.println("4"); /* This should not happen. Leave the previous value */ } }