Author Topic: Using RFID to detect proximity and run TTS using voxcommando  (Read 31485 times)

0 Members and 3 Guests are viewing this topic.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #45 on: October 30, 2013, 09:06:31 AM »
In order to solve this problem, I need to know the actual specification for the TCP messages that we can expect to receive.  We need to look at all possible messages, not just a single example at one time.

What are the possible values for the ID byte?
What are the possible values for the gain byte?
What do all the other bytes mean, and can they change, or will they always remain the same?

If we know this we can solve the problem.  Otherwise we are just fooling around for fun...

My main concern now is, how often do these "update" messages arrive?  If you are using 5 tags and each one is sending a message every 5 seconds, VC will be constantly dealing with these messages which will most likely interfere with the normal operation of the program.  In that case you should really find an alternative solution, such as a python script that is running on its own thread, which only interrupts the main program when something significant has happened, such as someone arriving, or someone leaving.

Another option would be to have a second VC running, only for this purpose. It could send updates to your regular VC.
« Last Edit: October 30, 2013, 09:08:43 AM by jitterjames »

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #46 on: October 30, 2013, 09:22:04 AM »
Thanks, James. I have the same concern but I plan to use separate VC or find other TCP server to deal with this. What I know about the format is FB 10 00 00 TagID RFGain ReaderID 01
where FB 10 00 00 is hex header and 01 is tail. TagID is range from 00 to FF same as RFGain which is RF level from 00 to FF. ReadID is what I can preset it. The time interval to scan Tag which can be configured, assuming from 100ms to 1000ms. I like VOX becasue of its convenience and easy to script. I don't know if any other TCP server I should try. But if I can resolve (A)Contains(B) problem I mentioned above. It already resolve it in VOX for my situation. Then I only need to know how to put global variable in VOX. It look like to learn another programming language from scratch  :bonk :bonk :bonk :bonk :bonk

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #47 on: October 30, 2013, 09:35:58 AM »
OK. I will get back to you. Let me think about this a bit.

You can look at using setvar, or maps to store values.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #48 on: October 30, 2013, 11:16:36 AM »
Here is a starting point using python.  It does not yet store the variables or decide when someone has arrived, or departed, but it is a good place to start I think.

Put the attached python file into your "VoxCommando\PY" folder

If you are not already using the python plugin you must:

- enable the plugin in Options and restart VC
- look in "VoxCommando\plugins\PY\Lib" and execute the file "Extract me here.exe" to extract the python library files.

If you are familiar with writing code in general you will not have too much trouble with python.  It is similar to luup.  There are many examples to be found online.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="True" name="rfid python test" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="1142" name="test send" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TCP.Single.Write</cmdType>
      <cmdString>\xFB\x10\x00\x00\x18\x05\x01&amp;&amp;127.0.0.1&amp;&amp;1000</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
  </command>
  <command id="1146" name="python tcp server" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <cmdString>PY\rfidTcpThread.py</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
</commandGroup>
« Last Edit: October 30, 2013, 11:59:05 AM by nime5ter »

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #49 on: October 30, 2013, 11:44:17 AM »
Excellent, James. Nothing I can say: only one word, Awesome! I will start to learn it and explore if it is a right way to expand VOX. If I used Python to fork a thread to handle it, I think few transactions in sec should not be a big problem under VOX, is it correct? I love it so much  :biglaugh :biglaugh :biglaugh :biglaugh :biglaugh

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #50 on: October 30, 2013, 12:46:04 PM »
Yes, I think it will be OK but I would set the RFID scan period to the longest possible (which is 1 second, I guess).

You might not need to create any other threads, other than the one that I already created to listen on the TCP socket.

One thing I am not too clear about.  How do you decide if someone is gone?  Does the "reader" device generate TCP messages for all tags every second including the tags that are "away/missing", or only for tags that are within range?

Will you consider a tag as "away/missing" when the gain is exactly 0, or do you consider it "away/missing" when the gain is (for example) less than 15.

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #51 on: October 31, 2013, 04:07:36 AM »
Thanks, James.

I have asked the manufacturer who said Active RFID Tag will actively send its presence signal to the reader every one second. Once the reader got it then it will send this tag information in form of hexcode stream FB 10 00.... over TCP port to our TCP server which represent this tag is presence. If no this tag signal is detected, the reader will not send this tag information which represents this tag away already. For the reader side, it is simple. But for our program, it will have a bit complicated. I need to check how long the idle time for every tag (mean how long I do not receive the tag information), once it run over this idle time, we can classify it is away. RFGain is not what my understanding before which is not a signal strength of tag to represent its distance from reader. I should not use this field to confirm if the tag is away....

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #52 on: October 31, 2013, 12:08:36 PM »
OK.  Here is your complete solution.

You just need this one command to load it and the python will do the rest, generating events when new IDs arrive or when they are absent for more than 30 seconds:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="1146" name="python tcp server" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecFile</cmdType>
    <cmdString>PY\rfidTcpThread.py</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>VC.Loaded</event>
