Page 1 of 1
Sampling rate for blockly scripts
Posted: Monday 10 December 2018 17:59
by Adso76
Hi,
Is it possible to change sampling rate for script? I have a script (blockly) which detects whether a physical button is pressed and alternatively turns on and off the device. It works but you need to hold the button pressed for half a second to get a reaction, which is annoying.
When I wrote the same logic in external Python scripts, which detects the button and sends a signal via JSON to domoticz, the reaction is without any delay. Is there a solution?
Re: Sampling rate for blockly scripts
Posted: Monday 10 December 2018 18:11
by waaren
Adso76 wrote: ↑Monday 10 December 2018 17:59
Hi,
Is it possible to change sampling rate for script? I have a script (blockly) which detects whether a physical button is pressed and alternatively turns on and off the device. It works but you need to hold the button pressed for half a second to get a reaction, which is annoying.
When I wrote the same logic in external Python scripts, which detects the button and sends a signal via JSON to domoticz, the reaction is without any delay. Is there a solution?
What kind of communication is there between the button and domoticz ? RFLink, Zwave, MQTT, other ?
Re: Sampling rate for blockly scripts
Posted: Monday 10 December 2018 19:42
by Adso76
The communication is wire

I just connect one of the pins of PCF8574 with GND.
Re: Sampling rate for blockly scripts
Posted: Monday 10 December 2018 20:18
by SweetPants
Adso76 wrote: ↑Monday 10 December 2018 19:42
The communication is wire

I just connect one of the pins of PCF8574 with GND.
I assume you use a GPIO pin for that? Is there software de-bouncing involved of the GPIO pin? That could explain the delay
Re: Sampling rate for blockly scripts
Posted: Monday 10 December 2018 21:56
by Adso76
@SweetPants
So how you explain that external Python script, which detects the button and sends a signal via JSON to domoticz works ok (the reaction is without any delay). IMHO, the problem is somewhere within domoticz.
Re: Sampling rate for blockly scripts
Posted: Monday 10 December 2018 22:04
by SweetPants
Without knowing how the Python script looks like, i assume you read the GPIO pin directly without de-bouncing the input. Normally when you connect a switch to a GPIO port, you need to de-bounce the input from generating multiple state changes (search Google for that). Then there is a delay involved.
Re: Sampling rate for blockly scripts
Posted: Wednesday 12 December 2018 11:35
by Adso76
Code: Select all
PCF8574=0x20
b=smbus.SMBus(1)
b.write_byte(PCF8574, 0xff)
state = 0
pins = b.read_byte(PCF8574)
prev_pin = pins & 0x01
while True:
pins = b.read_byte(PCF8574)
pin = pins & 0x01
if pin == 0 and prev_pin == 1:
if state:
state = 0
httpresponse = urllib.urlopen("http://192.168.1.200:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=Off")
time.sleep(0.3)
httpresponse = urllib.urlopen("http://192.168.1.200:8080/json.htm?type=command¶m=switchlight&idx=8&switchcmd=Off")
else:
state = 1
httpresponse = urllib.urlopen("http://192.168.1.200:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=On")
time.sleep(0.3)
httpresponse = urllib.urlopen("http://192.168.1.200:8080/json.htm&type=command¶m=switchlight&idx=8&switchcmd=Off")
And blockly looks like this:
