Author Topic: ping phones?  (Read 13262 times)

0 Members and 1 Guest are viewing this topic.

ryz4eva

  • Jr. Member
  • **
  • Posts: 40
  • Karma: -2
  • Chasing The Tech Dragon
    • View Profile
ping phones?
« on: December 20, 2013, 03:37:15 PM »
is it possible to "ping" a mobile phone from voxcommando?

i currently have a profile set up, so that when i wake up autoremote sends a message to eventghost, then it sends a broadcast to voxcommando to run a command
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="435" name="Morning" enabled="true" alwaysOn="True" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>WUnder.GetCurrent</cmdType>
    <cmdString />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <cmdString>Good Morning Sir, Did You Sleep Well? the time is {ShortTime} on {LongDate}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.SpeakSync</cmdType>
    <cmdString>{LastResult}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>VC.Pause</cmdType>
    <cmdString>100</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>File.Read</cmdType>
    <cmdString>C:\Users\Ryan\Documents\Dropbox\Public\L.U.C.A.S\System\vitals\battery.txt&amp;&amp;0</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.SpeakSync</cmdType>
    <cmdString>Phone Battery is at {LastResult} %,</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>File.Read</cmdType>
    <cmdString>C:\Users\Ryan\Documents\Dropbox\Public\L.U.C.A.S\System\vitals\signal.txt&amp;&amp;0</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.SpeakSync</cmdType>
    <cmdString>signal is {LastResult} out of 10 and</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>File.Read</cmdType>
    <cmdString>C:\Users\Ryan\Documents\Dropbox\Public\L.U.C.A.S\System\vitals\silent.txt&amp;&amp;0</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{LastResult}&amp;&amp;off</ifParams>
    <then>
      <action>
        <cmdType>File.Read</cmdType>
        <cmdString>C:\Users\Ryan\Documents\Dropbox\Public\L.U.C.A.S\System\vitals\ringer.txt</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.SpeakSync</cmdType>
        <cmdString>ring volume is at {lastresult} out of 10</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{LastResult}&amp;&amp;vibrate</ifParams>
    <then>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <cmdString>phone is set to vibrate</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{LastResult}&amp;&amp;on</ifParams>
    <then>
      <action>
        <cmdType>TTS.SpeakSync</cmdType>
        <cmdString>your phone is muted</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <event>Morning</event>
</command>

although this is already extremely complicated, i was wondering if it was possible to send a message (dont know the proper name for it) to the ip address of my families phones, so that if they are connected to my network then voxcommando will say something along the lines of "your mother, father and brother are home, but your sister is out", or nobody is home then it would say so.

just a thought, wondered if anybody could build on it, or develop it a bit?

i already have every bodies phones on Static IP addresses.
« Last Edit: December 20, 2013, 03:47:09 PM by ryz4eva »
Rocking:
Lenovo Ideapad Z580
Samsung Galaxy Note 10.1
LG Nexus 4
Voxcommando
Eventghost
XBMC Frodo
Vera Lite

View my site to see what im up to with vox...

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: ping phones?
« Reply #1 on: December 20, 2013, 05:13:20 PM »
I actually have played around a bit with this concept as an alternative to using RFID tags.  The solution involves using the PY (python) plugin.

the python script actually uses the system ping command and keeps track of when the status of a particular IP changes.

Let me look for the code...

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: ping phones?
« Reply #2 on: December 20, 2013, 05:25:15 PM »
EDIT: I have updated this code

You need to enable the python (PY) plugin.
Put this file in your vc\PY folder
Edit the file to include your devices and their IP addresses.  Modify the part that looks like this:
Code: [Select]
boxList = []
boxList.append(box("I7", "192.168.0.125", False))
boxList.append(box("HTPC", "192.168.0.126", False))
boxList.append(box("iPod", "192.168.0.100", False))

add this command to your tree

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="True" name="ping test" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="189" name="load ping test" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <cmdString>PY\ping.py</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
  <command id="208" name="who is home" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>pingUpdateOnce()</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>result=getlist()</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>{LastResult}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>who is home</phrase>
  </command>
</commandGroup>

It should load automatically when VC loads because it has the "VC.Loaded" event assigned to it.

It will (hopefully) generate events whenever the ping status of an IP in your list changes.
« Last Edit: December 23, 2013, 01:08:39 PM by jitterjames »

ryz4eva

  • Jr. Member
  • **
  • Posts: 40
  • Karma: -2
  • Chasing The Tech Dragon
    • View Profile
Re: ping phones?
« Reply #3 on: December 22, 2013, 03:23:57 PM »
ive added this into my vox, how would i go about turning the result into a TTS event?
Rocking:
Lenovo Ideapad Z580
Samsung Galaxy Note 10.1
LG Nexus 4
Voxcommando
Eventghost
XBMC Frodo
Vera Lite

View my site to see what im up to with vox...

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: ping phones?
« Reply #4 on: December 22, 2013, 05:31:01 PM »
You are trying to do some pretty specific stuff, but without really being that familiar with VoxCommando, and presumably, without knowing how to write code.  I can help you with this, but in general, to be able to solve problems like this you'll need to become more familiar with the software, and maybe you can also view this as an opportunity to familiarize yourself with python programming.

The python code I posted was something that I already had that was intended as a means to generate an event whenever someone arrived, or left.  The idea being that when Joe's iPod appeared, it could do whatever it was supposed to do when Joe got home.

I have adapted the code to include a function to check which devices are present and to return a result based on that.  The result will be of the form

i7 is home, ipod is not home, tablet is not home etc.

