@gohan IDE version 1.8.1.
martins
Posts
-
Serial Gateway -
Serial Gateway@gohan I'm pulling my hair out of my head. Tried it with 2 different power sources(one an 2amp ipad charger). 2 Different mcu's. 2 Different rfm69 radios. Symptom is the same.
Configured one with the stock standard mockmysensor and it runs without a problem. Take that same one and load the serial gateway and it does this weird loop/reset thing.
Thanks
-
Serial Gateway@mfalkvidd said in Serial Gateway:
mcu
It's currently connected via an usb ftdi connector to my laptop so the power should be fine. It's an arduino pro mini 3.3v 8mhz.
-
RFID LogMyMessage TEXTMsg(CHILD_ID_TXT,V_TEXT); // Send UID of RFID tag sendSketchInfo("RFID UID", "0.0.9",false); present(CHILD_ID_TXT, S_INFO, "RFID UID",false); #ifdef MY_DEBUG Serial.print("UID sent to Controller: "); Serial.println(uid_rfid_str); #endif send(TEXTMsg.set(uid_rfid), false);Hope this helps. I use it this way and it works like a charm. Just remember you need to convert the uid to string in order to send it as text to Domoticz.
Regards,
Martin -
Serial GatewayI just can't seem to fix this. This is the serial monitor output captured. Is it normal that the gateway act in this way? It'seems to me it reloads itself but I can't figure out why!!
;255;3;0;9;MCO:BGN:INIT GW,CP=RRNGA--,VER=2.1.1
0;255;3;0;9;TSM:INIT
0;255;3;0;9;TSF:WUR:MS=0
0;255;3;0;9;TSM:INIT:TSP OK
0;255;3;0;9;TSM:INIT:GW MODE
0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
0;255;3;0;9;MCO:REG:NOT NEEDED
0;255;3;0;14;Gateway startup complete.
0;255;0;0;18;2.1.1
0;255;3;0;9;MCO:BGN:STP
0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=255,c=3,t=0,pt=1,l=1,sg=0:84
253;255;3;0;0;84
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=255,c=3,t=0,pt=1,l=1,sg=0:84
253;255;3;0;0;84
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=255,c=3,t=0,pt=1,l=1,sg=0:84
253;255;3;0;0;84
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=10,c=1,t=37,pt=2,l=2,sg=0:-76
253;10;1;0;37;-76
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=10,c=1,t=37,pt=2,l=2,sg=0:-76
253;10;1;0;37;-76
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=10,c=1,t=37,pt=2,l=2,sg=0:-76
253;10;1;0;37;-76
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=255,c=3,t=1,pt=0,l=0,sg=0:
253;255;3;0;1;
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=255,c=3,t=1,pt=0,l=0,sg=0:
253;255;3;0;1;
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=255,c=3,t=1,pt=0,l=0,sg=0:
253;255;3;0;1;
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=255,c=3,t=1,pt=0,l=0,sg=0:
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;!TSF:MSG:SEND,0-0-253-253,s=255,c=3,t=1,pt=0,l=0,sg=0,ft=0,st=NACK:
0;255;3;0;9;MCO:BGN:INIT GW,CP=RRNGA--,VER=2.1.1
0;255;3;0;9;TSM:INIT
0;255;3;0;9;TSF:WUR:MS=0
0;255;3;0;9;TSM:INIT:TSP OK
0;255;3;0;9;TSM:INIT:GW MODE
0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
0;255;3;0;9;MCO:REG:NOT NEEDED
0;255;3;0;14;Gateway startup complete.
0;255;0;0;18;2.1.1
0;255;3;0;9;MCO:BGN:STP
0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=1,c=1,t=16,pt=2,l=2,sg=0:0
253;1;1;0;16;0
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=1,c=1,t=16,pt=2,l=2,sg=0:0
253;1;1;0;16;0
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=1,c=1,t=15,pt=1,l=1,sg=0:1
253;1;1;0;15;1
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=1,c=1,t=15,pt=1,l=1,sg=0:1
253;1;1;0;15;1
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=1,c=1,t=15,pt=1,l=1,sg=0:1
253;1;1;0;15;1
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=3,c=1,t=16,pt=2,l=2,sg=0:0
253;3;1;0;16;0
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=3,c=1,t=16,pt=2,l=2,sg=0:0
253;3;1;0;16;0
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=3,c=1,t=15,pt=1,l=1,sg=0:1
253;3;1;0;15;1
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=3,c=1,t=15,pt=1,l=1,sg=0:1
253;3;1;0;15;1
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=255,c=3,t=0,pt=1,l=1,sg=0:84
253;255;3;0;0;84
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=255,c=3,t=0,pt=1,l=1,sg=0:84
253;255;3;0;0;84
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=255,c=3,t=0,pt=1,l=1,sg=0:84
253;255;3;0;0;84
0;255;3;0;9;TSF:MSG:READ,253-253-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
0;255;3;0;9;TSF:MSG:BC
0;255;3;0;9;TSF:MSG:FPAR REQ,ID=253
0;255;3;0;9;TSF:PNG:SEND,TO=0
0;255;3;0;9;TSF:CKU:OK
0;255;3;0;9;TSF:MSG:GWL OK
0;255;3;0;9;!TSF:MSG:SEND,0-0-253-253,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=NACK:0
0;255;3;0;9;MCO:BGN:INIT GW,CP=RRNGA--,VER=2.1.1
0;255;3;0;9;TSM:INIT
0;255;3;0;9;TSF:WUR:MS=0
0;255;3;0;9;TSM:INIT:TSP OK
0;255;3;0;9;TSM:INIT:GW MODE
0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
0;255;3;0;9;MCO:REG:NOT NEEDED
0;255;3;0;14;Gateway startup complete.
0;255;0;0;18;2.1.1
0;255;3;0;9;MCO:BGN:STP
0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
0;255;3;0;9;TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
0;255;3;0;9;!TSF:MSG:LEN,0!=7
0;255;3;0;9;TSF:MSG:READ,253-253-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
0;255;3;0;9;TSF:MSG:PINGED,ID=253,HP=1
0;255;3;0;9;!TSF:MSG:SEND,0-0-253-253,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=NACK:1
0;255;3;0;9;MCO:BGN:INIT GW,CP=RRNGA--,VER=2.1.1
0;255;3;0;9;TSM:INIT
0;255;3;0;9;TSF:WUR:MS=0
0;255;3;0;9;TSM:INIT:TSP OK
0;255;3;0;9;TSM:INIT:GW MODE
0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
0;255;3;0;9;MCO:REG:NOT NEEDED
0;255;3;0;14;Gateway startup complete.
0;255;0;0;18;2.1.1
0;255;3;0;9;MCO:BGN:STP
0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
0;255;3;0;9;TSF:MSG:READ,0-0-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
0;255;3;0;9;!TSF:MSG:LEN,0!=7 -
RFID and NRF24L01 Wireless Network Coding Issues@Aron-Sjöberg said in RFID and NRF24L01 Wireless Network Coding Issues:
int getID()
Change that line in the getID() function to return 0;
-
Serial Gateway crash and reloads -
Serial Gateway crash and reloadsIDE 1.8.1

