If the communication works sporadically, it’s more likely to be an electrical issue than a code issue. Coding issues *usually* cause it to not work at all.
The -9999 is the library’s value for a failed reading. When you get in in SDI-12, it most often means the sensor didn’t respond or the response was garbled. Because the Mayfly’s voltage (and thus serial communication) range is only 3.3V, it doesn’t take much electrical noise to garble things up.