Wiegand sending codes to domoticz



  • Trying to get a Wiegand 26 reader to send the tagcode to domoticz.
    Being not a wizard in coding, I think I got something wrong. I need to send the cardCode to domoticz to use in events, but the code appears in domoticz as "lux".
    Does anyone out there knows how to correct the program (much obliged)

    //
    //
    #include <MySensor.h>
    #include <SPI.h>
    #define ID 0
    
     
    MySensor gw;
    MyMessage msg(ID, S_CUSTOM);
    
    #define MAX_BITS 100                 // max number of bits 
    #define WEIGAND_WAIT_TIME  3000      // time to wait for another weigand pulse.  
    
    unsigned char databits[MAX_BITS];    // stores all of the data bits
    unsigned char bitCount;              // number of bits currently captured
    unsigned char flagDone;              // goes low when data is currently being captured
    unsigned int weigand_counter;        // countdown until we assume there are no more bits
    
    unsigned long facilityCode=0;        // decoded facility code
    unsigned long cardCode=0;            // decoded card code
    
    // interrupt that happens when INTO goes low (0 bit)
    void ISR_INT0()
    {
      //Serial.print("0");
      bitCount++;
      flagDone = 0;
      weigand_counter = WEIGAND_WAIT_TIME;  
      
    }
    
    // interrupt that happens when INT1 goes low (1 bit)
    void ISR_INT1()
    {
      //Serial.print("1");
      databits[bitCount] = 1;
      bitCount++;
      flagDone = 0;
      weigand_counter = WEIGAND_WAIT_TIME;  
    }
    
    void setup()
    {
      gw.begin();
      gw.sendSketchInfo("Wiegand", "1.0");
      gw.present(ID, S_CUSTOM); 
      pinMode(13, OUTPUT);  // LED
      pinMode(2, INPUT);     // DATA0 (INT0)
      pinMode(3, INPUT);     // DATA1 (INT1)
      
      Serial.begin(9600);
      Serial.println("RFID Readers");
      
      // binds the ISR functions to the falling edge of INTO and INT1
      attachInterrupt(0, ISR_INT0, FALLING);  
      attachInterrupt(1, ISR_INT1, FALLING);
      
    
      weigand_counter = WEIGAND_WAIT_TIME;
    }
    
    void loop()
    {
      // This waits to make sure that there have been no more data pulses before processing data
      if (!flagDone) {
        if (--weigand_counter == 0)
          flagDone = 1;	
      }
      
      // if we have bits and we the weigand counter went out
      if (bitCount > 0 && flagDone) {
        unsigned char i;
        
        Serial.print("Read ");
        Serial.print(bitCount);
        Serial.print(" bits. ");
        
       
        if (bitCount == 26)
        {
                // facility code = bits 2 to 9
          for (i=1; i<9; i++)
          {
             facilityCode <<=1;
             facilityCode |= databits[i];
          }
          
          // card code = bits 10 to 23
          for (i=9; i<25; i++)
          {
             cardCode <<=1;
             cardCode |= databits[i];
          }
          
          printBits();  
          
        }
        else {
              Serial.println("Unable to decode."); 
        }
         // cleanup and get ready for the next card
         bitCount = 0;
         facilityCode = 0;
         cardCode = 0;
         for (i=0; i<MAX_BITS; i++) 
         {
           databits[i] = 0;
         } 
    
     }
    
    }
    
    void printBits()
    {
          // I really hope you can figure out what this function does
          Serial.print("FC = ");
          Serial.print(facilityCode);
          Serial.print(", CC = ");
          Serial.println(cardCode); 
          gw.send(msg.set(cardCode)); 
    }
    


  • @finch666

    Helllo,

    I'm trying to do the same. Did you succeed ?

    Kind regards
    Michel



  • Hi mscory,

    It's been a while, but as far as I remember I was able to see the values as text in domoticz, but was not able to use those in events.


  • Hero Member

    @finch666 domoticz does not support S_Custom in the way you use it. Try V_TEXT. (similar is discussed in a recent thread, I'm on a phone right now, hard to include the link.)



  • I believe I understood what you mean but I didn't find the message you referred to.

    My goal is to replace my old wired alarm with Domoticz and PiFace2 keeping my wired sensor (safer). I still have to find a way to arm/disarm the system. Up to now I didn't find such a device. If I can decypher Wiegand message I'll probably be able to use an access control device used for magnetic lock.

    Thank you to both of you

    Kind regards
    Michel


  • Mod


Log in to reply
 

Suggested Topics

  • 3
  • 1
  • 2
  • 2
  • 4
  • 24

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts