Author Topic: [Suggestion] WifiRemote connection check command  (Read 5451 times)

0 Members and 1 Guest are viewing this topic.

bodiroga

  • $upporter
  • Jr. Member
  • *****
  • Posts: 48
  • Karma: 1
    • View Profile
[Suggestion] WifiRemote connection check command
« on: March 25, 2012, 01:18:28 AM »
Hi James!

I think that I need your help because I don't know how can I achieve what I want  :biglaugh

My idea is to add some checking actions before sending some specific commands such as: play channel, play artist, play album, watch movie,... because all this actions won't do anything if my computer isn't turned on. You know that I have VC installed on my server and that I use it to control my MediaPortal installation on my HTPC, so what I request is to add something like "check if HTPC is awake" command using the authentication request message included in WifiRemote. The idea is to build something like this:

Command: "play artist X"

LCB:

CheckWifiRemoteStatus
If LastActionSuccess
   then MpWifi.RequestMusicBySQL  strArtist like '%| {1} |%' order by random() limit 100
   else WOL xx-xx-xx-xx-xx
         VC.Pause 4000    //Time until HTPC wakes up
         MpWifi.RequestMusicBySQL  strArtist like '%| {1} |%' order by random() limit 100

As you can see I just need a command that checks if WifiRemote responds to our "are you there?" question (like a ping command that answer yes if the client is reached).

What do you think about it? Is it possible to add this simple "question" command to the current WifiRemote plugin?

Many many many thanks as always for your help and looking forward to hearing from you, keep up with the good job.

Best regards ;)

Aitor

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: [Suggestion] WifiRemote connection check command
« Reply #1 on: March 25, 2012, 05:41:35 AM »
Hi James!

I think that I need your help because I don't know how can I achieve what I want  :biglaugh

My idea is to add some checking actions before sending some specific commands such as: play channel, play artist, play album, watch movie,... because all this actions won't do anything if my computer isn't turned on. You know that I have VC installed on my server and that I use it to control my MediaPortal installation on my HTPC, so what I request is to add something like "check if HTPC is awake" command using the authentication request message included in WifiRemote. The idea is to build something like this:

Command: "play artist X"

LCB:

CheckWifiRemoteStatus
If LastActionSuccess
   then MpWifi.RequestMusicBySQL  strArtist like '%| {1} |%' order by random() limit 100
   else WOL xx-xx-xx-xx-xx
         VC.Pause 4000    //Time until HTPC wakes up
         MpWifi.RequestMusicBySQL  strArtist like '%| {1} |%' order by random() limit 100

As you can see I just need a command that checks if WifiRemote responds to our "are you there?" question (like a ping command that answer yes if the client is reached).

What do you think about it? Is it possible to add this simple "question" command to the current WifiRemote plugin?

Many many many thanks as always for your help and looking forward to hearing from you, keep up with the good job.

Best regards ;)