-
Serial Gateway crash and reloadsNarrowed it down a bit more. As soon as I change the true (req ack) to false the gateway don't crash anymore. So my question now is why would a ack req cause the gateway to crash ?
send(TEXTMsg.set(uid_rfid), false);``` -
Serial Gateway crash and reloadsChanged the arduino pro mini. Same effect. As soon as this is executed the serial gateway restarts
send(TEXTMsg.set(uid_rfid), true);Output on serial gateway:
0;255;3;0;9;!TSF:MSG:SEND,0-0-10-10,s=9,c=1,t=47,pt=0,l=8,sg=0,ft=0,st=NACK:c350fd4b
Gateway restart:cry:
0;255;3;0;9;MCO:BGN:INIT GW,CP=RRNGA--,VER=2.1.1
0;255;3;0;9;TSM:INIT
0;255;3;0;9;TSF:WUR:MS=0
0;255;3;0;9;TSM:INIT:TSP OK
0;255;3;0;9;TSM:INIT:GW MODE
0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
0;255;3;0;9;MCO:REG:NOT NEEDED
0;255;3;0;14;Gateway startup complete.
0;255;0;0;18;2.1.1
0;255;3;0;11;MySensors Serial Gateway
0;255;3;0;12;2.0.0
0;255;3;0;9;MCO:BGN:STP
0;255;3;0;9;MCO:BGN:INIT OK,TSP=1 -
Serial Gateway crash and reloadsThis works perfect without the gateway reloading:
void granted (int setDelay) { value = 1; send(msg.set(value==HIGH ? 1 : 0)); delay(setDelay); value = 0; send(msg.set(value==HIGH ? 1 : 0)); #ifdef MY_DEBUG Serial.print("UID sent to Controller: "); Serial.println(uid_rfid_str); #endif // Send to gateway the UID to keep log of who entered // send(TEXTMsg.set(uid_rfid), false); }However as soon as I uncomment this it reloads:
send(TEXTMsg.set(uid_rfid), true);Some more code:
MyMessage msg(CHILD_ID,V_TRIPPED); MyMessage TEXTMsg(CHILD_ID_TXT,V_TEXT); // Send UID of RFID tag void presentation() { sendSketchInfo("RFID Gate", "1.0"); present(CHILD_ID, S_DOOR); sendSketchInfo("RFID UID", "0.0.1"); present(CHILD_ID_TXT, S_INFO, "RFID UID", true); } -
Serial Gateway crash and reloadsEven connected directly via usb to the ide I get the same symptom.
-
Serial Gateway crash and reloadsI comment out one msg.set from the sensor and that fix the problem. I really don't think this is power related. And this is the gateway guys. It is only powering an arduino mini pro and a rfm69.
-
Serial Gateway crash and reloadsPowered by a raspberry pi 3 of its 3.3 v. Couple of mockmysensors running of this serial gateway as well asva door sensor without any problem. However as soon as this rfid sensor sends a s_info back containing text and request an ack the gateway reboots. If I remove the sendmsg it runs fine. This text however contains the rfid_ui key and is required to log which card triggered the event.
-
Serial Gateway crash and reloadsWhy would this message cause the gateway to crash and reloads ? All it does is send a text field to the gateway and requesting an ack:
0;255;3;0;9;TSF:MSG:READ,10-10-0,s=9,c=1,t=47,pt=0,l=8,sg=0:c350fd4b
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;!TSF:MSG:SEND,0-0-10-10,s=9,c=1,t=47,pt=0,l=8,sg=0,ft=0,st=NACK:c350fd4b
0;255;3;0;9;MCO:BGN:INIT GW,CP=RRNGA--,VER=2.1.1
0;255;3;0;9;TSM:INIT
0;255;3;0;9;TSF:WUR:MS=0
0;255;3;0;9;TSM:INIT:TSP OK
0;255;3;0;9;TSM:INIT:GW MODE
0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
0;255;3;0;9;MCO:REG:NOT NEEDED
0;255;3;0;14;Gateway startup complete.
0;255;0;0;18;2.1.1
0;255;3;0;11;MySensors Serial Gateway
0;255;3;0;12;2.0.0
0;255;3;0;9;MCO:BGN:STP
0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
0;255;3;0;9;TSF:MSG:READ,10-10-0,s=8,c=1,t=16,pt=2,l=2,sg=0:1
10;8;1;0;16;1
0;255;3;0;9;TSF:MSG:READ,10-10-0,s=8,c=1,t=16,pt=2,l=2,sg=0:0
10;8;1;0;16;0
0;255;3;0;9;TSF:MSG:READ,10-10-0,s=9,c=1,t=47,pt=0,l=8,sg=0:c350fd4b
0;255;3;0;9;TSF:MSG:ACK REQ
0;255;3;0;9;!TSF:MSG:SEND,0-0-10-10,s=9,c=1,t=47,pt=0,l=8,sg=0,ft=0,st=NACK:c350fd4b
0;255;3;0;9;MCO:BGN:INIT GW,CP=RRNGA--,VER=2.1.1
0;255;3;0;9;TSM:INIT
0;255;3;0;9;TSF:WUR:MS=0
0;255;3;0;9;TSM:INIT:TSP OK
0;255;3;0;9;TSM:INIT:GW MODE
0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
0;255;3;0;9;MCO:REG:NOT NEEDED
0;255;3;0;14;Gateway startup complete.
0;255;0;0;18;2.1.1
0;255;3;0;11;MySensors Serial Gateway
0;255;3;0;12;2.0.0
0;255;3;0;9;MCO:BGN:STP
0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
0;255;3;0;9;TSF:MSG:READ,10-10-0,s=255,c=3,t=22,pt=5,l=4,sg=0:60250
10;255;3;0;22;60250Any suggestions on how to fix this is appreciated.
Regards,
Martin -
Pass RFID UID tag to DomoticzIs there a way that I can pass the UID of an RFID tag as a parameter to Domoticz to have a log of which uid trigered the switch?
Thanks,
Martin -
RFID and NRF24L01 Wireless Network Coding Issues@gohan This is the code that works for me on my pro mini. Try it out.
Here is my pins used:
MOSI: Pin 11
MISO: Pin 12
SCK : Pin 13
SS : Pin 8 (Configurable)
RST : Pin 6 (Configurable)/* Arduino RFID Access Control Security ! To keep it simple we are going to use Tag's Unique IDs as only method of Authenticity. It's simple and not hacker proof. If you need security, don't use it unless you modify the code Copyright (C) 2015 Omer Siar Baysal This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #define MY_DEBUG #define MY_RADIO_NRF24 //#define MY_RF24_PA_LEVEL RF24_PA_LOW //#define MY_RADIO_RFM69 //#define MY_RFM69_FREQUENCY RF69_433MHZ //#define MY_IS_RFM69HW #if F_CPU == 8000000L #define MY_BAUD_RATE 38400 #endif #define CHILD_ID 8 #define MAX_CARDS 18 #include <EEPROM.h> // We are going to read and write PICC's UIDs from/to EEPROM #include <SPI.h> // RC522 Module uses SPI protocol #include <MFRC522.h> // Library for Mifare RC522 Devices #include <MySensors.h> /* For visualizing whats going on hardware we need some leds and to control door lock a relay and a wipe button (or some other hardware) Used common anode led,digitalWriting HIGH turns OFF led Mind that if you are going to use common cathode led or just seperate leds, simply comment out #define COMMON_ANODE, */ int value=0; boolean match = false; // initialize card match to false boolean programMode = false; // initialize programming mode to false boolean replaceMaster = false; int successRead; // Variable integer to keep if we have Successful Read from Reader byte storedCard[4]; // Stores an ID read from EEPROM byte readCard[4]; // Stores scanned ID read from RFID Module byte masterCard[4]; // Stores master card's ID read from EEPROM byte countValidCards = 0; /* We need to define MFRC522's pins and create instance Pin layout should be as follows (on Arduino Uno): MOSI: Pin 11 / ICSP-4 MISO: Pin 12 / ICSP-1 SCK : Pin 13 / ICSP-3 SS : Pin 10 (8)(Configurable) RST : Pin 9 (6)(Configurable) look MFRC522 Library for other Arduinos' pin configuration */ // bool lockStatus; #define SS_PIN 8 #define RST_PIN 6 MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. // MFRC522::Uid validCards[MAX_CARDS]; //MyMessage lockMsg(CHILD_ID, V_LOCK_STATUS); MyMessage msg(CHILD_ID,V_TRIPPED); // MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. ///////////////////////////////////////// Setup /////////////////////////////////// void setup() { //Protocol Configuration //Serial.begin(9600); // Initialize serial communications with PC pinMode(RST_PIN, OUTPUT); digitalWrite(RST_PIN, LOW); pinMode(SS_PIN, OUTPUT); digitalWrite(SS_PIN, LOW); SPI.begin(); // MFRC522 Hardware uses SPI protocol mfrc522.PCD_Init(); // Initialize MFRC522 Hardware //If you set Antenna Gain to Max it will increase reading distance //mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); Serial.println(F("Access Control v3.4")); // For debugging purposes ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details if (EEPROM.read(500) != 143) { Serial.println(F("No Master Card Defined")); Serial.println(F("Scan A PICC to Define as Master Card")); do { successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 } while (!successRead); // Program will not go further while you not get a successful read // printHex(mfrc522.uid.uidByte, mfrc522.uid.size); for ( int j = 0; j < 4; j++ ) { // Loop 4 times EEPROM.write( 2 + j, readCard[j] ); // Write scanned PICC's UID to EEPROM, start from address 3 } EEPROM.write(500, 143); // Write to EEPROM we defined Master Card. delay(500); Serial.println(F("Master Card Defined")); // storeEeprom(); } Serial.println(F("-------------------")); Serial.println(F("Master Card's UID")); for ( int i = 0; i < 4; i++ ) { // Read Master Card's UID from EEPROM masterCard[i] = EEPROM.read(2 + i); // Write it to masterCard Serial.print(masterCard[i], HEX); } Serial.println(""); Serial.println(F("-------------------")); Serial.println(F("Everything Ready")); Serial.println(F("Waiting PICCs to be scanned")); Serial.println(EEPROM.read(500)); } void presentation() { // Register binary input sensor to gw (they will be created as child devices) // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. // If S_LIGHT is used, remember to update variable type you send in. See "msg" above. sendSketchInfo("RFID Gate", "1.0"); present(CHILD_ID, S_DOOR); } ///////////////////////////////////////// Main Loop /////////////////////////////////// void loop () { send(msg.set(value==HIGH ? 1 : 0)); do { successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 } while (!successRead); //the program will not go further while you not get a successful read if (programMode) { if ( isMaster(readCard) ) { //If master card scanned again exit program mode Serial.println(F("Master Card Scanned")); Serial.println(F("Exiting Program Mode")); Serial.println(F("-----------------------------")); programMode = false; return; } else { if ( findID(readCard) ) { // If scanned card is known delete it Serial.println(F("I know this PICC, removing...")); deleteID(readCard); Serial.println("-----------------------------"); Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); } else { // If scanned card is not known add it Serial.println(F("I do not know this PICC, adding...")); writeID(readCard); Serial.println(F("-----------------------------")); Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); } } } else { if ( isMaster(readCard)) { // If scanned card's ID matches Master Card's ID enter program mode programMode = true; Serial.println(F("Hello Master - Entered Program Mode")); int count = EEPROM.read(0); // Read the first Byte of EEPROM that Serial.print(F("I have ")); // stores the number of ID's in EEPROM Serial.print(count); Serial.print(F(" record(s) on EEPROM")); Serial.println(""); Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); Serial.println(F("Scan Master Card again to Exit Program Mode")); Serial.println(F("-----------------------------")); } else { if ( findID(readCard) ) { // If not, see if the card is in the EEPROM Serial.println(F("Welcome, You shall pass")); granted(300); // Open the door lock for 300 ms } else { // If not, show that the ID was not valid Serial.println(F("You shall not pass")); denied(); } } } } ///////////////////////////////////////// Access Granted /////////////////////////////////// void granted (int setDelay) { // setLockState(!lockStatus, true); value = 1; send(msg.set(value==HIGH ? 1 : 0)); smartSleep(5000); value = 0; send(msg.set(value==HIGH ? 1 : 0)); } ///////////////////////////////////////// Access Denied /////////////////////////////////// void denied() { } ///////////////////////////////////////// Get PICC's UID /////////////////////////////////// int getID() { // Getting ready for Reading PICCs if ( ! mfrc522.PICC_IsNewCardPresent()) return 0; // Verify if the NUID has been readed if ( ! mfrc522.PICC_ReadCardSerial()) return 0; Serial.print(F("PICC type: ")); MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak); Serial.println(mfrc522.PICC_GetTypeName(piccType)); // Check is the PICC of Classic MIFARE type if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI && piccType != MFRC522::PICC_TYPE_MIFARE_1K && piccType != MFRC522::PICC_TYPE_MIFARE_4K) { Serial.println(F("Your tag is not of type MIFARE Classic.")); return; } Serial.println(F("Scanned PICC's UID:")); for (int i = 0; i < 4; i++) { // readCard[i] = mfrc522.uid.uidByte[i]; Serial.print(readCard[i], HEX); } Serial.println(""); mfrc522.PICC_HaltA(); return 1; /* while (! mfrc522.PICC_IsNewCardPresent()) {;} if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue Serial.println("No NCP"); return 0; } if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue Serial.println("RCS"); return 0; } // There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC // I think we should assume every PICC as they have 4 byte UID // Until we support 7 byte PICCs Serial.println(F("Scanned PICC's UID:")); for (int i = 0; i < 4; i++) { // readCard[i] = mfrc522.uid.uidByte[i]; Serial.print(readCard[i], HEX); } Serial.println(""); mfrc522.PICC_HaltA(); // Stop reading return 1; */ } void ShowReaderDetails() { // Get the MFRC522 software version byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); Serial.print(F("MFRC522 Software Version: 0x")); Serial.print(v, HEX); if (v == 0x91) Serial.print(F(" = v1.0")); else if (v == 0x92) Serial.print(F(" = v2.0")); else Serial.print(F(" (unknown),probably a chinese clone?")); Serial.println(""); // When 0x00 or 0xFF is returned, communication probably failed if ((v == 0x00) || (v == 0xFF)) { Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?")); Serial.println(F("SYSTEM HALTED: Check connections.")); while (true); // do not go further } } ///////////////////////////////////////// Cycle Leds (Program Mode) /////////////////////////////////// void cycleLeds() { } //////////////////////////////////////// Normal Mode Led /////////////////////////////////// void normalModeOn () { } //////////////////////////////////////// Read an ID from EEPROM ////////////////////////////// void readID( int number ) { int start = (number * 4 ) + 2; // Figure out starting position for ( int i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes storedCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array } } ///////////////////////////////////////// Add ID to EEPROM /////////////////////////////////// void writeID( byte a[] ) { if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before! int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards int start = ( num * 4 ) + 6; // Figure out where the next slot starts num++; // Increment the counter by one EEPROM.write( 0, num ); // Write the new count to the counter for ( int j = 0; j < 4; j++ ) { // Loop 4 times EEPROM.write( start + j, a[j] ); // Write the array values to EEPROM in the right position } successWrite(); Serial.println(F("Succesfully added ID record to EEPROM")); } else { failedWrite(); Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); } } ///////////////////////////////////////// Remove ID from EEPROM /////////////////////////////////// void deleteID( byte a[] ) { if ( !findID( a ) ) { // Before we delete from the EEPROM, check to see if we have this card! failedWrite(); // If not Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); } else { int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards int slot; // Figure out the slot number of the card int start; // = ( num * 4 ) + 6; // Figure out where the next slot starts int looping; // The number of times the loop repeats int j; int count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards slot = findIDSLOT( a ); // Figure out the slot number of the card to delete start = (slot * 4) + 2; looping = ((num - slot) * 4); num--; // Decrement the counter by one EEPROM.write( 0, num ); // Write the new count to the counter for ( j = 0; j < looping; j++ ) { // Loop the card shift times EEPROM.write( start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM } for ( int k = 0; k < 4; k++ ) { // Shifting loop EEPROM.write( start + j + k, 0); } successDelete(); Serial.println(F("Succesfully removed ID record from EEPROM")); } } ///////////////////////////////////////// Check Bytes /////////////////////////////////// boolean checkTwo ( byte a[], byte b[] ) { if ( a[0] != NULL ) // Make sure there is something in the array first match = true; // Assume they match at first for ( int k = 0; k < 4; k++ ) { // Loop 4 times if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail match = false; } if ( match ) { // Check to see if if match is still true return true; // Return true } else { return false; // Return false } } ///////////////////////////////////////// Find Slot /////////////////////////////////// int findIDSLOT( byte find[] ) { int count = EEPROM.read(0); // Read the first Byte of EEPROM that for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM // is the same as the find[] ID card passed return i; // The slot number of the card break; // Stop looking we found it } } } ///////////////////////////////////////// Find ID From EEPROM /////////////////////////////////// boolean findID( byte find[] ) { int count = EEPROM.read(0); // Read the first Byte of EEPROM that for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM return true; break; // Stop looking we found it } else { // If not, return false } } return false; } ///////////////////////////////////////// Write Success to EEPROM /////////////////////////////////// // Flashes the green LED 3 times to indicate a successful write to EEPROM void successWrite() { } ///////////////////////////////////////// Write Failed to EEPROM /////////////////////////////////// // Flashes the red LED 3 times to indicate a failed write to EEPROM void failedWrite() { } ///////////////////////////////////////// Success Remove UID From EEPROM /////////////////////////////////// // Flashes the blue LED 3 times to indicate a success delete to EEPROM void successDelete() { } ////////////////////// Check readCard IF is masterCard /////////////////////////////////// // Check to see if the ID passed is the master programing card boolean isMaster( byte test[] ) { if ( checkTwo( test, masterCard ) ) return true; else return false; } /** * Helper routine to dump a byte array as hex values to Serial. */ void printHex(byte *buffer, byte bufferSize) { for (byte i = 0; i < bufferSize; i++) { Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i], HEX); } } //void presentation() { // sendSketchInfo("RFID Lock", "1.0"); // present(CHILD_ID, S_LOCK); //} void before() { // Make sure MFRC is disabled from the SPI bus pinMode(RST_PIN, OUTPUT); digitalWrite(RST_PIN, LOW); pinMode(SS_PIN, OUTPUT); digitalWrite(SS_PIN, LOW); } -
RFID and NRF24L01 Wireless Network Coding Issues@gohan What is the serial output or error that you get ?
-
RFID and NRF24L01 Wireless Network Coding Issues@gohan Yes
-
RFID and NRF24L01 Wireless Network Coding IssuesFound the solution in this thread:
https://forum.mysensors.org/topic/2439/rfid-garage-door-opener/35
void before() {
// Make sure MFRC is disabled from the SPI bus
pinMode(RST_PIN, OUTPUT);
digitalWrite(RST_PIN, LOW);
pinMode(SS_PIN, OUTPUT);
digitalWrite(SS_PIN, LOW);
}
