Author Topic: Using RFID to detect proximity and run TTS using voxcommando  (Read 28766 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 #75 on: November 06, 2013, 08:41:30 AM »
Try increasing the buffer size to 128

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #76 on: November 09, 2013, 05:11:26 PM »
Hello Fai,

Have you tried James's suggestion to increase the buffer size?

I'm curious whether or not that solved your problem.
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)

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #77 on: November 10, 2013, 08:51:06 AM »
I'm so sorry for my late reply because I was recently super busy  >:(

Hi James and nime5ter,

I've tried different buffer sizes and added the logic to check if (1) less than 8 chars on the buffer, (2) its header and footer bytes even (3) the length of buffer to ensure looping every 8-byte frame within buffer to check TagID, in order to avoid any duty bytes or any length size of buffer but no improvement. I found the "blocking" on socket.recv function very often when this sample is just startup or runing a while so I strongly suspect the part of TCP server code from this sample may not be able to handle the pattern of this continuous requests from the reader.

However, I found an temp solution but it is not perfect. I setup one more VOX on another machine B as a "bridge" and configure TCP Server there to receive these requests from the reader then immediately use TCP.SingleWrite to copy this stream back to this PY sample running on machine A. It seems running very well. I found using TCP Server from VOX's TCP Plug-in on this "bridge" machine should be much more robust than that's running on this PY sample.

I am not familiar with TCP programming but I found more information from web to point me to use socket option to set non-blocking mode for recv function and should use a very special logic to handle unknown buffer size sending from client. BUt I don't know how to change the code. What I know is TCP Plug-in as bridge to this sample can resolve my case. Any idea and suggestion?

Best regards,
Fai

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #78 on: November 10, 2013, 10:48:21 AM »
Please try this one.

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #79 on: November 10, 2013, 08:21:56 PM »
Hi James,

Thanks, I used 256 as the buffer size and added 8 bytes buffer test before but no improvement. I also downloaded your script and re-test it. No improvement! Any clue?

Do you know what the difference of how to code TCP server between TCP Plug-in and your sample?

Best regards,
Fai

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #80 on: November 10, 2013, 08:37:34 PM »
No. Sorry.

Without being able to experiment with the actual device I don't know what else to try.

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #81 on: November 11, 2013, 04:52:17 AM »
Thank all of your assitance. Yes, it is hard to trouble if lack of reader for trial and error. I will continue to test then update you all. I think it is socket issue so I will go deep for this area....

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #82 on: November 11, 2013, 09:31:31 AM »
I used the attached code with 8 bytes TCP buffer where include a separate thread to trigger the initial arrival events within the initialization period, a loop to check every 8 bytes frame on single recv function if buffer size more than 8 bytes (of course, now is useless due to only 8 byte buffer size). Running it using bridge machine to redirect the tag information from the reader on this sample in separate machine, so far so good :-) I will continue to think how to direct recevie tag information from the reader using this sample. Update you all later....

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #83 on: November 11, 2013, 10:55:29 AM »
The python code you just uploaded has indentation that is a mix of spaces and tabs.  I am surprised that python accepts this code at all, but it is possible that this code does not do what it looks like it should be doing!

You should remove all tabs and only use spaces in python for indentation.  If you use notepad++ to edit your python code (which I recommend) there is an option telling it to use only spaces.

If your code is working you should remove all logging and printing statements so that you are not causing your machine to be constantly writing to a text file (5 times per second) or overloading the text box in the python plugin window (from the print statements).

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #84 on: November 12, 2013, 11:27:38 AM »
I don't know why but it works on VOX. I am not familar with Python so I only know to use notepad for code modification. All logics are running as expect except TCP flow control which I never changed it. You can use your sample client to do the test and I am sure you shoulf get what you want. I have no clue for this sample so I decide to use "bridge" machine running TCP Plugin on VOX to handle all tag information from reader then copy back to another machine running on this sample for RFID alert. So far so good.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #85 on: November 12, 2013, 11:43:42 AM »
I am glad that you have a working solution.  It is too bad that we could not find a more elegant and efficient solution.

Just because your code works, does not mean that it is doing what you think it is doing.

My advice to anyone who is using any kind of Python, regardless of what editor you choose, is this:

DON'T EVER USE A SINGLE TAB.  ONLY SPACES.

Because the logic of Python is based on indentation, you can't mix tabs and spaces without having a lot of problems.

I also recommend using the fantastic, small, and completely free program called notepad++
It is superior to notepad in ALL conceivable situations, but especially when editing python, any kind of code, xml etc.

manfaiho

  • Jr. Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #86 on: November 24, 2013, 09:06:44 AM »
Hi all,

Sorry for my super busy in the past weeks no time update this thread! I took a whole day to dig into the coding (try and error) and finally identified the root cause then fix the issue. Yes, the data stream is sometime not consistent. It will even have NO data when all tags left out of home. If we assume no data then close the socket connection, the program will stop there and all tags will be departed after the timeout. Reader seems to use previous connected socket to keep the connection to send tag information. This is exactly my problem. I have changed the code especially for data stream handling below that can fix the problem eventually.

Code: [Select]
def handler(clientsock,addr):
        BUFFER_SIZE = 256
        while 1:
                try:
                        data = clientsock.recv(BUFFER_SIZE)
                        if not data: continue
                        if len(data)<8:continue
                        for i in range(0,int(len(data)/8)):
                                if data[i*8]!="\xFB" or data[i*8+1]!="\x10" or data[i*8+2]!="\x00" or data[i*8+3]!="\x00" or data[i*8+7]!="\x1F": continue
                                tagID =ord(data[i*8+4])
                                updateId(tagID)
                except clientsocket,e:
                        vc.triggerEvent("python.tcp.error",None)
                        continue
        clientsock.close()
        vc.triggerEvent("python.socket.thread.exit",None)

Of course, I have also added socketoption for timeout and created threading for each incoming socket connection for this infinite loop for recv(). Infinite looping for receving data stream is a key for Reader. If all tags not there, no data but we should wait there. Once any tags come back, the data should be continually received. It is different with so many traditional TCP server sample code whcih will close the socket then end when no data is received in buffer or specific key is treated as socket end. I attached the modified code for your reference. Enjoy!! Thanks all of your assitance and Happy VOXCOMMANDO :-)

Best regards,
Fai

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Using RFID to detect proximity and run TTS using voxcommando
« Reply #87 on: November 24, 2013, 03:03:19 PM »
Thanks for the update!
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)