Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Wiegand sending codes to domoticz

Wiegand sending codes to domoticz

Scheduled Pinned Locked Moved Troubleshooting
6 Posts 4 Posters 3.0k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • finch666F Offline
    finch666F Offline
    finch666
    wrote on last edited by finch666
    #1

    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)); 
    }
    
    mscoryM 1 Reply Last reply
    0
    • finch666F finch666

      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)); 
      }
      
      mscoryM Offline
      mscoryM Offline
      mscory
      wrote on last edited by
      #2

      @finch666

      Helllo,

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

      Kind regards
      Michel

      1 Reply Last reply
      0
      • finch666F Offline
        finch666F Offline
        finch666
        wrote on last edited by
        #3

        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.

        AWIA 1 Reply Last reply
        0
        • finch666F finch666

          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.

          AWIA Offline
          AWIA Offline
          AWI
          Hero Member
          wrote on last edited by
          #4

          @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.)

          1 Reply Last reply
          0
          • mscoryM Offline
            mscoryM Offline
            mscory
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by
              #6

              I think the post @AWI was referring to is https://forum.mysensors.org/topic/1957/lcd-clock-and-text-sensor-node-with-new-v_text/11

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              17

              Online

              11.7k

              Users

              11.2k

              Topics

              113.1k

              Posts


              Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • MySensors
              • OpenHardware.io
              • Categories
              • Recent
              • Tags
              • Popular