Custom User Code

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
islipfd19
Posts: 126
Joined: 07 Jul 2014 03:35

Custom User Code

Post by islipfd19 » 08 Jul 2014 22:47

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?

pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Custom User Code

Post by pofs » 09 Jul 2014 02:41

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.

islipfd19
Posts: 126
Joined: 07 Jul 2014 03:35

Re: Custom User Code

Post by islipfd19 » 09 Jul 2014 07:38

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

User avatar
kambis
Posts: 36
Joined: 23 Jun 2014 08:06
Location: Germany
Contact:

Re: Custom User Code

Post by kambis » 13 Jul 2014 20:37

You might like to have a look on this post:
viewtopic.php?f=3424&t=20528

islipfd19
Posts: 126
Joined: 07 Jul 2014 03:35

Re: Custom User Code

Post by islipfd19 » 02 Aug 2014 15:48

@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

User avatar
kambis
Posts: 36
Joined: 23 Jun 2014 08:06
Location: Germany
Contact:

Re: Custom User Code

Post by kambis » 02 Aug 2014 16:19

I saw your code in between, thank you for sharing.

Post Reply