MLScript to Reboot DirecTV DVR's

Repository of MainLobby Server plug-ins and updates not available in the current installation.
MurrayW
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1198
Joined: Sun Mar 07, 2004 1:05 pm
Location: Austin, TX
Contact:

MLScript to Reboot DirecTV DVR's

Postby MurrayW » Mon Feb 07, 2011 6:48 pm

Dave or any other script expert, can you take a look at this script and see if it will do what I want it to do? My script name is RebootDVR1 and I plan to schedule it to run in the middle of the night a few times a week. What I want to do is to check to see if the DVR is recording. If not, send the reboot command immediately. If it is recording, wait an hour then call the script again. After 5 attempts if the DVR is still recording, end the reboot attempts and just wait until the next scheduled reboot time.

One of the questions that I had was if it was possible to put a pause into the script. Before I read the isrecording variable I would like to send the command that refreshes this variable. So ideally, I would want to refresh the variable, wait 1 minute to make sure the variable has been refreshed then read it to see whether to reboot now or wait later.

Code: Select all

Sub Reboot1

   Dim IsRecording
   Dim RebootAttempts
    Dim tmpStr

    IsRecording = MLServer.GetVariable("directv_1_isrecording")
   RebootAttempts = MLServer.GetVariable("directv_1_rebootattempts")
   
   If IsRecording = 0 then
       MLServer.SetVariable "directv_1_RebootAttempts", 0
      tmpStr = "MLServeCmd.MLDirecTVIP|DTV1~Reboot"
      'Send the reboot command
      MLServer.cmdReceive tmpStr
    Else
      RebootAttempts = RebootAttempts + 1
      
      If RebootAttempts < 6 then
         'Set a timer to call the script in another hour since the DVR is currently recording a program
         MLServeCmd.MLTimer|SetTimer~1~NoRepeat~1~hours~MLScript|RebootDVR1~on
      Else
         MLServer.SetVariable "directv_1_RebootAttempts", 0
      End If
   End If
       
End Sub

Call Reboot1

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 12:19 pm
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby bigDvette » Tue Feb 08, 2011 9:49 am

You could, but you will also lock up the scripting engine for 1 minute while you wait. I don't think this would affect MLServer executing commands, but Dave can tell you that.

Another solution that will definitely not pause any processing would be to define a timer in ML so something like.

Step 1:
create a ML Macro that is fired on a schedule

1) sends the refresh command
2) enables whatever timer you have configured for step 2 below

Step 2:
create a timer that

waits 1 minute after it is enabled (non repeating) and fires macro in step 3

Step 3:
Check variable and use MLConditional to say

If (recording) then schedule a new check in 1 hour
Else
Reboot

Actually if you use this approach you won't even need MLScript will you?

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby CinemarDave » Tue Feb 08, 2011 11:01 am

Inserting the delay into the script would stop MLServer dead in its tracks for one minute. So that would not work well.

You could also do things with a macro that gets called every hour

If {{currenthour}} = 3 and {{recording}} = 0 and {{NeedsReboot}} = 0 then reboot

Macro|
MLConditional|IsEqual##{{currenthour}}{{recording}}##30##Macro|RebootDVR!SetVariable|NeedsReboot~0##SetVariable|NeedsReboot~1!!
MLConditional|IsEqual##{{currenthour}}{{recording}}{{NeedsReboot}}##401##Macro|RebootDVR!SetVariable|NeedsReboot~0##!!
MLConditional|IsEqual##{{currenthour}}{{recording}}{{NeedsReboot}}##501##Macro|RebootDVR!SetVariable|NeedsReboot~0##

MurrayW
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1198
Joined: Sun Mar 07, 2004 1:05 pm
Location: Austin, TX
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby MurrayW » Tue Feb 08, 2011 11:26 am

bigDvette wrote:You could, but you will also lock up the scripting engine for 1 minute while you wait. I don't think this would affect MLServer executing commands, but Dave can tell you that.

Another solution that will definitely not pause any processing would be to define a timer in ML so something like.

Step 1:
create a ML Macro that is fired on a schedule

1) sends the refresh command
2) enables whatever timer you have configured for step 2 below

Step 2:
create a timer that

waits 1 minute after it is enabled (non repeating) and fires macro in step 3

Step 3:
Check variable and use MLConditional to say

If (recording) then schedule a new check in 1 hour
Else
Reboot

Actually if you use this approach you won't even need MLScript will you?
I had thought about creating the refresh event as a separate step as you mentioned and it is true I probably don't need a script for this, but I want to try to start using them just because it is easier for me to see what is going on.

thanks,
Murray

MurrayW
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1198
Joined: Sun Mar 07, 2004 1:05 pm
Location: Austin, TX
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby MurrayW » Tue Feb 08, 2011 11:38 am

CinemarDave wrote:Inserting the delay into the script would stop MLServer dead in its tracks for one minute. So that would not work well.

You could also do things with a macro that gets called every hour

If {{currenthour}} = 3 and {{recording}} = 0 and {{NeedsReboot}} = 0 then reboot

Macro|
MLConditional|IsEqual##{{currenthour}}{{recording}}##30##Macro|RebootDVR!SetVariable|NeedsReboot~0##SetVariable|NeedsReboot~1!!
MLConditional|IsEqual##{{currenthour}}{{recording}}{{NeedsReboot}}##401##Macro|RebootDVR!SetVariable|NeedsReboot~0##!!
MLConditional|IsEqual##{{currenthour}}{{recording}}{{NeedsReboot}}##501##Macro|RebootDVR!SetVariable|NeedsReboot~0##
OK, so it is 2-0 against using a script for this, so I will abandon that effort. Dave, in general, when do you recommend using a script vs. doing everything in macros?

