I have a pretty niche question. The question is how do you grab the CPU temperature programmatically from the raspberry pi 4 that is running the LineageOS 20 build of Android 13 and assign it to a var? Below I have included the code that I have been using and not succeeding with:
fun cpuTemperature(): Float {
val process: Process
return try {
process = Runtime.getRuntime().exec("cat sys/class/thermal/thermal_zone0/temp")
process.waitFor()
val reader = BufferedReader(InputStreamReader(process.inputStream))
val line: String = reader.readLine()
if (line != null) {
val temp = line.toFloat()
temp / 1000.0f
} else {
51.0f
}
} catch (e: Exception) {
e.printStackTrace()
0.0f
}
}
I understand this a bit of a weird question and most people probably wont have experience doing something like this so I appreciate any help or insight into how garbing CPU temp on android apps works.