infrafast / piwebpool

The first full open source Raspberry PI PHP web-based application that automates the control of swimming pool
https://infrafast.github.io/piwebpool/
3 stars 1 forks source link

bounce material event #26

Closed infrafast closed 7 years ago

infrafast commented 7 years ago

when a switch change state, the state is fired to all listeners which could cause some infinite loop (example: with domoticz, when virtual switch is updated, it all the function "change state" which then fire the event etc...) as a consequence, we only change the state (and hence fire event) if the requested state differs from the current state. This method works, however we observe some "bounce" as the command is still executed a few time s(about 4) in a second .... see below logs

[2016-09-12 15:17:11][SWITCH traitement2][On] [2016-09-12 15:17:11][SWITCH traitement2][On] [2016-09-12 15:17:11][SWITCH traitement2][On] [2016-09-12 15:17:11][SWITCH traitement2][On] [2016-09-12 15:17:15][ACTIONS PERIODIQUES OK][{Periode:14h, Temperature:above28, Filtration:MARCHE}{|main:7.3ph, 698mV, 30.1°C |custom:R.A.S.}] [2016-09-12 16:17:10][SWITCH traitement2][Off] [2016-09-12 16:17:10][SWITCH traitement2][Off] [2016-09-12 16:17:11][SWITCH traitement2][Off] [2016-09-12 16:17:11][SWITCH traitement2][Off]

infrafast commented 7 years ago

fixed by adding sleep

function setPinState($pin,$state){ global $materials, $options, $pins; sleep(1); if ($state!=getPin($pin)){