Calculate Wh from power logger data set
Your approach is correct. If you are sampling, for example, every 5 s then take each reading, multiply by it by 5 to give you the number of Ws (watt-seconds) add them all up and divide by 3600 (seconds in an hour) to get Wh.


  What happens if the sampling is not at a constant rate? My sampling rate varies a bit between 1 and 2s.


As long as you know the individual dt between readings you can work out the watt-seconds as before (using dt rather than '5').

You might improve the accuracy by using the average power for each period.

#    t      Power   Period average (W)   dt (s)   Energy (Ws)
0    0.0    0.31    -                    -        -
1    1.2    0.36    (0.31 + 0.36) / 2    1.2      0.402
2    3.0    0.40    (0.36 + 0.40) / 2    1.8      0.684