about virtual device problem
about virtual device problem
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?
Re: about virtual device problem
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?
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?
-
- Posts: 192
- Joined: 02 Mar 2020 22:41
Re: about virtual device problem
>> 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).
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).
Re: about virtual device problem
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
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
Re: about virtual device problem
@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?
Re: about virtual device problem
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
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
Re: about virtual device problem
Thanks, it works well.