LinuxMCE Forums

Archive => Archive => Pluto Main General Issues => Topic started by: archived on September 07, 2006, 07:14:39 am

Title: How to stop a respond to event (bluetooth)
Post by: archived on September 07, 2006, 07:14:39 am
Hello, I set up a "bluetooth detected" event to send codes to my projector and my receiver. The good news is that it works! the bad news is that while I have my bluetooth device (mobile phone) turned on, it continue to send the codes over and over... How do I stop sending the commands, or how do I send it only once?

Thanks a lot for your help in advance! :D
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 07, 2006, 11:31:19 am
Hi,

I guess you have two solutions for this problem. Bluetooth_Dongle fires tree events:
- "Mobile orbiter detected" (The dongle detects the phone.)
- "Mobile orbiter linked" (The dongle successfully linked to the phone)
- "Mobile orbiter lost" (The dongle lost the connection to the phone)

Solution 1
-----------

If you have a phone supported by pluto on which you can install and use a "mobile orbiter" (symbian series 60 phones and windows mobile 2003 phones, for now), you can use "Mobile orbiter linked" events to send codes to your projector (the event is sent only once, when bluetooth_dongle connects to the PlutoMO running on your phone).

Solution 2
-----------

You can use "Mobile orbiter detected" and use an algorithm like this in your scripts:

Code: [Select]
if( intercepted "mobile orbiter detected" and CodesSent = false)
{
   CodesSent = true
   SendCodesToProjector();
}

if ( intercepted "mobile orbiter lost" and CodesSent = true)
{
   CodesSent = false;
}


Best regards,
Cristian Miron
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 07, 2006, 05:45:27 pm
Thanks Chris, very clear. Ill try both tonigh since I do have a symbian s60 phone with PlutoMo installed.

Ill let you lnow If I have any trouble.
Regards,
Martin
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 08, 2006, 03:05:06 am
Chris, how do I set that algorithm script? in the advance event configuration? I cant find how
Thanks
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 08, 2006, 02:02:26 pm
Hi Martin,

Yes, you can run a script when an event is fired and to do this, you'll need to edit events commands from pluto-admin (Advanced -> Configuration -> Events).

Let's say you'll choose the event "phone detected". When this event is fired, you'll choose an App_Server to process "Spawn application" command. This command accepts a filename and arguments as parameters. You'll set as filename a bash script, for example, like "SendCommandToProjector.sh", and with an argument "detected" or "lost". If you don't like bash, you can choose python, perl or a c++ application to do this job.

Best regards,
Cristian Miron
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 08, 2006, 04:29:35 pm
Quote from: "chris.m"
Hi Martin,

Yes, you can run a script when an event is fired and to do this, you'll need to edit events commands from pluto-admin (Advanced -> Configuration -> Events).

Let's say you'll choose the event "phone detected". When this event is fired, you'll choose an App_Server to process "Spawn application" command. This command accepts a filename and arguments as parameters. You'll set as filename a bash script, for example, like "SendCommandToProjector.sh", and with an argument "detected" or "lost". If you don't like bash, you can choose python, perl or a c++ application to do this job.

Best regards,
Cristian Miron

Is there possibility to write event handler in Ruby (like in gsd) ? It would ease such programming a lot....

Thanks in advance,

regards,

Rob.
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 10, 2006, 07:22:03 pm
Hi Chris, thanks for your answer. I didnt know i had to setup a script. I dont know any of those languages. I went to Advanced- Configuration- Events; the edit command event and set appserver and then spawn application. Then I have this:
#51 Arguments (string)  
#126 Exclusive (bool)  
#13 Filename (string)  
#50 Name (string)  
#120 Retransmit (bool)  
#94 SendOnFailure (string)  
#95 SendOnSuccess (string)  
#115 Show logo (bool)
 
What do I have to do then?
Thanks a lot.
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 11, 2006, 10:02:41 am
Quote
Is there possibility to write event handler in Ruby (like in gsd) ? It would ease such programming a lot....

Thanks in advance,

