I'm working on a pet treat dispenser that will enable someone to click a web submit button and activate the dispenser for one cycle. Ideally, I'd like the submit button to be disabled globally to the web (so my pets can't get more than one treat per 15 minutes) along with a countdown timer until the button is again enabled. I've gotten everything sorted out and ready to go except for a button that will do what I want it to.
Right now I have a web submit button that activates the feeder and resets, but can't figure out how to disable it with delay and display contdown either on the button or back to the webpage. And, I'm not sure exactly how this will need to be done other than it will probably need done with ajax/javascript or perhaps boolean logic. I don't think adding a 15 minute delay would be a good idea with an ethernet connection, but maybe I'm wrong. I'm fairly new to all of this, so any help you can give would be awesome.
To summarize, what I'd like is:
A web submit button that disables globally for 15 minutes after click and displays a message and/or a countdown timer until it enables itself again.
billroy:
If you want a global lock, the easiest thing is to modify the Arduino web server code to ignore requests for 15 minutes after receiving one.
Also, it would be user-friendly to have the web client display how long ago the last treat was given or how long the user needs to wait before the next treat can be given.
if i understand you right -
you are using an arduino as webserver with hardware control ?
than it is realy easy-
// PSEUDO CODE!!!
// create a variable to trac state of sytem / define states (for readabilty)
const byte cbState_Undefined = 0;
const byte cbState_free = 1;
const byte cbState_locked = 2;
byte bState = cbState_free;
//create a variable to hold the remaining time (15min*60seconds = 900 --> word)
word wRemainingTime = 0;
//create a variable to hold a TimeStamp (unsined long)
unsigned long ulTimeStamp = 0;
/////////////////////////////
// function skeleton for getting state and remaining time info for web
void getInfo() {
if ( bState == cbState_locked ) {
// Display remaining time --> found in wRemainingTime as seconds.
} else {
// Display Button
}
}
// function that is triggerd if button on webside is pressed:
void pushButton() {
if ( bState == cbState_free ) {
// set system state to locked
bState = cbState_locked;
// start wait time with 900seconds (=15min)
wRemainingTime = 900;
//original feed thing goes in this sub function
feedPets();
}
}
//original feed thing goes in this sub function
void feedPets() {
// Your Feeding things...
}
//in your main loop:
if (millis()-ulTimeStamp >= 1000) {
ulTimeStamp = millis();
//do something every second:
if ( bState == cbState_locked ) {
if ( wRemainingTime > 0 ) {
wRemainingTime = wRemainingTime - 1;
} else {
// time is over - pets are allowed to get some thing..
bState = cbState_free;
}
}
}
hey - this is just a dirty hack free out of my mind -
i hope it helps to get a idea how to go for this.
if you want to see the count down counting on the webside - you need javascript!
the concept at this part would be to get the webside with the remaining time and a small javascript that counts down this time.
and if it is reaching 0 it just reloads the page.
i have set up a small example: Count Down - JSFiddle - Code Playground
have fun
sunny greetings stefan
I'm going to work on this over the next couple days and will post back with my updated code. Currently my button is using javascript and showing the countdown correctly, but a page refresh or another user accessing the page would see the "feed" button again and not the countdown. Just ignoring requests won't solve the problem with the button code. As such, I need to go a different route since it won't function like I want, so I'll give s-light's suggestion a try.