-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Togle mode for relay #21
Comments
"toggle" for me have different meaning from what you described. It is (current_state XOR 1) i.e. if it is OFF switch it ON - if it is ON switch it OFF. Back to your question:
There can be arguments for either solution. Why two requests bother you? On-OFF is easily implemented using JavaScript setTimeout() function. function relaySet(socket, state) {
socket.send(
JSON.stringify(
{
URL: '/relay',
Method: 'POST',
Data: {
Relay: state
}
}
)
);
}
function relayOnOff(socket, delay) {
relaySet(socket, 1);
setTimeout(
function () {
relaySet(socket, 0);
},
delay
);
}
var socket = new WebSocket('ws://192.168.4.1/events');
relayOnOff(socket, 500); |
I don't use browser, but Android application to open my automated door. It happens that in a slow mobile connection (GPRS) the delay b/w ON and OFF requests is more than 3 sec, even 5 sometimes. This reflects on a different mode for my door - it switches to so called pedestrian mode where the door is not fully open. And let we simplify the case - currently you code has setRelay(1)/setRelay(0) to ON/OFF relay. |
I prefer to make relay state signed integer so if the state:
What about the case with double requests?
What should I do?
|
The short answer is - switch relay OFF 500ms after first request |
@bobybc your proposal is done. Now you can set the relay state as follows:
Due to some technical difficulties signed integer approach did not worked. Hope your door will work as expected ;-) |
10x a lot Peter |
Hi,
does it possible to have 3-th state for relay "toggle" , which should switch it "on" and after a while switch back to "off".
The goal is to have "button" like behavior with only one HTTP request .
Now it is possible with two separated requests.
10x
Boby
The text was updated successfully, but these errors were encountered: