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

0 Members and 1 Guest are viewing this topic.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #30 on: October 29, 2013, 10:47:53 AM »
it is perfectly normal.  \x2B is the ascii code for "+"

so \x12\x2B becomes \x12+

and \x12\x4B becomes \x12K

It will always convert this way, and there is nothing random about it, so you can still use it with confidence as an ID etc.

Only codes that cannot be converted to a character will be represented in the Hex format.

Why don't we wait until your hardware arrives to see what actual codes are generated by your device.  Then I can help you to isolate the ID using a regular expression.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #32 on: October 29, 2013, 10:59:56 AM »
If all the other codes are always the same you can isolate the tag using regex with this pattern:

 \xFB\x10\x00\x00\x12(.*?)\x02\x01\x01

so it will capture whatever appears between the \xFB\x10\x00\x00\x12 and the \x02\x02\x01\x01

in your examples it will return + or K.  You can consider these as valid IDs

Here is the modified command that will generate a new event with your ID as the payload:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="270" name="onRFID event" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="This command is triggered when the RFID event if fired.  It attempts to find the ID and then generates a new event which includes the ID in the EVENT NAME, instead of having it in the payload.">
  <action>
    <cmdType>Results.SetLastResult</cmdType>
    <cmdString>{1}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <cmdString> \xFB\x10\x00\x00\x12(.*?)\x02\x01\x01</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{#M}&amp;&amp;1</ifParams>
    <then>
      <action>
        <cmdType>VC.TriggerEvent</cmdType>
        <cmdString>TAG.{Match.1}</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <event>RFID</event>
</command>

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #33 on: October 29, 2013, 11:34:15 AM »
I hope everyone recognizes the best support in the world   :clap ::bow :hugs
***********  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 #34 on: October 29, 2013, 11:35:20 AM »
Hi James, thank you so much for your quick reply. Yes, I want to test it before I got the hardware. Just for fun  ;D But when I use regex with your operator pattern, I always get 0 on {#M} instead of + if i send 2B as TagID. No clue.... :bonk

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #35 on: October 29, 2013, 12:11:10 PM »
It is only hypothetical until I can see the actual commands you are using.

Please copy and paste your group to the forum.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #36 on: October 29, 2013, 12:12:17 PM »
and by the way {#M} is the number of matches.  If it is working you should get a value of 1 all the time and the actual ID will be in {Match.1}

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #37 on: October 29, 2013, 12:20:50 PM »
OK.  I made a mistake.  Because \ is used in regex for special things, we must escape it by putting an extra \ in front.  So the regex pattern should be

Code: [Select]
\\xFB\\x10\\x00\\x00\\x12(.*?)\\x02\\x01\\x01
or if you want the whole command:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="304" name="onRFID event" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="This command is triggered when the RFID event if fired.  It attempts to find the ID and then generates a new event which includes the ID in the EVENT NAME, instead of having it in the payload.">
  <action>
    <cmdType>Results.SetLastResult</cmdType>
    <cmdString>{1}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <cmdString> \\xFB\\x10\\x00\\x00\\x12(.*?)\\x02\\x01\\x01</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{#M}&amp;&amp;1</ifParams>
    <then>
      <action>
        <cmdType>VC.TriggerEvent</cmdType>
        <cmdString>TAG.{Match.1}</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <event>RFID</event>
</command>

Of course we don't really need to put the whole sequence in there.  We could probably also use a pattern like this:
Code: [Select]
\\x12(.*?)\\x02

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #38 on: October 29, 2013, 12:22:18 PM »
I hope everyone recognizes the best support in the world   :clap ::bow :hugs

...and see how VoxCommando makes learning about hex codes, ascii, regex and other mysterious things FUN  ::banana!!!

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #39 on: October 30, 2013, 05:24:49 AM »
Excellent support, I love you guys so quick respone and really found VOX is so powerful. But my fool I can't fully make use of VOX to do what I want.  :bonk My interest on this case: even the hardware is not here, I also want to take this chance to explore more power of VOX  :biglaugh

Hi James, it works now.

But the RFID format data stream I mentioned previosuly, we really need to get the value of TageID and RadioGain from sixth and severth character in separate becasue we need to firstly check the severth character: RadoGain to see if it is dropped to zero level for associated TagID that means we can confirm if this associated Tag has already disappeared from the range.

For most of in-range scenrios, I should check if TagID is exactly same as the character we want first. But simply using (A contain B) operator can't show exactly what I want becasue it may have a rare case that TageID value is on RadioGain character. My solution should see if we can make use of Results object to separate TageID and RadioGain character into different varables so that I can do this check individually. I can't acheive what I want from Editor, see my screen shots below[attachment=1]!

Besides, I also need to put TagID into a global varable as a flag for the state of each TageID. Becasue my understanding is the RFID reader should continually send a lot of RFID Hexcode stream in some time interval to tell us whether TagID is in the range based on different RadioGain. The best logic we find TagID data then check TagID's RadioGain. If RadioGain>1, I need to check if this TagID flag in ON or OFF. If ON then we should ignore it. If OFF then turn it ON. For out-of-range scenrios, when its RadioGain is dropped to zero, I also need to set corresponding TagID flag OFF immedately.

I don't know if I should use Results object to manupulate these cases within VOX editor. Please advise. I want to complete this homework before my reader is shipped in order to enjoy this fun earlier  ::)

Thank you very much. I've never seen the forum so active like you guys before. So VOX is exceeded my expectation. It's worth to make use of this for more home automation cases.

Best regards,
Fai

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #40 on: October 30, 2013, 06:52:59 AM »
I'm not sure this will help you in your command, but use \\+(.*?) instead of +(.*?) in the logic block.
***********  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 #41 on: October 30, 2013, 07:00:23 AM »
Thanks, Kalle. But I tried it before and {Match.1} is still empty. Any clue?

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #42 on: October 30, 2013, 07:08:11 AM »
please confirm for me what you need as result in your example? perhaps x02
so you can use result replace.
***********  get excited and make things  **********

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #43 on: October 30, 2013, 07:16:57 AM »
Thanks, Kalle. But I tried it before and {Match.1} is still empty. Any clue?
Yes, use results.replace in your logic block instead of relusts.regex and also {LastResult} instead of {Match.1}

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="False" name="RFID test" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="604" name="RFID test" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Results.SetLastResult</cmdType>
      <cmdString>{1}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <cmdString>\\xFB\\x10\\x00\\x00\\x12(.*?)\\x01</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetLastResult</cmdType>
      <cmdString>{Match.1}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)Contains(B)</ifType>
      <ifParams>{LastResult}&amp;&amp;+</ifParams>
      <then>
        <action>
          <cmdType>Results.Replace</cmdType>
          <cmdString>+\&amp;&amp; </cmdString>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>VC.TriggerEvent</cmdType>
          <cmdString>{LastResult}</cmdString>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <cmdString>{LastResult}</cmdString>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
  </command>
</commandGroup>
« Last Edit: October 30, 2013, 07:33:52 AM by Kalle »
***********  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 #44 on: October 30, 2013, 08:30:10 AM »
Thank you so much, Kalle  :D

I can successfully extract x02 now. But, it has some issue in the logic for my RFID project.

Assume the hex code stream is \xFB\x10\x00\x00\x12+\x02\x01 where "+" is the sixth hex char and "\x02" the seventh hex char. I can only use RegEx to extract "+\x02" then put into {match.1} then use (A)Contains(B) to check if "+" is contained whatever it is from "+\x02" or "\x02+" which will make me wrong to detect exactly TagID and RadioGain information.

What I want from my case is to firstly extract the sixth hex char into the variable that's "+" then check if it is what I want (TagID). Then I can use either the same variable or another variable to extract the severth hex char that's "\x02 for another if-then condition. That can exactly avoid the problem of "+\x02" not equal to "\x02+"  from above (A)Contains(B) example.

I can't see any leftchar, midchar or righchar function in Editor. Can you help me? I'm sorry to make you all trouble. :bonk :bonk :bonk :bonk :bonk

Thanks,
Fai