Aitor
Hi bodiroga, you can insert the follow commad entries. (no guarantee that it works, but I think it's a startpoint to do this)  ;)

1. WOL: This wake up your HTPC (if your HTPC is run, it does nothing), and wait 4 seconds.
If the HTPC in network with the correct "Mac adress" available, OSD shows: "wol Packets sent to: Mac adress XXXXXXXX" and "connect to HTPC is success" otherwise the OSD shows: "connect to HTPC is failed"

2. connect to MP and wait 2 seconds

3 insert as next in the second logic block the play song commands "MpWifi.RequestMusicBySQL strArtist like '%| {1} |%' order by random() limit 100" (in the fields of "THEN")

I don't use MP on my HTPC, so I have the "connect to MP" not tested, but the WOL works fine.

I hope it helps
Kalle

PS: I think your HTPC sleep in "S3 mode", and MP is always run, otherwise you must insert a "start MP" command
« Last Edit: March 25, 2012, 11:07:42 AM by Kalle »
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: [Suggestion] WifiRemote connection check command
« Reply #2 on: March 25, 2012, 09:39:41 AM »
I think you can make use of the events generated such as

MPWF.TryConnect
and
MPWIFI.Reconnected

bodiroga

  • $upporter
  • Jr. Member
  • *****
  • Posts: 48
  • Karma: 1
    • View Profile
Re: [Suggestion] WifiRemote connection check command
« Reply #3 on: March 25, 2012, 07:45:27 PM »
Hi guys!

Many thanks to both for your help, but I think that your suggestions are not going to work :(

@Kalle

Yeah, you are right, that is going to work, but... don't you think that waiting 5-6 seconds everytime to start playing a song or tunning a channel is a little bit too much when the HTPC is already waken up? That's why I request a fast "connection check command", because sending a WOL packet everytime is easy to implement but a very ugly and slow workaround. Do you see what I mean?

@jitterjames

Thanks for your tip James, but I don't know how can I implement this in my "Play song X" command. What I need is a command that indicates quickly if WifiRemote is connected or not, and I don't know how can I force WifiRemote to generate those events.

I'm trying to do something with MpWifi.Connect but it is not working. When this command is sent, if I place my mouse over MpWifi.Connect message in History column I can see "info": "Connecting", "Already Connected" or "Could not connect to Server". I have tried the following command:

MpWifi.Connect
If    A==B     {lastResult}     already connected
      then  (code that plays the song)
      else   WOL xx-xx-xx-xx-xx
              VC.Pause 5000
              (code that plays the song)

But it fails because MpWifi.Connect doesn't parse the "info" sentence to {lastResult} :(  James, is it any way to play with the answer of MpWifi.Connect and make conditional sentences with the info that it sends? That would solve all my problems and it seems that we already receive that information, I just need you make it a variable ;)

Many thanks again for all and I hope that you have understood better what I am looking for.

Best regards,

Aitor

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: [Suggestion] WifiRemote connection check command
« Reply #4 on: March 25, 2012, 08:25:15 PM »
the tryconnect event will automatically fire any time that you try to send a command to mediaportal if you are not connected (i.e. computer is sleeping).  It seems like exactly what you want... when that event fires, it means that there is no connection, so you should wake the machine and let the user know that it was sleeping.

anyway, if you still want to use the connect action that's fine.  I can probably modify the plugin easily enough to put the results into {lastResult} instead of just showing it as info in the history window.  I will take a look at it tomorrow since I don't really remember it too clearly.  But can't you use an IF block with "LastActionSuccess".  If you computer is asleep then the connect action should fail (shows orange in the history window) so LastActionSuccess would be false.

One thing that you should keep in mind is that the mpwifi plugin uses asynchronous communication so if we send a command or request, we do not wait for a response, we just shoot commands into the void and then it shoots stuff back when it feels like it.  So you may run into some difficulty when your machine has just fallen asleep.  It might take a while for it to figure out that it is not connected any more.

bodiroga

  • $upporter
  • Jr. Member
  • *****
  • Posts: 48
  • Karma: 1
    • View Profile
Re: [Suggestion] WifiRemote connection check command
« Reply #5 on: March 25, 2012, 09:54:13 PM »
the tryconnect event will automatically fire any time that you try to send a command to mediaportal if you are not connected (i.e. computer is sleeping).  It seems like exactly what you want... when that event fires, it means that there is no connection, so you should wake the machine and let the user know that it was sleeping.

Ok, now I understand why you had recommended to use that command ;) The problem is that I think that my commands will become really complicated if I implement your approach. I have to configure VC in a way that:

1. The normal "play song x" command is sent.
2. ...

WTF! I have realized, as I'm typing, how can I make it work with your tryconnect event. It seems to be very easy! Just make the following commands to fire when tryconnect event is received:

WOL xx-xx-xx-xx-xx
VC.Pause 8000
VC.TellVox {LastSpoken}

No need to change any of my other commands, just add this event and it should work...

I'm testing it right now and it seems that VC freezes after the Pause time, perhaps because it is not yet connected to WifiRemote and enters in a weird loop. I will do more tests tomorrow as it's time to go to sleep now ;-)

Quote from: jitterjames
anyway, if you still want to use the connect action that's fine.  I can probably modify the plugin easily enough to put the results into {lastResult} instead of just showing it as info in the history window.  I will take a look at it tomorrow since I don't really remember it too clearly.  But can't you use an IF block with "LastActionSuccess".  If you computer is asleep then the connect action should fail (shows orange in the history window) so LastActionSuccess would be false.

