RFID Reader ID-3LA



  • Hello everybody,

    i am trying to establish a node with a RFID reader to recognice which Resident is at home. Therefore I have a ID-3LA including antenna.
    The reader works fin with this sketch:

    #include <SoftwareSerial.h>
    
    SoftwareSerial rfid = SoftwareSerial(5, 6);
    String msg;
    
    void setup()  
    {
      Serial.begin(9600);
      rfid.begin(9600);
      Serial.println("Ready");
    }
    
    void loop(){
      msg = "";
      
      while(rfid.available()>0) {
        msg += char(rfid.read());
        delay(1);
      }
      
      if(msg.length() >= 13) {
         msg=msg.substring(1,13);
         tone(4, 262, 100);
         Serial.println(msg);
      }
    }
    

    this code results on the serial Monitor with 9600 baud in something like:

    Ready
    0100B058FD14

    which is excactly what i want (for now).

    But Iam strugeling implementing it into MySensors, that is what i came up with:

    /**
     * ID-3LA       Arduino
     * -----      -------
     * GND   ->   GND
     * VCC   ->   +3.3V
     * D0   ->   D5
     * D1   ->   D6
     * FORM -> GND
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_NODE_ID 102 
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <SoftwareSerial.h>
    
    SoftwareSerial rfid = SoftwareSerial(5, 6);
    String key;
    
    #define CHILD_ID 1   // Id of the sensor child
    
    MyMessage KeyMsg(CHILD_ID, V_VAR1);
    
    void setup()  
    {
      Serial.begin(9600);
      rfid.begin(9600);
      //Serial.println("Ready");
    }
    
    void presentation()  {
      sendSketchInfo("RFID Reader", "1.0");
      present(CHILD_ID, S_CUSTOM);
    }
    
    void loop(){
      key = "";
      
      while(rfid.available()>0) {
        key += char(rfid.read());
        delay(1);
      }
      
      if(key.length() >= 13) {
         key=key.substring(1,13);
         Serial.println(key);
         send(KeyMsg.set(key)); 
         
         
      }
    } 
    

    but i do not get any readings... as i still consider myself as a started i have very little clou where to beginn finding the wrong/missing parts. It would be great to get some indications or tips.

    thanks in advance!


  • Mod

    @jeti could you post the debug output of the node? I looked at the sketch but didn't notice anyhong suspicious.



  • so this is the debug:
    I also just figurer out, that i can only see the tag code when i use 9600 baud, thats why the first line is messed up. When i use 115200 baud the tag ID does not show up...

    ¸Ëÿi"ùŸÒ9q„Š3ñ“â@Ù8>‹`ÿÊ<›Ð%ŠÆ/t6þTSP:MSG:SEND 102-102-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
    TSP:MSG:SEND 102-102-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0
    TSP:MSG:SEND 102-102-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0
    TSP:MSG:READ 0-0-102 s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    TSP:MSG:READ 0-0-102 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    TSP:MSG:SEND 102-102-0-0 s=255,c=3,t=11,pt=0,l=11,sg=0,ft=0,st=ok:RFID Reader
    TSP:MSG:SEND 102-102-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.0
    TSP:MSG:SEND 102-102-0-0 s=1,c=0,t=23,pt=0,l=0,sg=0,ft=0,st=ok:
    Request registration...
    TSP:MSG:SEND 102-102-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
    TSP:MSG:READ 0-0-102 s=255,c=3,t=27,pt=1,l=1,sg=0:1
    Node registration=1
    Init complete, id=102, parent=0, distance=1, registration=1
    TSP:MSG:READ 154-154-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    TSP:MSG:BC
    0100B058FD1
    TSP:MSG:SEND 102-102-0-0 s=1,c=1,t=47,pt=1,l=1,sg=0,ft=0,st=ok:1
    0100B058FD1
    TSP:MSG:SEND 102-102-0-0 s=1,c=1,t=47,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:READ 154-154-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    TSP:MSG:BC
    

    can it be the case the the format of the tag ID is not correct?

    thanks


  • Mod

    @jeti Looks like it has no trouble reading the tag, the print fro the node matches the one you got with the first sketch. st=ok means that the gateway acknowledged the message so it got through alright.

    What does the gateway receive? (could you post the debug log?)


  • Mod

    I think the problem is that Domoticz doesn't support V_VAR1. This post suggests to use V_TEXT instead.



  • I am using FHEM as controller.

    Log of the gateway:

    0;255;3;0;9;TSP:MSG:READ 102-102-0 s=1,c=1,t=24,pt=1,l=1,sg=0:1
    102;1;1;0;24;1

    so it receives a "1" correct?
    Can Mysesnors handle strings?


  • Mod

    @jeti Yes that is correct.

    https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help/4 has info on how to read the debug messages.

    pt=1 means payload type 1. Payload type 1 is "byte". According to https://www.mysensors.org/download/serial_api_20#variable-types V_VAR1 has a custom type. I don't know what that means, but it looks like the MySensors library interprets that as a byte, which won't be very useful for sending an RFID tag. I have not used the custom variable types and I don't know how they work unfortunately.

    Yes, MySensors handles strings. Use S_INFO and V_TEXT as suggested in the post I linked to above.



  • @mfalkvidd:
    also with S_INFO amd V_TEXT the gateway only receives a "1"...

    I just searched and played a little more and i got i working now:

     /**
     * ID-3LA       Arduino
     * -----      -------
     * GND   ->   GND
     * VCC   ->   +3.3V
     * D0   ->   D5
     * D1   ->   D6
     * FORM -> GND
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_NODE_ID 102 
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <SoftwareSerial.h>
    
    SoftwareSerial rfid = SoftwareSerial(5, 6);
    int  val = 0; 
    char code[10]; 
    int bytesread = 0; 
    
    #define CHILD_ID 1   // Id of the sensor child
    
    MyMessage KeyMsg(CHILD_ID, V_VAR1);
    
    void setup()  
    {
      Serial.begin(9600);
      rfid.begin(9600);
      //Serial.println("Ready");
    }
    
    void presentation()  {
      sendSketchInfo("RFID Reader", "1.0");
      present(CHILD_ID, S_CUSTOM);
    }
    
    void loop(){
    if(rfid.available() > 0) {          // if data available from reader 
        if((val = rfid.read()) == 10) {   // check for header 
          bytesread = 0; 
          while(bytesread<10) {              // read 10 digit code 
            if( rfid.available() > 0) { 
              val = rfid.read(); 
              if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading 
                break;                       // stop reading 
              } 
              code[bytesread] = val;         // add the digit           
              bytesread++;                   // ready to read next digit  
            } 
          } 
          if(bytesread == 10) {              // if 10 digit read is complete 
            Serial.print("TAG code is: ");   // possibly a good TAG 
            Serial.println(code);            // print the TAG code 
          } 
          bytesread = 0; 
         Serial.println(code);
         send(KeyMsg.set(code)); 
         
        }
      }
    }
    

    The issue seemed to be the string, now with a char it works...

    now i only need to get reset the reader every now an then to recognice if a tag is removed. The reader only updates when a tag enters the reading adistance but not when it leaves it.

    thanks!


  • Mod

    @jeti great work!


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.