Skip to content

Instantly share code, notes, and snippets.

@robintw
Last active August 28, 2024 08:56
Show Gist options
  • Save robintw/76a771f426d338479cec to your computer and use it in GitHub Desktop.
Save robintw/76a771f426d338479cec to your computer and use it in GitHub Desktop.
Code to read data from a CurrentCost EnviR electricity usage meter
import untangle
import serial
def get_data(port='/dev/ttyUSB1', verbose=False):
"""Gets temperature and power usage data from an attached CurrentCost meter.
Parameters:
- port: the port that the CurrentCost meter is attached to. Somthing like /dev/ttyUSB0 or COM1
Returns:
(temperature, usage), with temperature in degrees C, and usage in Watts
"""
ser = serial.Serial(port, 57600)
xmldata = ser.readline()
if verbose:
print(xmldata)
ser.close()
p = untangle.parse(xmldata)
temperature = float(p.msg.tmpr.cdata)
watts = int(p.msg.ch1.watts.cdata)
return (watts, temperature)
@Danifont
Copy link

Danifont commented Apr 3, 2019

HI ! Solved it ...
The problem is with the output ... If don't found value for the Watts or for the imp don't produce the output of return ... I add a dummy value and output the 3 values and all runs !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment