/data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=[sliderval]
http://192.168.1.90:3480/data_request?id=lu_status2&DataVersion=1&output_format=xml&DeviceNum=3
<root LoadTime="1385141152" DataVersion="141597519" UserData_DataVersion="141152053" TimeStamp="1385193505" ZWaveStatus="1" LocalTime="2013-11-23 08:58:25 D">
<Device_Num_3 status="-1">
<states>
<state id="133" service="urn:upnp-org:serviceId:SwitchPower1" variable="Status" value="1"/>
<state id="134" service="urn:upnp-org:serviceId:Dimming1" variable="LoadLevelStatus" value="22"/>
<state id="135" service="urn:upnp-org:serviceId:Dimming1" variable="LoadLevelTarget" value="22"/>
<state id="136" service="urn:micasaverde-com:serviceId:EnergyMetering1" variable="Watts" value="26"/>
<state id="137" service="urn:micasaverde-com:serviceId:EnergyMetering1" variable="Log" value="26,26,26,1385191800,1"/>
<state id="138" service="urn:micasaverde-com:serviceId:ZWaveDevice1" variable="Neighbors" value="1,3,"/>
<state id="139" service="urn:micasaverde-com:serviceId:ZWaveDevice1" variable="LastRouteUpdate" value="1385177593"/>
</states>
<Jobs/>
<tooltip display="0"/>
</Device_Num_3>
</root>
{ "Device_Num_3": { "states": [ { "id": 147, "service": "urn:upnp-org:serviceId:SwitchPower1", "variable": "Status", "value": "1" }, { "id": 148, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelStatus", "value": "22" }, { "id": 149, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelTarget", "value": "22" }, { "id": 150, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Watts", "value": "26" }, { "id": 151, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Log", "value": "26,26,26,1385191800,1" }, { "id": 152, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "Neighbors", "value": "1,3," }, { "id": 153, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "LastRouteUpdate", "value": "1385177593" } ], "Jobs": [ ], "tooltip": { "display": 0 }, "status": -1 }, "LoadTime": 1385141152, "DataVersion": 141597519, "UserData_DataVersion": 141152053, "TimeStamp": 1385193954, "ZWaveStatus": 1, "LocalTime": "2013-11-23 09:05:54 D" }
{ "Device_Num_3":
{ "states":
[
{ "id": 133, "service": "urn:upnp-org:serviceId:SwitchPower1", "variable": "Status", "value": "1" }
,
{ "id": 134, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelStatus", "value": "22" }
,
{ "id": 135, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelTarget", "value": "22" }
,
{ "id": 136, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Watts", "value": "26" }
,
{ "id": 137, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Log", "value": "26,26,26,1385191800,1" }
,
{ "id": 138, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "Neighbors", "value": "1,3," }
,
{ "id": 139, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "LastRouteUpdate", "value": "1385177593" }
]
,
"Jobs": [ ],
"tooltip": { "display": 0 },
"status": -1 },
"LoadTime": 1385141152,
"DataVersion": 141598008,
"UserData_DataVersion": 141152054,
"TimeStamp": 1385197018,
"ZWaveStatus": 1,
"LocalTime": "2013-11-23 09:56:58 D" }
I strongly suggest you "Bite the Bullet" and learn enough Javascript to allow you to do feedback processing. This is especially true for complex returns such as you are showing. On my web site (The-gordons.net) I have posted a weather module which gets back responses in the form of JSON strings. The feedback is all done in JS. You could use it as an example on one way of doing it. The nice thing about the JSON return format and doing the processing in JS is that there is really no parsing. A single JS command converts the JSON text string to a true Javascript Object. Once it is in object form, retrieval of individual values is trivial. the only non-trivial aspect to your JSON string is the fact that there is an array of objects embedded in the returned object, so for that object you will need a loop construct to handle each of the array members (objects). The weather module does that for the 10 day forecast.
--
You received this message because you are subscribed to the Google Groups
"CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
self.loadRooms = function () {
// Load the XML data from a URL
CF.request(self.url, function (status, headers, body) {
// Check that the URL request returned without error
if (status == 200) {
// Use the returned body and create an XML DOM object
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(body, 'text/xml');
// Get the house name
self.houseName = xmlDoc.getElementsByTagName("root")[0].attributes["LocalTime"].value;
CF.setJoin("s109", self.houseName);
// Clear any existing rooms and levels before loading the new ones
self.levels = [];
var levelNodes = xmlDoc.getElementsByTagName("states");
for (var i = 0; i < levelNodes.length; i++) {
// Create the level object
var newLevel = new Level(levelNodes[i].childNodes[0].nodeValue, 'Getfeedback');
CF.log("Level: " + levelNodes[i].childNodes[0].nodeValue);
// Get the room nodes
for (var j = 0; j < levelNodes[i].childNodes.length; j++) {
if (levelNodes[i].childNodes[j].nodeName == "state") {
// Add the room to the level
newLevel.rooms.push(new Room(levelNodes[i].childNodes[j].attributes["variable"].value, levelNodes[i].childNodes[j].attributes["value"].value));
CF.log("Room: " + levelNodes[i].childNodes[j].attributes["value"].value);
}
}
self.levels.push(newLevel);
}
// Finished parsing the XML, now sort the levels and setup the list
self.levels.sort(self.sortLevels);
self.showLevelsList();
} else {
CF.log("XML Request Failed with status " + status);
}
});
};
return self;
};
That is why I recommended the JSON format. It eliminates the XML parsing issue.
Search the web for XML2JSON; a function written by Thomas Frank. That might help you
From: comman...@googlegroups.com
[mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Saturday, November 23, 2013 12:00 PM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback
OK, one more step ahead: I could manage to get my values as a final result, when querying only one device (http://192.168.1.90:3480/data_request?id=lu_status2&DataVersion=1&output_format=xml&DeviceNum=3 as the XML url), and changing a part of the javascript as follow:
--
Look at the function Process JSON in the weather module. It does all the work. You might also want to go to wunderground.com to look at what they return so you have a better idea of what the JSON being returned looks like. The JSON objects are very well documented.
In the weather module there are also debugging and diagnostic tool that I use to see what is going on. Are you familiar with using chrome or safari to display data as the system is running.
If you are still having an issue let me know tomorrow and I will write something for you that should explain it all based upon what you are getting back. I will annotate it heavily so you should be able to understand what I am doing. You can easily reach me by eMail my name you know and my domain you know so my email address should be obvious.
To make things very easy for me, send me your complete project. The best way to do that IMHO is sendspace.com which is a free system for sending large files. In that way I will start with what you have and integrate what you need, I will not be able to test it since I do not have the equipment, but if the JSON you posted is correct I will dummy that in as the reply.
From: comman...@googlegroups.com
[mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Saturday, November 23, 2013 12:52 PM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback
Barry,
--
var time=obj.Device_Num_3.LocalTime;
CF.setJoins([{join:"s100", value:time},
WT.listLoad(obj.forecast.txt_forecast.forecastday);
{ "Device_Num_3":
{ "states":
[
{ "id": 126, "service": "urn:upnp-org:serviceId:SwitchPower1", "variable": "Status", "value": "0" },
{ "id": 127, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelStatus", "value": "0" },
{ "id": 128, "service": "urn:upnp-org:serviceId:Dimming1", "variable": "LoadLevelTarget", "value": "0" },
{ "id": 129, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Watts", "value": "0" },
{ "id": 130, "service": "urn:micasaverde-com:serviceId:EnergyMetering1", "variable": "Log", "value": "0,0,0,1385195400,1" },
{ "id": 131, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "Neighbors", "value": "1,3," },
{ "id": 132, "service": "urn:micasaverde-com:serviceId:ZWaveDevice1", "variable": "LastRouteUpdate", "value": "1385177593" }
You are getting the idea.
The JSON in your case is unique. The first object is named Device_Num_3 and is complex containing an array of objects.
The objects in Device_Num_3 are
"states": an array of objects
"Jobs": an array which is empty
"tooltip": a single object and
"status: an integer with the value of -1
There are then 6 objects each one being a simple name value pair; LoadTime, DateVersion, . . .
your var time statement is correct assuming that when you parsed the JSON string you set it into a var called obj.
The setJoin also looks correct
Now for the states array something like
for(var i=0; i<obj.Device_Num_3.states.length; i++)
{ if(obj. Device_Num_3.states[i].variable== "LoadLevelStatus")
{ // do whatever You need to do here such as:
CF.setJoins([join:"s100", value: obj. Device_Num_3.states[i].value])
};
};
the above is similar to what happens in loadList where the action is to put the desired value into a list item since I want to show all the forecasts in a scrolling list
Hope that helps
As you gain understanding you will begin to appreciate how powerful using JS can be.
From: comman...@googlegroups.com
[mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Saturday, November 23, 2013 3:36 PM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback
So, I could get the json from wunderground.com, it's more clear now for me. Indeed, you are right, it seems pretty straight forward to obtain the different objects with JSON feedbacks.
--
And to be more efficient in a code sense:
CF.setJoins([{join:"s100", value: obj.Device_Num_3.LocalTime },
I do it with the explicit var so I can display it during debugging to check I have it correct.
From: comman...@googlegroups.com
[mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Saturday, November 23, 2013 3:36 PM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback
So, I could get the json from wunderground.com, it's more clear now for me. Indeed, you are right, it seems pretty straight forward to obtain the different objects with JSON feedbacks.
--
http://192.168.1.90:3480/data_request?id=lu_status2&DataVersion=1&DeviceNum=3
for(var i=0; i<obj.Device_Num_3.states.length; i++)
{ if(obj. Device_Num_3.states[i].variable== "LoadLevelStatus")
{ // do whatever You need to do here such as:
CF.setJoins([join:"s100", value: obj. Device_Num_3.states[i].value])
};
};
Before you go crazy:
Do you understand how to use the Chrome (or Safari, I use Chrome) browser to debug the javascript code? As a minimum you should understand how to use the CF.log and CF.objectLog functions; and how to set your iPad to use the debugger when load iViewer. This is all covered in the CommandFusion documents on scripting and in their Wiki.
The Weather Demo module in my web site has CF.log statements in the code but they are all controlled by some debugging constants (e.g. trace, debug, etc.) for example
if(WT.trace) CF.log("Text_string_to_display_in_the_debugger");
With regard to doing the CF.request, the getWeather function in the weather demo system is where the correct URL for the weather system is built. Very similar code in your module would be necessary to dynamically build the URL you require. If the URL is always the same, then you just need to do:
CF.request("Your_URL", your_feedback_Function_name);
I strongly suggest you get a wunderground api, place it in the appropriate spot in the weather demo and get weather demo to work with debugging turned on. (e.g. trace: true, debug: true, etc.) . Play with it until you really understand how it works. It is not at all complex. Do not worry about anything in the JS weather module that are internal functions.
Also find and use a Javascript editor that does syntax checking. I use cPoint's Antechinus editor. It is not free, but is relatively in expensive.
Lastly, The Javascript coding style I use makes every module except one a large object with a simple name (in the weather demo the name is WT). One module is coded straight and generally has functions used by all the modules in a project (e.g the Common_Subroutines.js module). This allows me to use the same function names, e.g. setup, initialize, etc. in every module in the project. when referenced, these functions are referenced as object_name.function_name() e.g. WT.initialize(). This style is also covered in the CommandFusion scripting documents.
PS I have revised the weather demo program on my site taking out some extraneous stuff.
Hope That helps
From: comman...@googlegroups.com
[mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Sunday, November 24, 2013 4:21 AM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback
I was enthusiast this morning... until I found out I was not even able to call my json file by a simple CF.request function.
--
I believe the error is in the function getDeviceVariable. There is a reference to JSON[device] but device has not been defined.
In the function getVariable, there is a similar usage but device is defined in the outer for statement
I believe the correction is to change JSON[device] to JSON[deviceName] in the two occurrences in getDeviceVariable
From: comman...@googlegroups.com
[mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Sunday, November 24, 2013 9:31 AM
To: comman...@googlegroups.com
Cc: jar...@commandfusion.com
Subject: Re: http xml/json feedback
Wahoo...you guys just come on time when I was about to give up! That's really nice, thanks.
--
You should start to think about how to organize your JS modules. I use one of the Standard Javascript patterns. A JS pattern is just a way of coding the module. All my projects follow the same general style. The differences are mainly in when I developed them. I organize a project in a master project folder so it has three main parts:
1- the gui file
2- a resource folder which holds all of the projects resources (Graphics generally). Often the resource folder has sub folders.
3- a Javascript folder that contains all of the Javascript files (modules)
For non-demo projects
There is a javascript module called Main which has various common functions, including the CF.userMain function.
There is a Common_subroutines module which holds the obvious
All other modules are coded as objects containing a master object in which are function, and data unique to that module
For demo projects I sometimes combine Main, and Common_Subroutines into the demo javascript module
For example of a slider look at the Serial and IR demo on my web site. It is a much "richer" project that does IR and serial (RS232) communications using an iTach as the converter from IP. The anthem module which handles the Anthem AVP over a serial port has a slider implemented for volume control as an example.
From: comman...@googlegroups.com
[mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Sunday, November 24, 2013 11:03 AM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback
Good catch Barry!
--
Feel free to ask questions here or using my email address (preferred) regarding how any of the functions I write works.
Do you have a good Javascript reference? I use Javascript: The Definitive Guide by David Flanagan; publisher O'Reilly
From: comman...@googlegroups.com [mailto:comman...@googlegroups.com] On Behalf Of Guillaume Vigneron
Sent: Sunday, November 24, 2013 11:03 AM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback
Good catch Barry!
--
if myJSON["Device_Num_"+deviceNum] == myJSON["Device_Num_4"]
return CF.setJoin("s104", myJSON["Device_Num_4"].states[1].value);
var myJSON, baseURL = "http://192.168.1.90:3480/data_request?id=lu_status2&DataVersion=1";
function requestData(deviceNum) {
CF.request(baseURL, function(status, headers, body) {
if (status == 200) {
// OK response received, now grab the JSON string from body and turn it into an object
myJSON = JSON.parse(body);
// Now assign one of the known state variables to a serial join (if it will always be at a certain index in the state & device array)
CF.setJoin("s100", myJSON.devices[1].states[1].value);
// Now assign one of the known state variables to a serial join (if it will always be at a certain index in the state & device array)
CF.setJoin("s104", myJSON.devices[2].states[1].value);
// Analog Join for slider position when another user change the light dimmer. (if it will always be at a certain index in the state & device array)
CF.setJoin("a1000", (myJSON.devices[1].states[1].value)*655.35);
// Analog Join for slider position when another user change the light dimmer. (if it will always be at a certain index in the state & device array)
CF.setJoin("d10", myJSON.devices[2].states[0].value);
}
});
}
The feedback is is only triggered by the page timer. So, on all the pages that will display z-wave feedback in your project you need to set up this timer.Just reproduce the page timer you can see on my project and it should work.
To learn Javascript there are many tutorials and step by step lessons on the WWW. A quick search with Google or Yahoo for Javascript tutorials should provide you what you need.
An excellent reference book, not a tutorial, is "Javascript, The Definitive Guide" by Flanagan. As a reference it does not teach Javascript but provides a place to look things up.
From: comman...@googlegroups.com
[mailto:comman...@googlegroups.com] On Behalf Of ian
Sent: Tuesday, March 25, 2014 4:57 AM
To: comman...@googlegroups.com
Subject: Re: http xml/json feedback
HI Guillaume!
--
You received this message because you are subscribed to the Google Groups
"CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Regarding the device number that change, it's because the request URL query only devices that had a status changed recently. I did'nt know that when I first created this code, I have changed the URL since that. I'll give you the proper URL later today.
Regards,
Guillaume
Having not seen the JS code, the status==200 is normally a check on the status returned by a CF.request. The CF.request will do an http request to a server. the returned status argument is the status returned by the server. There are many different status values. 200 is "okay". The following link shows all the http status values returned:
From: comman...@googlegroups.com
[mailto:comman...@googlegroups.com] On
Behalf Of Bob Green
Sent: Saturday, December 02, 2017
9:08 AM
To: CommandFusion Software
Subject: Re: http xml/json
feedback
Hi Thiago - I know this is an old thread, but I'm trying to implement your Vera feedback and have a couple questions:
--