Hello,

I try to adapt the code of the Pond service found at 
https://github.com/weewx/weewx/wiki/add-sensor to access xml data from a 
known url and record these data in my sqlite weewx database. Sure I am not 
a Python guy and I did my best to write the following code :

import syslog
import weewx
from weewx.wxengine import StdService
import urllib2
import xml.etree.ElementTree as ET

class ElectronService(StdService):
        def __init__(self, engine, config_dict):
                try:
                        super(ElectronService, self).__init__(engine, 
config_dict)
                        self.dashdata_url = 
'http://192.168.1.111/api/DashData.xml?T=0&D=0&M=1'
                        xmlurl = urllib2.urlopen(self.dashdata_url)
                        xmldata = xmlurl.read()
                        tree = ET.parse(xmldata)
                        root = tree.getroot()
                        syslog.syslog(syslog.LOG_INFO, "TED Pro: probing 
%s" % self.dashdata_url)
                        self.bind(weewx.NEW_ARCHIVE_RECORD, self.read_xml)
                except Exception as e:
                       syslog.syslog(syslog.LOG_ERR, "TED Pro: cannot reach 
TED url: %s" % e)

        def read_xml(self, event):
                try:
                       event.record['networkVoltage'] = 
float(root.find('Voltage').text)
                       event.record['powerConsumption'] = 
float(root.find('TDY').text)
                except Exception as e:
                       syslog.syslog(syslog.LOG_ERR, "TED Pro: cannot read 
value: %s" % e)


Could you give some advises on this code ?

For example I do not understand the line : 
self.bind(weewx.NEW_ARCHIVE_RECORD, self.read_xml)

read_xml is defined with two parameters but in this line this function is 
not even called with parameters ...

Thank you.

-- 
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.

Reply via email to