about virtual device problem

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
alex_tpc
Posts: 11
Joined: 21 Apr 2022 12:40

about virtual device problem

Post by alex_tpc »

I want to use a virtual device to execute a python code, but when the python code includes the request.get() function running in the virtual device, it will break down the website system port(8083). The z-way-server got 100% loading and the web system will keep loading and cannot to use. However, I run it(python code) in the putty and it works well. How could I run it on a virtual device?
Screenshot 2022-04-21 181209.png
Screenshot 2022-04-21 181209.png (41.26 KiB) Viewed 2055 times
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

Re: about virtual device problem

Post by PoltoS »

Am I right that on CodeDevice click you are running a Python script that is making a request to the Z-Way server again?

The server web handling is synchronous. You press a button, webserver handles it and execute CodeDevice that does a shell execution of python that tries a sync http request to the same server and will wait until the command is executed, but it can't since the previous is still in execution until your Python ends, which is waiting for the http to finalize. So, you are in a dead loop.

But why not to execute everything inside the Z-Way JavaScript engine without python?
seattleneil
Posts: 172
Joined: 02 Mar 2020 22:41

Re: about virtual device problem

Post by seattleneil »

>> But why not to execute everything inside the Z-Way JavaScript engine without python?

Likely explanation... incomplete documentation on how to use the Virtual Device module. Please consider updating the CodeDevice m_descr with links to a sticky post on this forum (where the forum post contains simple and more complicated examples, such as turning a Z-Wave switch on and off, setting a level of a code device, reading the level of an HTTP device and taking an action based on the level, setting a Z-Wave configuration parameter). My sense is that many Z-Way users do not fully understand what you mean by "This app allows creating a new virtual device based on JavaScript code." In my opinion, if the Z-Way team provided more examples, users would appreciate the extensibility provided by the CodeDevice, EasyScripting and HTTPDevice automation modules (and @alex_tpc would have known to write the virtual device action as: controller.devices.get('Code_Device_sensorMultlevel_54').set('metrics:level',50) instead of calling a python script to run an Z-Way HTTP request).
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

Re: about virtual device problem

Post by PoltoS »

Well noted, more docs is never bad.

But may be @alex_pc can help us to understand the initial idea so we understand which example is missing.

Here there are a few examples:
https://help.z-wave.me/en/knowledge_bas ... ation-apps
alex_tpc
Posts: 11
Joined: 21 Apr 2022 12:40

Re: about virtual device problem

Post by alex_tpc »

@PoltoS , I have another task in python so I cannot do it in the js engine. Can we change from python to shell script and shell script to call python? Can it avoid the deadloop problem?
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

Re: about virtual device problem

Post by PoltoS »

The dead loop happens when you call synchronouslynsomehing that is calling Z-Way HTTP API and eaits for it.

So either do a sync execution (with &), so that Z-Way can end the system call and proceed with the new HTTP API request from tour script.

Does not matter python or ahell
alex_tpc
Posts: 11
Joined: 21 Apr 2022 12:40

Re: about virtual device problem

Post by alex_tpc »

Thanks, it works well.
Post Reply