venari / timelapse

A set of tools/scripts to automate the taking and creation of timelapse videos and videos with a Raspberry Pi
MIT License
1 stars 0 forks source link

Create script to log power and temperature every ten minutes #1

Closed leighghunt closed 2 years ago

leighghunt commented 2 years ago

Log battery power remaining, and temperature to a CSV log file.

Possibly helpful links:

ethandhunt commented 2 years ago

Runs on restart with cron tab Appends to log.csv in same dir as file in format: yyyy-mm-dd hh:mm:ss, battery%, temperatureInCelsius

print('Logging...')

from pijuice import PiJuice
import time
import os

pj = PiJuice(1, 0x14) #?

log = f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}, {pj.status.GetChargeLevel()["data"]}, {pj.status.GetBatteryTemperature()["data"]}\n' 

outFile = os.path.dirname(os.path.realpath(__file__)) + '/log.csv'

with open(outFile, 'a') as f:
    f.write(log)

print('Logging complete')