Skip to content

Instantly share code, notes, and snippets.

@robintw
Last active September 12, 2023 17:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 !
Great scripting, it's great for me to monitor the Power Consumtion, but ....
I need to include the value on the script, it's the gasmeter value.

This is the line collected by the serial port.
<msg><src>CC128-v1.29</src><dsb>01248</dsb><time>09:31:32</time><tmpr>19.0</tmpr><sensor>0</sensor><id>02040</id><type>1</type><ch1><watts>00188</watts></ch1></msg>
<msg><src>CC128-v1.29</src><dsb>01248</dsb><time>09:31:35</time><tmpr>19.0</tmpr><sensor>3</sensor><id>03352</id><type>2</type><imp>0000000664</imp><ipu>1000</ipu></msg>

I try with
impulse=int.(p.msg.imp.cdata)

But it doesn't work ...

Any help with it?

@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