Comments (6)
"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 is need for additional parameter - delay after it will be switched OFF
- how the following situation should be handled:
- we have request for "ON-OFF"
- before delay for switching OFF is expired we receive another "ON-OFF" request
- should we switch it OFF after the delay of first request is expired or should we wait for the second?!?
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);
from esp8266.
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.
That's why i need to have ON-OFF with one request...
And let we simplify the case - currently you code has setRelay(1)/setRelay(0) to ON/OFF relay.
Can we just put delay interval (in ms) as parameter to this function?
Server side it can be implemented like : if the value is greater than 1, just switch ON, wait time in ms described in the value and then switch OFF.
What do you think on that?
from esp8266.
I prefer to make relay state signed integer so if the state:
- is equal to 0 - switch OFF
- is greater than 0 - switch ON
- is lower than 0 - switch ON wait abs(state) ms then switch OFF
What about the case with double requests?
- receive request for ON-OFF after 500ms
- switch relay ON
- 200ms later second request is received for new 500ms
What should I do?
- switch relay OFF 500ms after first request
- switch relay OFF 500ms after second request i.e. 700ms after first request
from esp8266.
The short answer is - switch relay OFF 500ms after first request
But I think that it will be good if it is synchronized i.e. until first request is not completed, do not execute new one
from esp8266.
@bobybc your proposal is done. Now you can set the relay state as follows:
- If [state] is 0 relay is switched OFF.
- If [state] is 1 relay is switched ON.
- If [state] is greater than 1 relay is switched ON for [state]ms and then switched OFF. During this interval all other commands are ignored.
Due to some technical difficulties signed integer approach did not worked.
Hope your door will work as expected ;-)
from esp8266.
10x a lot Peter
Cheers :)
from esp8266.
Related Issues (20)
- WEBCLIENT - no request freeing from list HOT 1
- IoT Firmware Websocket "freezes" on frame segmentation at TCP level HOT 7
- Enhancement: Upgrade SDK to 1.5.1 (16.1.2016) (IoT Firmware) HOT 2
- IoT Firmware: Default config settings after complete flashing HOT 6
- How to adapte 8Mbit flash with iot_firmware project? HOT 1
- What's the purpose of bringing out SD_CLK to SD_CMD? (EVB board) HOT 1
- memcpy in fnc jsonparse_object_str copies 1 byte to much HOT 1
- MQTT example must be updated with changes to PubSubClient HOT 1
- WebClient.webclient_recv - Finishing chunked message hotfix
- Webserver does not respond after reconnect
- Tho functions move into flash instead of RAM HOT 4
- after commit SDK 2.0.0 IoT Firmware won't to compile HOT 8
- RX and TX pin are messed up HOT 1
- it is possible to add webserver/websocket port config in web app HOT 5
- WPA2-PEAP Support HOT 1
- Status/event Messages: field "device" to fill with host name HOT 1
- Compiling Issue HOT 1
- Conection betwen ESPs
- Compile with SDK 2.1.0
- HTML page it's not show in web Server
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp8266.