Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Enable/Disable buttons at certain times of day

  1. #1
    Join Date
    Mar 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Enable/Disable buttons at certain times of day

    Folks,

    I have an unusual request.

    I am trying to figure out how I can disable then enable form buttons automatically using some kind of clock depending on the time of day.

    To let you understand why I need this, I am running a pan/tilt webcam and I do not want the remote viewers to "control" the cam at certain times of the day/night pointing it into direct sunlight etc ruining my cam. I am currently having to manually change the button script which I forget to do sometimes. So can this be done automatically using some kind of clock?

    I have "UP", "DOWN", "CENTER", "LEFT", "RIGHT" buttons on a file called index.html as seen on the webcam page CLICK HERE

    So for example at 06:00am, the clock would disable the "UP" button then at midday the clock would enable it again automatically using some kind of clock script.

    Any ideas would be great.

    thanks peeps.

    -NairB
    Last edited by NairB; 05-31-2008 at 05:10 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    As it's your camera at risk here, this would probably best be handled on the server side, like if you have PHP or asp available. That way you could even serve different pages at different times. You would want there to be no code on the page at all for moving the camera into danger at those times when it could be at risk. Because, even if a button is disabled in javascript, a clever person could look at the source code and activate the function anyway.

    An even better solution would be to not have the camera situated like that. This is because, no matter what you do, a user may be able to take control of the camera via a cached page.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi John, thanks for your reply.

    I agree with your concern and I too would like to see this page protected via php but unfortunately it is written by Roborealm and I don't have control over this.

    I will post this on Roborealm's forum requesting better security with the possibility of a php version of the index file.

    For the time being, to stop me manually changing the buttons, a little java script of some kind was what I was looking for to maybe add the word "disabled" then remove it at a certain time as seen from this line within the code.....

    <input disabled type="button" value="UP" onclick="setVariable('move=1')">

    Any takers

    Thanks again,

    NairB

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Think about this a little more. What happens when a user leaves the page? I got the impression that the camera remains where it was left. If so, even with this disabled at times, the camera could inadvertently get left at an angle that would later burn it out.

    I'm also curious (but this isn't too important here), what happens when two users try to control the camera at once.

    Have you lost any cameras yet?

    Getting back to using javascript for this, there is no reliable way, unless we can at least get the time from the server.

    A very unreliable method that depends upon well intentioned users with accurate clocks, and upon a camera that cannot be left in a bad spot as mentioned above would be:

    HTML Code:
    <input id="up_button" type="button" value="UP" onclick="setVariable('move=1')">
    <script type="text/javascript" defer="defer">
    <!-- 
    var UTC_hours = new Date().getUTCHours();
    if(UTC_hours > 5 && UTC_hours < 17)
    document.getElementById('up_button').disabled = true;
    // -->
    </script>
    That will kill the button for a twelve hour period, from 5am to 5pm GMT. You may change the range to suit, but remember - at different times of the year, things will be different - so make the range as broad as possible. UTC is the same as GMT, both skip changes in DST, and for user's with accurate clocks, it will be the same value regardless of their time zone. You must determine the difference between UTC time and your locale, and add/subtract the difference between your zone and UTC here (IMPORTANT):

    Code:
    var UTC_hours = new Date().getUTCHours() - 5;
    with full awareness that if DST is used in your area, that will throw things off a little at those times, so the range should be padded by an extra hour in one direction or the other. Also sunrise and sunset varies, you will want to cover all times in the year that the camera could possibly be in jeopardy.

    Maybe you should just rent a room on the other side of the street.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    Think about this a little more. What happens when a user leaves the page? I got the impression that the camera remains where it was left. If so, even with this disabled at times, the camera could inadvertently get left at an angle that would later burn it out.
    Many, many thanks John for the code but let me answer your questions. The camera server is on a my PC at home and I am often away, hence I cannot always "manually" change the settings. However, I have my notebook with me and like everyone else, I remotely check the cam.

    Yes, the camera will remain where it is by the remote user but No, the camera will not burn out because remotely all I need to do is click the remaining enabled buttons before the sun comes up, moving the cam out of danger. The code will disable the "up" and "center" buttons only automatically, so no one, including me can move the cam back into danger. All I need to do is click the "down" button to ensure the camera will not be stuck in an upwards position looking at the sun to burn it out. It will stay in this "down" postion until the code enables the "up" and "center" buttons again when the sun is out of the cams path and users can have full control of the cam again. Of course, this depends on me checking last thing in the evening the cam is out of danger, which I do anyway to make sure the server hasn't crashed.

    I need the code because I am often not at home to "manually" change the script file on the server but now I have the code, all I need to do is click the remaining enabled "down" button remotely to protect the cam and no need to access the actual script file on the server......can you see what I mean now John.

    Quote Originally Posted by jscheuer1 View Post
    I'm also curious (but this isn't too important here), what happens when two users try to control the camera at once.
    Have you lost any cameras yet?
    Well to answer this simply, both users have to fight it out who controls the cam lol....no preference I'm afraid and No, I haven't lost any cams but I do know that the CCD sensors will degrade if facing direct sunlight all the time.

    Hope that answers a few questions John.

    ahahahaha do you know any code that can get me a flat across the road, if you do, I will have that instead LMAO!!!
    I will try the code when I get home to see if it works and let you know how I get on

    Again many many thanks John for your help and I hope you understand what I am trying to do now.

    -NairB
    Last edited by NairB; 05-31-2008 at 10:07 PM.

  6. #6
    Join Date
    Mar 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    John,

    I tried the code and it hasn't disabled the button....have I put the code in the correct position on the page?

    -NairB

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The code looks good on your page, and I'm not getting any script errors. I'm not sure what time zone you are in though. The value of -5 here:

    Code:
    var UTC_hours = new Date().getUTCHours() - 5;
    would approximately be good for the East coast of the USA (where I am - Eastern Standard Time and Eastern Daylight Savings Time - depending upon the time of year). If you are in a different timezone (I think you probably are - it's still a little light here - looks completely dark on your page), you would need to use the offset for your timezone. What timezone ARE you in? I just tested the code, works here. I'll check again when it's light (the only time the UP button should be disabled) to see if it is working or not.

    Also, since you only asked about the UP button, I only wrote for the UP button. The CENTER button would be unaffected, unless it were given its own unique id and included in the script code.

    I basically understood what you were trying to do from the very start. Why was never that crucial to me in this case, but I got most of that too.

    I would caution you again though, this will only be good for users with accurate settings for their computer's clock. And only if all of the math for your timezone is worked out correctly. And only if the user doesn't decide to mess with your camera. If they decide that, and they know anything about time and javascript, your camera could well be toast anyway.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Mar 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    Im in the UK, so my GMT time zone is '0'. I removed the -5 from the code presuming it defaults to 0....still no change.

    Hmmm, I also tried it with -0 in case it needed a value....no joy.

    I then tried the code on a blank html page with no other code present on my notebook PC and it still wont work, the button is still "clickable"...strange. Is it not reading my clock on my PC perhaps??

    NairB

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, right now UTC_hours is 3, so the UP button should still be enabled. Wait two hours. Also, as I mentioned before, the page can be cached, so make sure you are looking at it with the most recent code before judging whether or not it works.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Mar 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    John,

    I removed the -5 thinking that because I am GMT zero, it should work. Im unsure now what my code should read.

    Code:
    <input id="up_button" type="button" value="UP" onclick="setVariable('move=1')">
    <script type="text/javascript" defer="defer">
    <!-- 
    var UTC_hours = new Date().getUTCHours();
    if(UTC_hours > 5 && UTC_hours < 17)
    document.getElementById('up_button').disabled = true;
    // -->
    </script>
    Should I leave it without the -5?

    It is now gone 5am here in UK, should my button be disabled now??

    NairB

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •