However, in our application, we're trying to log a bunch of different sensor data, including the JSN-SR04, to a microSD card, and we're receiving a result of 0.00 about 95% of the time when we request result.cm() (deriving from distanceCallback(JSN_SR04_Gen3::DistanceResult result)) in our datalogging script.
I imagine the problem stems from my poor understanding of how to access a result of the callback function. We are running distance.loop() within void loop() and passing the callback function's result.cm() to a global that we call in the datalogging portion of the script.
I should note that we're running it on a Boron, we've added an external boost converter to give the sensor its desired 5 V, and we're level shifting the response down to 3.3 V back into the Boron. It's certainly possible that there's a hardware/wiring issue, though the example script from the provided repo worked fine, so I suspect it's a firmware issue. I wouldn't expect anyone to read through our firmware to troubleshoot for us to that extent, but the full .ino file is here.
Is anyone able to offer advice regarding how to access the callback function's result.cm() outside of that callback function such that we can log it and/or do some simple math with the result?
The distanceCallback should be void, not return a float
Add the SerialLogHandler logHandler back in and see if you're getting the distance log messages from the callback, or are getting an error.
You shouldn't mix Log.info and Serial.print, you should switch everything to use Log.info, Log.trace, etc.
If your sensor is returning 0 in some cases, you may want to only save the result to depth_cm when it's non-zero, so at least you'll have the last good distance saved.
Thanks, @rickkas7, much appreciated. I added the logHandler back in. Not sure how we lost that, but it's back. I also changed the distanceCallback back to void. The change to returning a float was an experiment in how to access the result when needed.
Those updates seem to be an improvement, but still getting lots of zeros (responses below, including other output).
I still need to switch all Serial.print statements to Log.info. Next step will be to save only nonzero responses.