Here is the new function (full python code is also attached but you'll need to change the names and ip addresses)
Code: [Select]
def getPingList():
    mylist=""
    for target in boxList:
        mylist+=target.name
        if target.present:            
            mylist+=" is here, "
        else:
            mylist+=" is not here, "
    mylist = mylist.strip()
    mylist = mylist.strip(',')
    return mylist

and here is a VC command xml with the actions needed to access this function and the result.
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="198" name="who is home" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecString</cmdType>
    <cmdString>result=getPingList()</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <cmdString>{LastResult}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>who is home</phrase>
</command>

If you want to change the way the list is phrased, I recommend that you try to understand the python code and to modify it to suit your needs.
« Last Edit: November 02, 2014, 07:38:32 AM by nime5ter »

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2318
  • Karma: 47
    • View Profile
Re: ping phones?
« Reply #5 on: December 23, 2013, 10:04:47 AM »
For all users which use not a english version of Windows OS (german, french, ...)

If you want to use the python script above, you must change code in follow line, otherwise you get always a True result for the ip adresses.

first check your OS language: Click on the Windows "Start button", type cmd and then press return. As next type in the cmd window ping 192.168.0.2 (change 192.168.0.2 with a available IP) and press return.
You can see a result for this IP - take a look on the word that I have marked red -> If you can see here the word loss - you need not to modify the ping.py and everything is fine. If there a other word as loss, you must replace the word loss in the ping.py with exact the word that is is displayed. In my case (german) Verlust.

example:

[attachment=1]

How can you change code in a python code: open the ping.py in a txt-editor  ;)

After you have open the ping.py search for the word loss, replace it and save the file.

[attachment=2]



That is all - I hope this will help some users

Merry Christmas   ::antlers


Kalle
« Last Edit: December 23, 2013, 10:14:31 AM by Kalle »
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: ping phones?
« Reply #6 on: December 23, 2013, 10:24:30 AM »
Thanks Kalle.  Good catch, I did not think of that!  :bonk

I wonder if we could simply use "100%" and then it might work in all languages?

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2318
  • Karma: 47
    • View Profile
Re: ping phones?
« Reply #7 on: December 23, 2013, 10:41:08 AM »
Yes, you're right, if we use only "100%" it will work with all languages  ::duh

So will be best if you replace the attached code with a new one and we can clean the thread.
« Last Edit: December 23, 2013, 12:59:43 PM by jitterjames »
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: ping phones?
« Reply #8 on: December 23, 2013, 12:58:08 PM »
Sorry, there was an error in the python code, first line should read:

import os,thread, time

time was missing, so the polling loop was only running once and then dying.

I will post the full corrected code and xml at the beginning of this thread to avoid confusion.  It will take me a few minutes to make sure everything is correct first.

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: ping phones?
« Reply #9 on: October 22, 2014, 02:22:10 AM »
Can anybody modify this PY code to make it raise an event one a new device joins or leaves the LAN?
When Voice command gets tough, use hand gestures

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: ping phones?
« Reply #10 on: October 22, 2014, 09:02:19 AM »
I guess I do not understand your question because as far as I know that is exactly what my ping script does.

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: ping phones?
« Reply #11 on: October 22, 2014, 09:17:16 AM »
I guess I do not understand your question because as far as I know that is exactly what my ping script does.

Then I think I did not understood the script when I read it  :bonk :bonk :bonk,
But I have another question, can device name used instead of ip ? So it will be possible pinging devices with dynamic IP?
« Last Edit: October 22, 2014, 09:30:37 AM by Haddood »
When Voice command gets tough, use hand gestures

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: ping phones?
« Reply #12 on: October 22, 2014, 10:37:38 AM »
But I have another question, can device name used instead of ip ? So it will be possible pinging devices with dynamic IP?

Yes, it's just using the standard ping command, which can use either IP or device name, so you can change the ping line to use "self.name" instead of "self.ip".

Obviously this will only work if you can ordinarily ping that device by name on your network. So, you could start by checking whether that works before messing with the script.

For devices that you can ping by device name, you get a slightly different pingResult returned if it can't find the device name, so you'd need to catch that in the code before you can define the "present" variable.
« Last Edit: October 22, 2014, 03:39:46 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: ping phones?
« Reply #13 on: October 22, 2014, 05:23:16 PM »
I've checked into this a bit more. Ping is only resolving names for actual computers on my LAN, not other devices. So I guess that won't help you.

Continuing to ponder alternatives ...
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: ping phones?
« Reply #14 on: October 25, 2014, 09:37:21 AM »
I've checked into this a bit more. Ping is only resolving names for actual computers on my LAN, not other devices. So I guess that won't help you.

Continuing to ponder alternatives ...

Your router should give it is ip as main DNS ... I do not have an issue with resolving names...

On the other hand for some reason the script stop looping after about 15 to 20 iterations !!! No idea why...

iPhone, iPad keep coming online and offline (I am pinging at interval of 15 seconds) ... That can be resolved by waiting x of times to be offline before declaring the device offline, but still not very elegant ... And not sure if mobile devices respond to ping when they are sleeping ...

On the other hand i found http://people.csail.mit.edu/albert/bluez-intro/c212.html which will be much better solution for mobile devices to ping them using Bluetooth ... However I have no idea how to add new modules for VC Python IDE ...
If we can make this happen ... We will end up with above script to monitor standard network devices and a similar using Bluetooth for mobile devices ...

Maybe the Bluetooth lib can be made as a plug-in ? That will be really neat
Any ideas, thoughts ?


Edit: I changed one line in the above script, as I found that unreachable devices triggers false online status since the reply do not have "100 Loss". the new line is
Code: [Select]
present = "bytes=32" in pingResult
« Last Edit: October 25, 2014, 10:48:02 AM by Haddood »
When Voice command gets tough, use hand gestures