RFID-RC522 and sending text via serialgateway



  • Hello
    I have a problem with sending out data from arduino to controller. Without mySensors everything is working, but when I try to introduce mySensors syntax everything just stops

    #define MY_GATEWAY_SERIAL
    
    #include <MySensors.h>  
    #include <SPI.h>
    #include <MFRC522.h>
    
    #define CHILD_ID_USER 20 
    #define SS_PIN 53
    #define RST_PIN 5
    
    MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
     
    const byte michal[] = {0xD4,0x9E,0x17,0xA3};
    const byte martyna[] = {0x16,0xCF,0x8F,0x12};
    MyMessage msgUSER(CHILD_ID_USER, V_TEXT);
    
    void setup() { 
      Serial.begin(115200);
      SPI.begin(); 
      rfid.PCD_Init(); 
    }
    
    void presentation()  
    { 
      sendSketchInfo("USER", "1.1");
      present(CHILD_ID_USER, S_INFO);
    }
     
    void loop() {
      // Look for new cards
      if ( ! rfid.PICC_IsNewCardPresent()) 
        return;
     
      // Verify if the NUID has been readed
      if ( ! rfid.PICC_ReadCardSerial())
        return;
     
      if (rfid.uid.uidByte[0] == michal[0] || 
          rfid.uid.uidByte[1] == michal[1] || 
          rfid.uid.uidByte[2] == michal[2] || 
          rfid.uid.uidByte[3] == michal[3] ) 
         {
              Serial.println("User: Michal");  
              send(msgUSER.set("Michal"),1);
              delay(1500);
              
      }
      else if (rfid.uid.uidByte[0] == martyna[0] || 
               rfid.uid.uidByte[1] == martyna[1] || 
               rfid.uid.uidByte[2] == martyna[2] || 
               rfid.uid.uidByte[3] == martyna[3] )
                    {
              Serial.println("User: Martyna");  
              send(msgUSER.set("Martyna"),1);
              delay(1500);
              
      }
      else 
      {
              Serial.println("Niepoprawna karta!!!");
              send(msgUSER.set("Obcy"),1);
              delay(2000);
              
      }
      
      // Halt PICC
      rfid.PICC_HaltA();
     
      // Stop encryption on PCD
      rfid.PCD_StopCrypto1();
    }
    

    Meybe someone can see the error in my implementation?


  • Mod

    Welcome to the forum @ozyreusz!

    Could you expand on what you mean by "everything just stops"? Does the sketch not compile? If so, what error are you getting? Does the gateway not send messages through serial? If so, what does the debug output say? (add #define MY_DEBUG at top of your sketch)



  • I get no output from the card I try to read. When I comment out all lines connected with mysensors library it works

    There are no errors
    The sketch checks cards id and returns name of the card owner, if it is known, if not "unknown person" is printed on serial. I wanted to send names detected to domoticz, so based on them it would be possible to create an event

    0;255;3;0;9;0 MCO:BGN:INIT GW,CP=R-NGA---,REL=255,VER=2.3.1
    0;255;3;0;14;Gateway startup complete.
    0;255;0;0;17;2.3.1
    0;255;3;0;11;USER
    0;255;3;0;12;1.1
    0;20;0;0;36;
    0;255;3;0;9;9 MCO:BGN:STP
    0;255;3;0;9;68 MCO:REG:NOT NEEDED
    0;255;3;0;9;71 MCO:BGN:INIT OK,TSP=NA```

 

296
Online

8.7k
Users

9.5k
Topics

99.5k
Posts