regards,

Rob.


Hi Rob. Right now you cannot write an event handler in Ruby. An idea would be to add this feature to gsd (the ability to intercept events) and the user will be able to create a new gdb "device" called, let's say, "Event Handler" which will intercept events and then send the desired commands. However, gsd wasn't designed to support this feature and I don' think this will be implemented in the near future.
The second solution would be to use pluto-admin to configure an event handler and run a script/application via App_Server's SpawnApplication command. If you want to write the event handler in ruby, you can type there the filename like this "/usr/bin/ruby ./script/myPlutoEventHandler" and command line parameters for script in Arguments.


Quote
Hi Chris, thanks for your answer. I didnt know i had to setup a script. I dont know any of those languages. I went to Advanced- Configuration- Events; the edit command event and set appserver and then spawn application.


Hi Martin,

This is how the parameters should look:

#51 Arguments (string)               = detected
#126 Exclusive (bool)
#13 Filename (string)        = /usr/bin/python /usr/pluto/bin/myEventHandler.py
#50 Name (string)                      = PythonEventHandler
#120 Retransmit (bool)              
#94 SendOnFailure (string)
#95 SendOnSuccess (string)
#115 Show logo (bool)

You can ignore the other parameters. What programming languages do you know ?


Best regards,
Cristian Miron
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 11, 2006, 03:44:59 pm
Hi,

thanks for info. Well I like to program in Perl - I actually didn't wrote single line in Ruby - I just thought to learn it since it's integrated in GSD. Anyway integrating possibility of more script languages would be marvelous, but when the time permits....

I'll probably write Perl interface in Misterhouse. But I have important question:
- does pluto wait till that external script finishes ? One useful solution is to wait, another is just to start it and let it running...

Regards,

Rob.
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 11, 2006, 04:59:20 pm
Pluto doesn't wait till the external scripts finish. There are two parameters for SpawnApplication (SendOfFailure and SendOnSuccess) which can contain a list with commands to be executed when the external script/application exits with success or failure.

Best regards,
Cristian Miron
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 11, 2006, 11:29:18 pm
Thanks again Chris. So basically I have to enter the commands on SendOnFailure and SendOnSuccess. Could you send me a sample of the script and how to excecute it? (martin@interwebsa.net). It would help a lot if you explain it to me step by step considering that I dont know about bash scripts.

Thanks a lot and sorry to bother  :wink:
Martin
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 12, 2006, 10:37:46 am
Hi Martin,

Let's create two bash scripts in /usr/pluto/bin and give them rights for execution (chmod +x filename):

For "Mobile Orbiter Detected" event, /usr/pluto/bin/HandleMODetected.sh :

Code: [Select]
#!/bin/bash

FCodesSent=/tmp/pluto_codes_sent

## If the file doesn't exist
if [[ ! -f "$FCodesSent" ]]; then
   touch $FCodesSent
   # send message to projector
   # /usr/pluto/bin/MessageSend dcerouter 0 <projector_Device_id> 1 <command_id> <additional parameters: pair id,value> like this
   /usr/pluto/bin/MessageSend dcerouter 0 23 1 130
fi



For "Mobile Orbiter Lost" event, /usr/pluto/bin/HandlerMOLost.sh :


On "Mobile Orbiter Lost" event:

Code: [Select]
#!/bin/bash

FCodesSent=/tmp/pluto_codes_sent

## if the file exists
if [[ -f "$FCodesSent" ]]; then
   rm -f $FCodesSent
fi


Now, let's configure the event handler.
For "mobile orbiter detected", set this arguments:

Code: [Select]
#51 Arguments (string) =
#126 Exclusive (bool)
#13 Filename (string) = /usr/pluto/bin/HandleMODetected.sh
#50 Name (string) = MODetectedHandler
#120 Retransmit (bool)
#94 SendOnFailure (string)
#95 SendOnSuccess (string)
#115 Show logo (bool)


For "mobile orbiter lost", set this arguments:

