Page 1 of 1

Custom User Code

Posted: 08 Jul 2014 22:47
by islipfd19
I'm attempting to add custom code to the automation section and I continue to see errors in the log file.
[2014-07-08 15:30:55.406] Scheduling execution of file: automation/update.js
...4-07-08 15:30:55.419] Executing script: function getDataUpdate(sync){
[2014-07-08 15:30:55.443] JavaScript compilation error: SyntaxError: Unexpected
end of input
at automation/modules/CustomUserCodeLoader/index.js:39:13
at Array.forEach (native)
at CustomUserCodeLoader.init (automation/modules/CustomUserCodeLoader/index.
js:34:33)
at AutomationController.reconfigureInstance (automation/classes/AutomationCo
ntroller.js:341:22)
at ZAutomationAPIWebRequest.<anonymous> (automation/webserver.js:542:44)
at ZAutomationAPIWebRequest.ZAutomationWebRequest.handleRequest (automation/
request.js:241:30)
at automation/request.js:31:35
at HTTP request:1:1
I've actually copied the code from the API that's available online at http://razberry.z-wave.me/docs/Z-WayAPI.pdf.

Code: Select all

function getDataUpdate(sync)	{	
 $.postJSON('/ZWaveAPI/Data/'+D.updateTime,handlerDataUpdate,sync);	
}		

$.postJSON = function(url, data, callback, sync) {	
	if (jQuery.isFunction(data)){	
		sync = sync || callback;	
		callback = data;	
		data = {};	
	};	
	$.ajax({
		type: 'POST',
		url: url,
		data: data,
		dataType: 'json',
		success: callback,
		error: callback,
		async: (sync!=true)
	});	
};		

function handlerDataUpdate(data) {
	try {
		$.each(data, function (path, obj) {	
		var pobj = D;
		var pe_arr = path.split('.');
		for (var pe in pe_arr.slice(0, -1)) {
			pobj = pobj[pe_arr[pe]];
		};	
		pobj[pe_arr.slice(-1)] = obj;
I don't know much about js but everything seems to be accurate, syntax wise. Does anyone have any thoughts?

Re: Custom User Code

Posted: 09 Jul 2014 02:41
by pofs
The code you quoted is client-side (intended for execution in browser with jQuery), but you're trying to use it at server side.
Furthermore, handlerDataUpdate function seems to be truncated in some brutal way.

Re: Custom User Code

Posted: 09 Jul 2014 07:38
by islipfd19
Do you know or can think of anything that can be used on the server side? Even something along the lines of a PHP script that can be scheduled to run frequently using cron. Basically, all that is needed is a way to query the z-wave switch component requesting whether it's on/off/(or what state it's in if it's a dimmer).

Re: Custom User Code

Posted: 13 Jul 2014 20:37
by kambis
You might like to have a look on this post:
viewtopic.php?f=3424&t=20528

Re: Custom User Code

Posted: 02 Aug 2014 15:48
by islipfd19
@Kambis:

Not sure how often you read your own posts...? I've replied to one of your posts where you responded to me in. I was able to figure out the correct syntax to poll for the switch state. I've uploaded the module for anyone to use if they like. viewtopic.php?f=3424&t=20588

Re: Custom User Code

Posted: 02 Aug 2014 16:19
by kambis
I saw your code in between, thank you for sharing.