Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Original thread:
Post 6 made on Tuesday January 21, 2020 at 11:12
randman
Long Time Member
Joined:
Posts:
June 2003
421
On January 21, 2020 at 03:13, Fischi said...
Hi,
I have added json2.js to my library.
I'm a newbie in Pronto with Json.
Can anybody help me to let the pronto communicate over json ?
My HomeSeer system is able to Json and I want to have access to it with
my TSu-9800.
A .xcf file would be fine for me so I could learn and try.

Regards,
Fischi

I have HomeSeer as well and I use http from my Pronto TSU9400 to tell HomeSeer to run events. My use case is to define HomeSeer events in HomeSeer, and then have my Pronto call those HomeSeer events. Since the response of running events from HomeSeer back to Pronto is fairly simple, I didn't need to use JSON.parse() to parse the response from HomeSeer. (But, if you have something more complicated than running events to do, then you may need to use JSON.parse() to parse HomeSeer's response).

Below is an excerpt/example of how to tell Pronto to run a HomeSeer event:

// In Main part of JavaScript:

var HomeSeer = {};
HomeSeer.lastMessageSent = "";
HomeSeer.lastResponseReceived = "";
HomeSeer.IP = "x.x.x.x"; // assign HomeSeer IP here
// Below assumes HomeSeer configured to not require user/password when
// request coming from local LAN:
HomeSeer.msgPrefix = "http://" + HomeSeer.IP + "/JSON?request=";

...

function runEvent(groupName, eventName)
{
var msg = "", msgSuffix = "";

// Use encodeURI in case groupName or eventName have spaces:
msgSuffix = "runevent&group=" + encodeURI(groupName) + "&name=" + encodeURI(eventName);
msg = HomeSeer.msgPrefix + msgSuffix;
HomeSeer.lastMessageSent = msgSuffix;
com.philips.HttpLibrary.getHTTP(msg, processResponse);
} // runEvent


function processResponse(rcvd)
{
var arg = "", copyLen;
// For runEvent response, HomeSeer returns "{ "Response":"ok" }" if it
// was successful
if (rcvd.length >= 16) {
HomeSeer.lastResponseReceived = rcvd.substr(14, 2);
}
else if (rcvd.length > 2) {
// Remove "\r\n" at the end of the string
HomeSeer.lastResponseReceived = rcvd.substr(0, rcvd.length - 2);
}
else {
// "Warning: length of string received from HomeSeer <= 2. Length = " + rcvd.length, 0);
HomeSeer.lastResponseReceived = rcvd;
}

if (HomeSeer.lastResponseReceived == "ok") {
// trace/debug string: "Command " + HomeSeer.lastMessageSent + " completed successfully.", 3);
}
else {
// trace/debug string: "ERROR. Command failed: " + HomeSeer.lastMessageSent + ".", 0);
}
} // processResponse

….

Then, from another Javscript, or from an Actions tab of Pronto, you can call:

runEvent("Some Group Name","Some Event Name");

EDIT: oops, somehow, the spacing/indentation of above code was not preserved once I submitted my response, but the code should still be fairly straightforward to see.


Hosting Services by ipHouse