thanks,
Murray

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby CinemarDave » Tue Feb 08, 2011 11:42 am

No I love script. You should use script whenever possible because of the power at your command. You just needed a delay that would stop MLServer. So I had a different idea.

MurrayW
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1198
Joined: Sun Mar 07, 2004 1:05 pm
Location: Austin, TX
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby MurrayW » Tue Feb 08, 2011 11:55 am

CinemarDave wrote:No I love script. You should use script whenever possible because of the power at your command. You just needed a delay that would stop MLServer. So I had a different idea.
OK. Then I should be able to take some of bigDvette's suggestions and work them into my script without putting a delay in my script. I can have the GetChannel event as a separate macro that runs a minute before the script then use the my script to determine if I should reboot at that time or not. I could even set a different timer to run the GetChannel event at 59 minutes if the DVR is recording and I need to wait another hour to check for reboot.

I guess the ideal situation is to determine why I can't use the polling feature from within MLDirecTVIP without running into the queuing issue that I have on my DVR's so I don't have to send the GetChannel commands prior to running the script.

thanks,
Murray

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby CinemarDave » Tue Feb 08, 2011 12:05 pm

Those commnads are queuing up because one or more DVRs are taking a long time to respond to the web request. When things get queued what is the next command in the queue? The plugin is waiting for the previous DVR to respond. Is it always the same DVR that it is waiting on?

MurrayW
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1198
Joined: Sun Mar 07, 2004 1:05 pm
Location: Austin, TX
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby MurrayW » Tue Feb 08, 2011 1:07 pm

CinemarDave wrote:Those commnads are queuing up because one or more DVRs are taking a long time to respond to the web request. When things get queued what is the next command in the queue? The plugin is waiting for the previous DVR to respond. Is it always the same DVR that it is waiting on?
I'll do some troubleshooting tonight. I am looking at the log now and it looks like it takes about 3 seconds on average for all 5 DVR's to issue and respond to the GetChannel command after it queues up. Is that typical? I don't see one taking any longer than the other. If I am trying to control DVR1, would it have to wait until the queue for DVR2 through DVR5 processes to respond to the remote key press sent to DVR1?

Here's the log with just the polling commands. I'll throw in the remote control commands tonight when I am in front of the TV.

thanks,
Murray
You do not have the required permissions to view the files attached to this post.

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby CinemarDave » Tue Feb 08, 2011 1:34 pm

Timings sound normal from the tests I have run on user systems. The processors in the boxes are not that powerful. With the current version all commands are put into the queue. If you were stuck in a polling interval your commands would be waiting at the end of the queue.

I just posted version 3.99.86 and you'll notice that there are now two command queues. A polling queue and a user command queue. Commands in the user command queue will always have higher priority than those in the polling queue. See if this works better for you.

MurrayW
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1198
Joined: Sun Mar 07, 2004 1:05 pm
Location: Austin, TX
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby MurrayW » Tue Feb 08, 2011 1:45 pm

CinemarDave wrote:Timings sound normal from the tests I have run on user systems. The processors in the boxes are not that powerful. With the current version all commands are put into the queue. If you were stuck in a polling interval your commands would be waiting at the end of the queue.

I just posted version 3.99.86 and you'll notice that there are now two command queues. A polling queue and a user command queue. Commands in the user command queue will always have higher priority than those in the polling queue. See if this works better for you.
Different polling and command queues sound like a great idea. I'll try it out tonight!

thanks,
Murray

MurrayW
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1198
Joined: Sun Mar 07, 2004 1:05 pm
Location: Austin, TX
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby MurrayW » Wed Feb 09, 2011 11:56 am

CinemarDave wrote:Timings sound normal from the tests I have run on user systems. The processors in the boxes are not that powerful. With the current version all commands are put into the queue. If you were stuck in a polling interval your commands would be waiting at the end of the queue.

I just posted version 3.99.86 and you'll notice that there are now two command queues. A polling queue and a user command queue. Commands in the user command queue will always have higher priority than those in the polling queue. See if this works better for you.
Dave, I tried the new version and saw similar problems. I attached 45 minutes of the log. Sometimes during the delays there were get channel requests being sent but other times there weren't. Also a few times there was a problem connecting to a DVR but not all the time. I tried it with my oldest DVR (DVR2) and my newest one (DVR5) with a faster processor and got similar delays. Most of the time (but not all) the queue buildup happened with 10 seconds before the top of the minute. Here is the data from the logs for part of the time that multiple key presses were queued up that resulted in delays.

    DVR2--> Queue: 9:43:51; Processed: 9:44:08
    DVR2--> Queue: 9:46:57; Processed: 9:47:07; Can't connect to DVR2
    DVR2--> Queue: 9:48:08; Processed: 9:48:17 GetChannel event during this time
    DVR2--> Queue: 10:01:54; Processed: 10:02:07
    DVR5--> Queue: 10:08:53; Processed: 10:09:07 GetChannel event during this time
    DVR5--> Queue: 10:11:22; Processed: 10:11:29
    DVR5--> Queue: 10:02:53; Processed: 10:13:11

When I turn off polling I don't see any of these queuing problems.

As Erik suggested in another post I will try powering off my DVR's and leaving them off for several minutes and retest tonight, but I don't hold out a lot of hope that is going to work.
You do not have the required permissions to view the files attached to this post.

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Re: MLScript to Reboot DirecTV DVR's

Postby CinemarDave » Wed Feb 09, 2011 1:22 pm

All the traffic in the log looks normal. You had one issue at 2/8/2011 9:49:27 PM where DVD4 timed out trying to satisfy a request. No errors.


Return to “MLServer Plug-Ins”

Who is online

Users browsing this forum: No registered users and 1 guest