Good idea, I also thought about it before you, but as I said in my previous post there is a third info answer: "Connecting", and this option breaks the LastActionSuccess if block :( "Connecting" is a successful action for VC, so perhaps the easiest way to solve the problem is simply consider it an unsuccessful action :D:D:D Anyway, in my opinion the best solution is to parse the info phare to {lastResult}, but as always it's up to you, you are the boss!!!

Quote from: jitterjames
One thing that you should keep in mind is that the mpwifi plugin uses asynchronous communication so if we send a command or request, we do not wait for a response, we just shoot commands into the void and then it shoots stuff back when it feels like it.  So you may run into some difficulty when your machine has just fallen asleep.  It might take a while for it to figure out that it is not connected any more.

Thanks for the tip James, we will see how does it work first. If the problem is only when the computer goes to sleep I can live with it, normally when you suspend the HTPC you don't want to use it immediately.

Best regards,

Aitor

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: [Suggestion] WifiRemote connection check command
« Reply #6 on: March 25, 2012, 10:42:17 PM »
VC.Pause 8000 is not a great idea since it basically locks the program execution for 8 seconds.

again, I urge you to use the events!

MPWIFI.Reconnected should fire if and only if (and more importantly WHEN) your computer successfully wakes up and VC is able to connect (assuming auto-connect is enabled in the mpwifi plugin settings).

if you want to automatically re-send your last command at this point you can try.

vc.tellvox  option 1

In theory we should actually be able to call:

VC.Option     1

... but this action seems to be hard-wired to the payload.  This is not ideal and I should take another look at the code for this.  This is one of the oldest actions so it is a bit out of date, but the need to modify it never came up before now.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: [Suggestion] WifiRemote connection check command
« Reply #7 on: March 27, 2012, 07:23:39 PM »
here's the plugin with the change to the connect command.  It should now store the results in {lastResult}

bodiroga

  • $upporter
  • Jr. Member
  • *****
  • Posts: 48
  • Karma: 1
    • View Profile
Re: [Suggestion] WifiRemote connection check command
« Reply #8 on: March 31, 2012, 01:10:56 AM »
here's the plugin with the change to the connect command.  It should now store the results in {lastResult}

Hi James!

Sorry for the late reply, but I couldn't try your .dll file until today.

I hope you are not going think that you have lost your time, but finally I'm using your event solution instead of the connect command as I realize that it is a more elegant solution. This is how it works:

- If the HTPC is sleep and I tell VC to play an artist, the TryConnect event will be fired.
- The TryConnect event sends a WOL packet and I use the VC.EnableGroup command to enable a group folder where the MPWIFI.Reconnected is placed (I do this to avoid launching VC.TellVox command when I turn on my computer manually)
- When the HTPC has resumed from standby, MPWIFI.Reconnected is fired.
- MPWIFI.Reconnected event will launch the following commands: MpWifi.Connect, VC.TellVox {LastSpoken} and VC.DisableGroup to disable the previously enabled group.

Ok, it seems that everything should work, right? No, it doesn't work :( I don't know why but I HAVE to do a full restart of VC when my computer is suspend, if I don't do it the VC.TellVox command will be send but WifiRemote won't receive it. Believe me, I have made lots of test and this is the only option (6am here :D). My current setup is: (EG is installed in my HTPC and in the Server)

HTPC is suspended (on.Suspend) -> HTPCs EG sends a network event to Servers EG and (after pausing EG for 4 seconds, really important) a .bat file is launched killing the VoxCommando.exe process and opening the program again. The rest of the procedure is the same. It seems that it is really important to restart VC after the HTPC is completely suspended, that's way I'm using the 4 sec. delay in Servers EG.

Does all this make any sense to you? It's like VC needs to completely close the connection with WifiRemote to be able to parse the VC.TellVox command again after waking up the HTPC :S

Oh, and I have found that if I use this option many times in a short period of time (suspend, tell VC to play an artist, suspend, tell VC, suspend...) VC force closes with the following error:

Quote
Consulte el final de este mensaje para obtener más detalles sobre cómo invocar a la depuración
Just-In-Time (JIT) en lugar de a este cuadro de diálogo.

************** Texto de la excepción **************
System.InvalidOperationException: No se puede realizar esta operación mientras el reconocedor está realizando el reconocimiento.
   en System.Speech.Recognition.RecognizerBase.InternalEmulateRecognizeAsync(String phrase, SpeechEmulationCompareFlags flag, Boolean useReco2, RecognizedWordUnit[] wordUnits)
   en System.Speech.Recognition.RecognizerBase.InternalEmulateRecognize(String phrase, SpeechEmulationCompareFlags flag, Boolean useReco2, RecognizedWordUnit[] wordUnits)
   en System.Speech.Recognition.RecognizerBase.EmulateRecognize(String inputText, CompareOptions compareOptions)
   en System.Speech.Recognition.SpeechRecognitionEngine.EmulateRecognize(String inputText, CompareOptions compareOptions)
   en System.Speech.Recognition.SpeechRecognitionEngine.EmulateRecognize(String inputText)
   en VoxCommando.MainWindow.emulateOnString(String strEmulateCommand)
   en VoxCommando.MainWindow.doAction(macroElement action, List`1 payloads)
   en VoxCommando.MainWindow.doVoxCommand(activeCommand doCommand)
   en VoxCommando.MainWindow.doEvent(String strEventName, List`1 payloads)
   en VoxCommando.MainWindow.doEvent(String strEventString)
   en VoxCommando.MainWindow.backgroundWorkerUDP_ProgressChanged(Object sender, ProgressChangedEventArgs e)
   en System.ComponentModel.BackgroundWorker.OnProgressChanged(ProgressChangedEventArgs e)
   en System.ComponentModel.BackgroundWorker.ProgressReporter(Object arg)
...
...

Any idea about what's happening here? I'm really lost and I can't find anything else is VCs logs.

Many many thanks for your patient and I'm really sorry for the horrible English I have used in this message, it's too late to think properly. My apologizes.

Best regards James,

Aitor
« Last Edit: March 31, 2012, 12:20:30 PM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: [Suggestion] WifiRemote connection check command
« Reply #9 on: April 02, 2012, 12:53:16 PM »
Hi Aitor,

I just want to let you know that I read your post, and understand the issue you are having.  I am still looking into this.  Basically I think it comes down to a "failure to reconnect" issue.  Hopefully I can figure it out and then you won't have to mess around with restarting VC over and over, which is something it is not really meant to do.  In addition, I will probably be adding some new commands / variables that will give you a bit more control over trying to call the command after the machine is reconnected.

I will also try to add an event which will only fire once MP is fully connected and ready to accept commands.

it is a struggle for me though because I don't fully understand how the asynchronous socket connections with MP/WifiRemote work.  I will keep trying though!

edit: oh and by the way, as a temporary solution, you might try removing the authentication in wifi remote settings.  It think that will allow you to reconnect successfully after sleep.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: [Suggestion] WifiRemote connection check command
« Reply #10 on: April 03, 2012, 02:42:26 PM »
please try the new version:

http://voxcommando.com/forum/index.php?topic=787.0

I am hoping that it will reconnect properly.  When you get the Mpwifi.connect event it should be ready to go.

There is also a disconnect event.  It seems to fire when the MP machine goes to sleep, but if your network connection is severed it takes a while for the socket to close (if ever).  I may beef this up in the future.

The new version of VC also lets you store any value into a user variable, so you could store your {lastspoken} and then use it later when the connect event fires.

bodiroga

  • $upporter
  • Jr. Member
  • *****
  • Posts: 48
  • Karma: 1
    • View Profile
Re: [Suggestion] WifiRemote connection check command
« Reply #11 on: April 04, 2012, 08:37:00 PM »
please try the new version:

http://voxcommando.com/forum/index.php?topic=787.0

I am hoping that it will reconnect properly.  When you get the Mpwifi.connect event it should be ready to go.

There is also a disconnect event.  It seems to fire when the MP machine goes to sleep, but if your network connection is severed it takes a while for the socket to close (if ever).  I may beef this up in the future.

The new version of VC also lets you store any value into a user variable, so you could store your {lastspoken} and then use it later when the connect event fires.

Just two words James: fucking genius! Seriously man, I wish all big and medium companies would have 50% of your patient, attention and care for their users. It's a pleasure to be part of this community and I'm glad that I bought your program, you really deserve every euro.

As you can assume your changes work perfectly and now VC fire the actions after it is connected to MediaPortal, great! No more EGs events, no more batch files and no more crashes, it just works! Many many thanks for your work James, I'm in love with you program!

Best regards,

Aitor

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: [Suggestion] WifiRemote connection check command
« Reply #12 on: April 04, 2012, 09:20:36 PM »
It is an absolute pleasure, especially when people like yourself are so generous with their praise and to show their appreciation!  I'm also very glad to hear that it works.  One less thing to worry about!  ::wiggle

Thanks Aitor :)