Custom Javascript code stop working until manually restarted

Discussions about RaZberry - Z-Wave board for Raspberry computer
simonc
Posts: 16
Joined: 16 Aug 2015 18:43

Custom Javascript code stop working until manually restarted

Post by simonc »

Hi,

I got a Razberry setup with one door sensor that when is triggered start a custom Java code using the App "Load custom JavaScript code".

Everything was working fine until a couple of days ago , now it's not and I have not touched the configuration at all ( not in the OS not in the wave software I have 2.0.1).

Long story short: the sensor is working and communicating , the web interface dashboard is working and I can see the sensor activating but the Java code is not even launched.

If I go in the smart home web guy -> App -> Load custom JavaScript code and save my code again without even touching it everything seems to work again but...if i restart the raspberry everything is "NOT" working again...

It seems that the module ID 7 cannot be loaded...sometimes ( but not always) I see this error messages, in this case I have just rebooted the raspberry :

Code: Select all

[2015-08-29 11:47:48.419] [I] [core] Loading module HTTPDevice from modules/HTTPDevice
[2015-08-29 11:47:48.423] [I] [core] Executing script: /*** HTTPDevice Z-Way HA module *********************************
********** ...
[2015-08-29 11:47:48.424] [I] [core] Loading module CustomUserCode from modules/CustomUserCode
[2015-08-29 11:47:48.426] [I] [core] Executing script:   /*** CustomUserCode ZAutomation module ************************
**************** ...
[2015-08-29 11:47:48.429] [I] [core] Instantiating module 7 from class CustomUserCode
[2015-08-29 11:47:48.430] [I] [core] --- Starting module Load custom JavaScript code
[2015-08-29 11:47:48.434] [I] [core] Executing script: zway.devices[3].instances[0].commandClasses[48].data[1].level.bind(function() { ...
[2015-08-29 11:47:48.466] [E] [core] result: Error: ReferenceError: zway is not defined
    at <anonymous>:1:1
    at CustomUserCode.init (automation/modules/CustomUserCode/index.js:36:30)
    at AutomationController.instantiateModule (automation/classes/AutomationController.js:300:22)
    at AutomationController.<anonymous> (automation/classes/AutomationController.js:392:18)
    at Array.forEach (native)
    at AutomationController.loadModule (automation/classes/AutomationController.js:391:8)
    at AutomationController.<anonymous> (automation/classes/AutomationController.js:409:14)
    at Array.forEach (native)
    at AutomationController.instantiateModules (automation/classes/AutomationController.js:408:46)
    at AutomationController.start (automation/classes/AutomationController.js:147:10)
[2015-08-29 11:47:48.480] [I] [core] Notification: error (core): Cannot instantiate module: CustomUserCode: Error: Uncaught ReferenceError: zway is not defined
[2015-08-29 11:47:48.489] [I] [core] Error: Uncaught ReferenceError: zway is not defined
    at Error (native)
    at CustomUserCode.init (automation/modules/CustomUserCode/index.js:36:30)
    at AutomationController.instantiateModule (automation/classes/AutomationController.js:300:22)
    at AutomationController.<anonymous> (automation/classes/AutomationController.js:392:18)
    at Array.forEach (native)
    at AutomationController.loadModule (automation/classes/AutomationController.js:391:8)
    at AutomationController.<anonymous> (automation/classes/AutomationController.js:409:14)
    at Array.forEach (native)
    at AutomationController.instantiateModules (automation/classes/AutomationController.js:408:46)
    at AutomationController.start (automation/classes/AutomationController.js:147:10)

is there a way to use only cli to handle custom java code?
Can I restart the App Custom Java Code from the cli?

hope sameone helps!


EDIT: Looking at the logs, I don't know if there is a connection between the "zway is not defined error" and the custom code not working anymore, but I forgot to tell you that in the zway log, from the day when Customcode execution was not working there were no more messages, everything was silent...
Last edited by simonc on 08 Dec 2015 03:15, edited 1 time in total.
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Custom Java code stop working until manually restarted

Post by PoltoS »

This is a know feature. Z-Wave object might start after your Custom code. So when your code is executed, zway object is not defied yet and hence you get the error.

See for example this: viewtopic.php?t=20849&p=57468#p57380
simonc
Posts: 16
Joined: 16 Aug 2015 18:43

Re: Custom Java code stop working until manually restarted

Post by simonc »

Thanks for the reply.

But I don't understand the mechanism ... it's my code problem or is a CustomUserCode App Problem?

my personal code is:

Code: Select all

zway.devices[3].instances[0].commandClasses[48].data[1].level.bind(function() {
    if (this.value == true)
         system('/opt/z-way-server/automation/userModules/myscript.bash');
});
Did I have to put some code to wait at the beginning?

Is there somewhere some example? I really don't code in JS...
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Custom Java code stop working until manually restarted

Post by pz1 »

PoltoS wrote:This is a know feature. Z-Wave object might start after your Custom code. So when your code is executed, zway object is not defied yet and hence you get the error.

See for example this: viewtopic.php?t=20849&p=57468#p57380
Sorry to say this, but the code that you refer to does not work. It is highly unpredictable if the bindings do get made or not. I have to fiddle with many times doing Zway stop/start, which often leads to the loss of my configuration. Also many reboots

Since rc7 update this morning I have been unable to get both my machine to start sending these UDP messages.
Frankly it is a nail to my coffin, and as a matter of fact (regrettably) a show-stopper for me.

Update 20151202 My code (UDP sender) that PoltoS referred to is working robustly for a couple of months now. I have to thank Pofs to point me to a misunderstanding on my side
Since 29-12-2016 I am no longer a moderator for this forum
simonc
Posts: 16
Joined: 16 Aug 2015 18:43

Re: Custom Java code stop working until manually restarted

Post by simonc »

is there any news about this?

sorry Poltos but I don't understand how the topic you linked is about my problem, and most of all the reason that this is a "feature".

For some time I had no problem after a couple of restarts but now the problem is up again, always.
I updated the Razberry software to the latest stable release but the results are the same.. I don't know what can I do to solve this problem, Razberry is useless in this way ...

It sounds like a bug to me, a bug of custom Java code module that randomly stop working, there is no other way I can explain this...

Simone
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Custom Java code stop working until manually restarted

Post by pz1 »

I updated my post above
simonc
Posts: 16
Joined: 16 Aug 2015 18:43

Re: Custom Java code stop working until manually restarted

Post by simonc »

Thank you pz1 for the reply, but I 'm not a Js programmer , I had already read your thread even with the last updates but I thought that your case was different, I really am not in this type of coding.

This is my code:

Code: Select all

zway.devices[3].instances[0].commandClasses[48].data[1].level.bind(function() {
    if (this.value == true)
         system('/opt/z-way-server/automation/userModules/myscript.bash');
});
I just want to execute a bash script if one sensor is alarmed, that's it, what is that I need to check or add there? Is it there or in other files or configuration?

You are talking about iteration bindings in the other thread I really am not in that kind of programming, so here is the simple question:

1) can we write here down an official and working example of launching a shell script when one sensor is alarmed?
simonc
Posts: 16
Joined: 16 Aug 2015 18:43

Re: Custom Java code stop working until manually restarted

Post by simonc »

Again , I tried to adjust my script in this way:

Code: Select all

this.bindFunc1 = function (zwayName) {
   if (zwayName != "zway")
      return; // you want to bind to default zway instance

   var devices = global.ZWave[zwayName].zway.devices;

   //from here insert your devices

 zway.devices[3].instances[0].commandClasses[48].data[1].level.bind(function() {
    if (this.value == true)
         system('/opt/z-way-server/automation/userModules/sendmailalert-portacasa.bash');
});

};
// process all active bindings
if (global.ZWave) {
   global.ZWave().forEach(this.bindFunc1);
}

// and listen for future ones
global.controller.on("ZWave.register", this.bindFunc1);
The system is not return any "away not defined" error at boot or in any ways , but the script is not launched...
ricargr
Posts: 15
Joined: 13 May 2014 22:47

Re: Custom Javascript code stop working until manually resta

Post by ricargr »

Please do you have any advance in this?
I have the same problem that simon explains


Thank you in advance
simonc
Posts: 16
Joined: 16 Aug 2015 18:43

Re: Custom Javascript code stop working until manually restarted

Post by simonc »

So , just for who get the same problem but cannot get help from this forum, I found the problem, here down the code that works for me:

Code: Select all

this.bindFunc1 = function (zwayName) {
   if (zwayName != "zway")
      return; // you want to bind to default zway instance

   var devices = global.ZWave[zwayName].zway.devices;

   //from here insert your devices
   devices[3].instances[0].commandClasses[48].data[1].level.bind(function() {
    if (this.value == true)
         system('/opt/z-way-server/automation/userModules/sendmailalert-portacasa.bash');
});

};
// process all active bindings
if (global.ZWave) {
   global.ZWave().forEach(this.bindFunc1);
}

// and listen for future ones
global.controller.on("ZWave.register", this.bindFunc1);
Post Reply