Sampling rate for blockly scripts

Moderator: leecollings

Post Reply
Adso76
Posts: 20
Joined: Tuesday 28 August 2018 21:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Sampling rate for blockly scripts

Post 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?
Domoticz Version: 4.9895 running on Raspberry Pi B 3+ (Raspbian). PCF8574 as input and output.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sampling rate for blockly scripts

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Adso76
Posts: 20
Joined: Tuesday 28 August 2018 21:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sampling rate for blockly scripts

Post by Adso76 »

The communication is wire :) I just connect one of the pins of PCF8574 with GND.
Domoticz Version: 4.9895 running on Raspberry Pi B 3+ (Raspbian). PCF8574 as input and output.
SweetPants

Re: Sampling rate for blockly scripts

Post 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
Adso76
Posts: 20
Joined: Tuesday 28 August 2018 21:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sampling rate for blockly scripts

Post 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.
Domoticz Version: 4.9895 running on Raspberry Pi B 3+ (Raspbian). PCF8574 as input and output.
SweetPants

Re: Sampling rate for blockly scripts

Post 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.
Adso76
Posts: 20
Joined: Tuesday 28 August 2018 21:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sampling rate for blockly scripts

Post 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&param=switchlight&idx=20&switchcmd=Off")
			time.sleep(0.3)
			httpresponse = urllib.urlopen("http://192.168.1.200:8080/json.htm?type=command&param=switchlight&idx=8&switchcmd=Off")
		else:
			state = 1
			httpresponse = urllib.urlopen("http://192.168.1.200:8080/json.htm?type=command&param=switchlight&idx=20&switchcmd=On")
			time.sleep(0.3)
			httpresponse = urllib.urlopen("http://192.168.1.200:8080/json.htm&type=command&param=switchlight&idx=8&switchcmd=Off")

And blockly looks like this:

Image
Domoticz Version: 4.9895 running on Raspberry Pi B 3+ (Raspbian). PCF8574 as input and output.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest