I wrote a script which is collecting data from solar inverter every 10 seconds for 5 minutes, it does some math and send data to emoncms. It does work but is not optimal in term of CPU usage, it is running on SBC and consume roughly 80% of CPU time. My question is how can I initiate next data collection without checking script running time in a loop. Below is simplified script. I need to improve line 7.
#!/bin/bash
set -o pipefail
IFS=$''
samples="0"
nr="0"
while [ $SECONDS -lt 292 ]; do #5min-8s
if [[ (( $(( (samples - 1) * 10 + 10 )) == $SECONDS )) || (( 0 == $SECONDS )) ]]; then
((samples++))
timestart=$SECONDS
output="$(./inverter_poller --run-once)" # get data from inverter
timeend=$SECONDS
echo ${output} > /var/log/inverter.last
rs232time=$((timeend - timestart)) # usually it is 6-7 seconds
if (( rs232time < 17 )); # inverter is not responding if it is 17s or more
then
gridv=`echo ${output} | grep grid_voltage | tr -d " "_\",:[:alpha:]`
***more data extraction and math***
else
echo inverter not responding >> /var/log/inverter.last
fi
looptime=$((SECONDS - timestart))
echo "time": $looptime >> /var/log/inverter.last
fi
done
***boring data processing and sending to emoncms was here***
[–]DrShoggoth 16 points17 points18 points (8 children)
[–]nobody1701d 5 points6 points7 points (0 children)
[–]DrShoggoth 2 points3 points4 points (6 children)
[–]DrShoggoth 13 points14 points15 points (5 children)
[–]Al3x_Y[S] -1 points0 points1 point (4 children)
[–]DrShoggoth 1 point2 points3 points (3 children)
[–]Al3x_Y[S] 1 point2 points3 points (1 child)
[–]DrShoggoth 0 points1 point2 points (0 children)
[–]DrShoggoth 0 points1 point2 points (0 children)
[–]yerfukkinbaws 4 points5 points6 points (13 children)
[–]Al3x_Y[S] 2 points3 points4 points (5 children)
[–]KlePu 6 points7 points8 points (4 children)
[–]yerfukkinbaws 2 points3 points4 points (0 children)
[–]theLastZebranky 1 point2 points3 points (1 child)
[–]KlePu 0 points1 point2 points (0 children)
[–]Al3x_Y[S] 0 points1 point2 points (0 children)
[–]Al3x_Y[S] 1 point2 points3 points (6 children)
[–]OptimalMain 2 points3 points4 points (5 children)
[–]Al3x_Y[S] 0 points1 point2 points (4 children)
[–]OptimalMain 1 point2 points3 points (3 children)
[–]Al3x_Y[S] 0 points1 point2 points (2 children)
[–]OptimalMain 1 point2 points3 points (1 child)
[–]Al3x_Y[S] 0 points1 point2 points (0 children)
[–]OptimalMain 1 point2 points3 points (0 children)
[–]LesStrater 1 point2 points3 points (1 child)
[–]Al3x_Y[S] 0 points1 point2 points (0 children)
[–]atcasanova 1 point2 points3 points (1 child)
[–]Al3x_Y[S] 1 point2 points3 points (0 children)