Thank you for the info, pofs.
I'm also going to do some projects with XML. But now watching pz1 activities
Read value from XML document
Re: Read value from XML document
Razberry B+ 2.0.1-rc25 on ZW500 + 15 devices / Razberry B 2.0.1-rc25 on ZW300 for test
Re: Read value from XML document
No I did not, because imho the problem is not in getting the XML in. It works in my earlier post about the Solar monitor (PVLogger) example. That works for a rather flat xml.dolpheen wrote: Did you try my example?
So I guess here there is something funny with the path selection, or I am missing a stupid typo again
Re: Read value from XML document
Looks like this was the case. After several searches here an in my code, I found the findOne had lost its capitalisation of the Opz1 wrote: or I am missing a stupid typo again
Re: Read value from XML document
Got Wunderground Weather Services working now for both JSON and XML.
The essential part for XML based weather report is:
The call
produces:
So many thanks to Pofs and Dolpheen for their support
The essential part for XML based weather report is:
Code: Select all
Wunderground.prototype.fetchWeather = function (instance) {
var self = instance;
http.request({
url : "http://api.wunderground.com/api/" + self.config.key + "/conditions/forecast/q/" + self.config.country + "/" + self.config.city + ".xml",
method : "GET",
async : true,
success : function (response) {
var doc = response.data; // it is already ZXmlDocument
try {
temp_c = parseFloat(doc.findOne("/response/current_observation/temp_c/text()"));
windgust = parseFloat(doc.findOne("/response/current_observation/wind_gust_kph/text()"));
wind_degrees = parseFloat(doc.findOne("/response/current_observation/wind_degrees/text()"));
observe_time = doc.findOne("/response/current_observation/local_time_rfc822/text()");
max_temp = parseInt(doc.findOne("/response/forecast/simpleforecast/forecastdays/forecastday/high/celsius/text()"));
icon = doc.findOne("/response/current_observation/icon_url/text()");
self.vDev.set("metrics:level", temp_c);
self.vDev.set("metrics:windgust", windgust);
self.vDev.set("metrics:wind_degrees", wind_degrees);
self.vDev.set("metrics:observe_time", observe_time);
self.vDev.set("metrics:max_temp", max_temp);
self.vDev.set("metrics:icon", icon);
} catch (e) {
self.controller.addNotification("error", "Can not parse weather information", "module");
}
},
error : function () {
self.controller.addNotification("error", "Can not fetch weather information", "module");
}
});
};
Code: Select all
http://raspi-ip:8083/JS/Run/controller.devices.get("Wunderground_8").get("metrics")
Code: Select all
{"scaleTitle":"°C","title":"lauwersoog","probeTitle":"Temperature","level":6.9,"windgust":16.9,"wind_degrees":112,"observe_time":"Sat, 28 Feb 2015 19:29:37 +0100","icon":"http://icons.wxug.com/i/c/k/nt_cloudy.gif","max_temp":8}
Re: Read value from XML document
I have been fiddling with the PVLogger module a bit. I tried to combine the output of two loggers into one module. No success. So I deleted and commented some of the added code. However if I do ask for the metrics now:pz1 wrote:After upgrade to 2.0.1 RC16 I do get as expected:pz1 wrote: Unfortunately, something seems to go wrong with the Virtual Device creation.
producesCode: Select all
http://rasp_IP:8083/JS/Run/controller.devices.get("PVLogger_17").get("metrics")
I am surprised by getting the sensors twice, and with different values. I did not expect to get gauge_power and energy_todayCode: Select all
{"scaleTitle":"W","title":"Solar Power","probeTitle":"Watt","gauge_power":473,"energy_today":0.548,"power":614,"energy":5}
Code: Select all
{"scaleTitle":"W","title":"Solar Power","probeTitle":"Watt","level":2797,"energy":4.6}
Code: Select all
http://quadras:8083/JS/Run/controller.devices.get("PVLogger_15").get("metrics")
Code: Select all
{"scaleTitle":"W","title":"Solar Power","probeTitle":"Watt","level":251,"energy1":0.272,"level2":244,"energy2":0.25,"icon":"http://quadras:8083/user/solarok58px.png","kWh":null,"watts1":229,"kWh1":1.6,"watts2":381,"kWh2":1.3}
Code: Select all
{"scaleTitle":"W","title":"Solar Power","probeTitle":"Watt","level":251,"icon":"http://quadras:8083/user/solarok58px.png","kWh1":1.6}
Present code in the attached ZIP (deleted)
Re: Read value from XML document
Ah, I do understand now. All these variables are permanently kept in storage/configjson-xxxxx.json. No clean-up if the module is changed. (Old modules still reside there to. I did mention that on Github)pz1 wrote: I do get the following mess of values:Code: Select all
{"scaleTitle":"W","title":"Solar Power","probeTitle":"Watt","level":251,"energy1":0.272,"level2":244,"energy2":0.25,"icon":"http://quadras:8083/user/solarok58px.png","kWh":null,"watts1":229,"kWh1":1.6,"watts2":381,"kWh2":1.3}
Code: Select all
"PVLogger_15" : {
"deviceType" : "sensorMultilevel",
"metrics" : {
"scaleTitle" : "W",
"title" : "Solar Power",
"probeTitle" : "Watt",
"level" : 98,
"energy1" : 0.272,
"level2" : 244,
"energy2" : 0.25,
"icon" : "http://quadras:8083/user/solarok58px.png",
"kWh" : null,
"watts1" : 229,
"kWh1" : 0.172,
"watts2" : 381,
"kWh2" : 1.3
},
"location" : null,
"tags" : [],
"permanently_hidden" : false
},