Thank you Tom,
I corrected my code (ted.py) thanks to your link :
import syslog
import weewx
from weewx.wxengine import StdService
import urllib2
import xml.etree.ElementTree as ET
class electricityService(StdService):
def __init__(self, engine, config_dict):
try:
super(electricityService, self).__init__(engine,
config_dict)
d = config_dict.get('electricityService', {})
self.dashdata_url = d.get('dashdata_url',
'http://192.168.1.77:8089/api/DashData.xml?T=0&D=0&M=1')
syslog.syslog(syslog.LOG_INFO, "TED Pro: probing %s"
% self.dashdata_url)
self.bind(weewx.NEW_ARCHIVE_RECORD, self.read_xml)
self.previousEnergy = None
except Exception as e:
syslog.syslog(syslog.LOG_ERR, "TED Pro: cannot reach
TED url: %s" % e)
def read_xml(self, event):
try:
xmlurl = urllib2.urlopen(self.dashdata_url)
xmldata = xmlurl.read()
tree = ET.fromstring(xmldata)
# gives Wh since a zero (since midnight)
currentEnergy = float(tree.find('TDY').text) / 1000
# gives voltage of my installation in V
event.record['networkVoltage'] = float(tree.find(
'Voltage').text) / 10
if self.previousEnergy:
# record energy consumption over a period (5 min in my weewx.conf)
event.record['powerConsumption'] =
currentEnergy - self.previousEnergy
self.previousEnergy = currentEnergy
except Exception as e:
syslog.syslog(syslog.LOG_ERR, "TED Pro: cannot read
value: %s" % e)
This allows to read directly xml data from a URL.
Now the database is populated with voltage and energy consumption by my
house. I give the code in case somebody is interested.
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.