Calculating RMS Voltage and Current to get Reactive Power and Real Power

Please note that the '^' operator in C and C++ is bitwise exclusive-or, not exponentiation. To square a number X, use X*X, not X^2.

OpenEnergyMonitor.org is a good resource for monitoring AC devices.