Last active
August 28, 2024 08:56
-
-
Save robintw/76a771f426d338479cec to your computer and use it in GitHub Desktop.
Code to read data from a CurrentCost EnviR electricity usage meter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
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?