Ensure readPressure function is executed only if begin returns 1 #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With some example sketches like https://opla.arduino.cc/opla/module/iot-starter-kit-maker/lesson/02-personal-weather-station the program execution goes on even if carrier.begin() returns an error. If the pressure sensor (or any other sensor of the board) fails to initialize the following reading calls get stuck here
Arduino_LPS22HB/src/BARO.cpp
Line 61 in 1f0a793
because the sensor is not responding. On the MKR_WIFI_1010 this will lead to a watchdog infinite reset loop (watchdog is enabled by the IOT library).
Even if the board resets itself the sensor is never initialized correctly, the only thing i found working is to completely power off the board unplugging the usb connector, therefore, in this specific case, the watchdog resets are completely usless.
What i propose is to store the initialization return value and check it into the readPressure funcion avoiding any action if something went wrong during initialization phase and let the user decide when to reset/unplug the board.
If the changes are good i think we could extend them also to:
and maybe some other library...