#!/bin/bash

output_file="sensors_log.csv"

if [ ! -f "$output_file" ]; then
    echo "timestamp,CPU (°C),Vcore (V),VSOC (V),VDDP (mV),DRAM (V)" > "$output_file"
fi

while true; do
    timestamp=$(date +"%Y-%m-%d %H:%M:%S")

    values=$(sensors it8686-isa-0a40 | grep -E 'CPU:|Vcore:|VSOC:|VDDP:|DRAM:')

    CPU_temp=$(echo "$values" | grep "CPU:" | grep -oE '[+-]?[0-9]+\.[0-9]+' | head -n 1)
    Vcore=$(echo "$values" | grep "Vcore:" | grep -oE '[+-]?[0-9]+\.[0-9]+' | head -n 1)
    VSOC=$(echo "$values" | grep "VSOC:" | grep -oE '[+-]?[0-9]+\.[0-9]+' | head -n 1)
    VDDP=$(echo "$values" | grep "VDDP:" | grep -oE '[+-]?[0-9]+' | head -n 1)
    DRAM=$(echo "$values" | grep "DRAM:" | grep -oE '[+-]?[0-9]+\.[0-9]+' | head -n 1)

    echo "$timestamp,$CPU_temp,$Vcore,$VSOC,$VDDP,$DRAM" >> "$output_file"

    sleep 1
done