Code: [Select]
#51 Arguments (string) =
#126 Exclusive (bool)
#13 Filename (string) = /usr/pluto/bin/HandleMOLost.sh
#50 Name (string) = MOLostHandler
#120 Retransmit (bool)
#94 SendOnFailure (string)
#95 SendOnSuccess (string)
#115 Show logo (bool)



Best regards,
Cristian Miron
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 15, 2006, 06:23:27 am
Thanks Chris, you've been very patience with me thanks a lot  :D

OK I figure it out how to put the script in /usr/pluto/bin and at least when I do a "dir" (using putty) I see the file HandleMODetected.sh

The script I created was for turning on the receiver in AV2 so it was like this:

Code: [Select]

#!/bin/bash

FCodesSent=/tmp/pluto_codes_sent

## If the file doesn't exist
if [[ ! -f "$FCodesSent" ]]; then
   touch $FCodesSent
   # send message to projector
   # /usr/pluto/bin/MessageSend dcerouter 0 40 1 317
fi


where 40 is the receiver ID and 317 the command ID which I tested and it did turned on the receiver in AV2.

Then in the event configuration in criteria I set PK_Room = Home Theater (the room where the receiver is configurated)

and in commands:

Code: [Select]

#51 Arguments (string) =
#126 Exclusive (bool)
#13 Filename (string) = /usr/pluto/bin/HandleMODetected.sh
#50 Name (string) = MODetectedHandler
#120 Retransmit (bool)
#94 SendOnFailure (string)
#95 SendOnSuccess (string)
#115 Show logo (bool)


Am I missing something? I have the mobile phone with bluetooth on and nothing happens  :?

Thanks a lot Chris I feel Im getting closer  8)
Martin
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 17, 2006, 05:16:10 pm
Any ideas?
thanks a lot
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 21, 2006, 12:17:56 am
Hello Chris, could you help me on my last question?
Thanks!
Martin
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 27, 2006, 08:31:35 pm
Chris or someone else, could someone please help me on my last question? I think Im close to the answer  :idea:

Thank you
Martin
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 28, 2006, 09:40:02 am
Hi,

Sorry for the delay, I was in the vacation :)
It's an easy way to debug. When "# /usr/pluto/bin/MessageSend dcerouter 0 40 1 317" is executed, you should see in /var/log/pluto/DCERouter.log a line of log like this: Received from 0 to 40 message type 1 id 317 with parameters: ...  

You can use putty for example and in linux console type:
tail -f /var/log/pluto/DCERouter.log, then fire the event and check the log.

You can also can run that messagesend manually to confirm it's ok.

Best regards,
Cristian Miron
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 28, 2006, 09:44:18 am
One more thing.... in bash, a # before a line means that the line is commented :) Remove that before MessageSend ;)
Title: How to stop a respond to event (bluetooth)
Post by: archived on September 30, 2006, 06:27:41 pm
Hi Chris thanks for replying!
Well I tested the messagesend manually and it works, but somehow nothing happens with the "phone detected" event.

I tryed to run the script manually (./HandleMODetected.sh) and nothing happens either.

A friend of mine told me that if I created the .sh file in windows I should convert it to a unix format unis "dos2unix". I found a conversion utility online and tryed that also. Heres my script just in case I have something wrong:

Code: [Select]

#!/bin/bash



FCodesSent=/tmp/pluto_codes_sent



## If the file doesn't exist

if [[ ! -f "$FCodesSent" ]]; then
touch $FCodesSent
# send message to receiver
/usr/pluto/bin/MessageSend dcerouter 0 38 1 317

fi


I really dont know what else to do  :?
If you think of something please let me know.

Thanks
Martin
Title: How to stop a respond to event (bluetooth)
Post by: archived on October 02, 2006, 09:49:07 am
Hi,

You must be aware that the logic from HandleMODetected.sh is to prevent  sending your message to router on two consecutive "mo detected" events (it creates a dummy file for this).  You must manually delete /tmp/pluto_codes_sent or fire/run HandleMOLost.sh, which will also delete the file.

HTH,
Cristian Miron