Here you go: https://github.com/sweenig/lmcommunity/blob/master/PiJuice/collect.groovy
In this script, I compose the python script within my groovy script. Then the groovy script connects to the server via SSH, runs the script on the command line, grabs the output, then extracts the data from the returned json.
//SETUP PORTION OMITTED (it's in the linked github repo)
pythonScript = """import json
from pijuice import PiJuice
x=PiJuice(1,0x14)
output = {}
output["charge"] = x.status.GetChargeLevel()
output["status"] = x.status.GetStatus()
output["temp"] = x.status.GetBatteryTemperature()
output["voltage"] = x.status.GetBatteryVoltage()
output["current"] = x.status.GetBatteryCurrent()
output["iovoltage"] = x.status.GetIoVoltage()
output["iocurrent"] = x.status.GetIoCurrent()
print(json.dumps(output))
"""
power_input_status = ["NOT_PRESENT": 0, "BAD": 1, "WEAK": 2, "PRESENT": 3]
battery_status = ["NORMAL": 0, "CHARGING_FROM_IN": 1, "CHARGING_FROM_5V_IO": 2, "NOT_PRESENT": 3]
try {
def userCmd = getCommandOutput("python3 -c \"${pythonScript.replaceAll("\"","'").replaceAll("\n",";")}\"")
data = new JsonSlurper().parseText(userCmd)
println("5v_power_input_status: ${power_input_status[data.status.data.powerInput5vIo]}")
println("charge: ${data.charge.data}")
println("battery_status: ${battery_status[data.status.data.battery]}")
println("power_input_status: ${power_input_status[data.status.data.powerInput]}")
return 0
}
catch (Exception e) {println "Unexpected Exception : " + e; return 1}
//FUNCTIONS OMITTED (it's in the linked github repo)