</command>

You can test it by sending a bunch of random IDs in a loop.  Ideally you would run this command from a different computer.  You must trigger this command using the phrase "do R.F.I.D. test".  If you just click execute from the tree editor it will not loop.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="1142" name="do R.F.I.D. test" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="True" loopDelay="5000" loopMax="200" description="">
  <action>
    <cmdType>TCP.Single.Write</cmdType>
    <cmdString>\xFB\x10\x00\x00\x0{Rnd.2.9}\x05\x01&amp;&amp;127.0.0.1&amp;&amp;1000</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>test</event>
  <phrase>do R.F.I.D. test</phrase>
</command>

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #53 on: November 01, 2013, 06:27:37 AM »
James, Katte and all brothers in VOX Forum. It's great and appreciate all of your help. Excellent support  :D :D :D :D :D :D :D :D :D :D

I just got 2.4GHz Active RFID Reader and some Active Tags. When I plug it then do some basic configuration. James's solution immediately works as we expect and perfectly show me Tag in and away as expect. Perfect!!!

I believe the logic must work for other RFID readers that can benefit us to start proximity detction project using VOX in the future. I will pass the information to other friends and use it good software for more advanced home automation.

This is the one I purchased from TaoBao (China ebay) http://item.taobao.com/item.htm?id=13280048779

Enjoy!!

I also used the following UHF Audio Transmitter from PC (speaker jack) to up to 6 speakers for TTS broadcasting at home. I used the following bluetooth speaker as 3.5mm AUX in becasue I like its appearance :-)

http://item.taobao.com/item.htm?id=16822952986
http://trade.taobao.com/trade/detail/tradeSnap.htm?spm=a1z09.2.9.84.hj3NN8&tradeID=441668175466002

Enjoy too and good to share more!!!

Ah, James, you may try to develop a cutomize code for bluetooth detection within Python to detect the presence of your mobile phone back or away from home. I already used a sample code in PC to detect my mobile bluetooth signal. It can trigger a series of batch commands and run different scenes (via http) in Vera for my proximity detection. Intersting :biglaugh :biglaugh :biglaugh :biglaugh :biglaugh :biglaugh
 




Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #54 on: November 01, 2013, 07:13:24 AM »
Very cool stuff!

@James
Did you see the pictures of the Wireless Audio device? It looks like exactly as my HALx  :D
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #55 on: November 01, 2013, 09:30:03 AM »
Yes, this is what is known as a "Chinese Box".

I have updated the python code a bit for the rfid and added a function to check "who is home".

The voice command "do rfid test" runs a loop that sends random IDs to simulate the tag reader.

Here is a demo:



The updated python code is attached.  The old version might not have been safe because of different threads reading and modifying the dictionary simultaneously.

Here is the complete group including the "who is home" command.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="True" name="rfid python test" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="1142" name="do R.F.I.D. test" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="True" loopDelay="150" loopMax="100" description="">
    <action>
      <cmdType>TCP.Single.Write</cmdType>
      <cmdString>\xFB\x10\x00\x00\x{Rnd.0.1}{Rnd.0.9}\x05\x01&amp;&amp;127.0.0.1&amp;&amp;1000</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>test</event>
    <phrase>do R.F.I.D. test</phrase>
  </command>
  <command id="1146" name="python tcp server" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <cmdString>PY\rfidTcpThread.py</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
  <command id="245" 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 = whoIsHome()</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>{LastResult}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>who is home</phrase>
  </command>
</commandGroup>
« Last Edit: November 01, 2013, 09:32:59 AM by jitterjames »

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #56 on: November 01, 2013, 09:42:41 AM »
Wow, great work  ::bow
Maybe this is also possible with a smartphone when it is connect to the WLAN router. My smartphone/tablet connect automatically to the WLAN. When I'm at home the MAC or IP address for the device is available and we can use this information in VC (I think, but I'm not sure)  ::hmm
***********  get excited and make things  **********

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #57 on: November 01, 2013, 10:10:18 AM »
Wonderfullllllllllllllllllllllllllllllllllllll :biglaugh :biglaugh :biglaugh Excellenttttttttttttttttttttttt :biglaugh :biglaugh :biglaugh :biglaugh

I test it already as well. Work perfect. I initally plan to do who is home function but you already helped. Nothing I can say, thank you soooooooooooooooo much  ;D

Yes the next proximity is for mobile phone detection by either ping your mobile IP address at home or its bluetooth address. Look forward to seeing more fun using VOX on home automation. I love you guys  ;)

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #58 on: November 01, 2013, 10:13:19 AM »
Hi Katte, what's HALx? May I know more detail? Wireless via 2.4G or Bluetooth or UHF, VHF?? My one can pass through two rooms becasue of UHF, how about your? May I have the site to check? Thanks.  ;)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #59 on: November 01, 2013, 10:18:22 AM »
You can search the forum for HALX.

But you can't buy this anymore.  Maybe one day xterminator will start selling them again...