arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.26k stars 4.82k forks source link

PN532: Support for different NFC Cards/Tags #4941

Closed conphilpott closed 5 years ago

conphilpott commented 5 years ago

When scanning some NFC tags the data field is empty, this seems to work ok, but when others are scanned things like this are sent as JSON which make it unfriendly to decode. "DATA":"\x14\x01\x03\xe1\x03\xe1\x03\xe1\x03\xe1\x03\xe1\x03\xe1\x03\xe1\x03"

Using a wemos D1 mini with PN532, compiled and flashed using Arduino IDE

19:26:06 MQT: stat/nfc/STATUS = {"Status":{"Module":18,"FriendlyName":["NFC"],"Topic":"nfc","ButtonTopic":"0","Power":1,"PowerOnState":3,"LedState":1,"SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0}}
19:26:06 MQT: stat/nfc/STATUS1 = {"StatusPRM":{"Baudrate":115200,"GroupTopic":"sonoffs","OtaUrl":"http://thehackbox.org/tasmota/release/sonoff.bin","RestartReason":"Software/System restart","Uptime":"0T00:01:04","StartupUTC":"2019-01-15T18:25:02","Sleep":50,"BootCount":537,"SaveCount":734,"SaveAddress":"F6000"}}
19:26:06 MQT: stat/nfc/STATUS2 = {"StatusFWR":{"Version":"6.4.1.8(sonoff)","BuildDateTime":"2019-01-12T21:48:33","Boot":31,"Core":"2_4_2","SDK":"2.2.1(cfd48f3)"}}
19:26:06 MQT: stat/nfc/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["AirPort Extreme","Office AP"],"TelePeriod":300,"SetOption":["00008009","558180C0","00000000"]}}
19:26:06 MQT: stat/nfc/STATUS4 = {"StatusMEM":{"ProgramSize":540,"Free":460,"Heap":18,"ProgramFlashSize":1024,"FlashSize":1024,"FlashChipId":"144051","FlashMode":3,"Features":["00000809","0FDAE794","000383A0","23B617CE","00103BC0"]}}
19:26:06 MQT: stat/nfc/STATUS5 = {"StatusNET":{"Hostname":"NFC","IPAddress":"192.168.1.12","Gateway":"192.168.1.254","Subnetmask":"255.255.255.0","DNSServer":"192.168.1.31","Mac":"DC:4F:22:D1:8E:8B","Webserver":2,"WifiConfig":4}}
19:26:06 MQT: stat/nfc/STATUS6 = {"StatusMQT":{"MqttHost":"192.168.1.31","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_D18E8B","MqttUser":"connor","MqttType":1,"MAX_PACKET_SIZE":1000,"KEEPALIVE":15}}
19:26:06 MQT: stat/nfc/STATUS7 = {"StatusTIM":{"UTC":"Tue Jan 15 18:26:06 2019","Local":"Tue Jan 15 19:26:06 2019","StartDST":"Sun Mar 31 02:00:00 2019","EndDST":"Sun Oct 27 03:00:00 2019","Timezone":"+01:00","Sunrise":"08:38","Sunset":"17:20"}}
19:26:06 MQT: stat/nfc/STATUS10 = {"StatusSNS":{"Time":"2019-01-15T19:26:06"}}
19:26:06 MQT: stat/nfc/STATUS11 = {"StatusSTS":{"Time":"2019-01-15T19:26:06","Uptime":"0T00:01:04","Vcc":2.960,"SleepMode":"Dynamic","Sleep":0,"LoadAvg":999,"POWER":"ON","Dimmer":20,"Color":"003300","HSBColor":"120,100,20","Channel":[0,20,0],"Scheme":0,"Width":1,"Fade":"ON","Speed":2,"LedTable":"OFF","Wifi":{"AP":1,"SSId":"AirPort Extreme","BSSId":"88:1F:A1:34:8E:5C","Channel":1,"RSSI":42}}}

To Reproduce Scan different types of cards using the PN532

Expected behavior either no data displayed or valid JSON generated

Jason2866 commented 5 years ago

What kind of different types?

conphilpott commented 5 years ago

ISO 14443-3A NXP MIFARE Classic 1k - NfcA, MifareClassic, NdefFormattable (Some work) ISO 14443-4 NXP MIFARE DESFire / NXP MIFARE DESFire EV1 - IsoDep, NfcA, NdefFormattable (Doesn"t work)

Im using a clear adafruit fob with ISO 14443-3A NXP MIFARE Classic 1k - NfcA, MifareClassic, NdefFormattable and it doesnt work, generic fobs with the same specs do.

Just wondering if there is a way to turn off the data field as its just causing problems for me.

conphilpott commented 5 years ago

ISO 14443-3A NXP Mifare Ultralight (Ultralight C) - NfcA, MifareUltralight, NdefFormattable used to work on the last version i had but I upgraded to get the reader to stop entering the error state (didn't work)

andrethomas commented 5 years ago

Hi

I've made a PR which adds a definition to the my_user_config.h to enable use of the DATA functionality that is currently in the driver.

The reason is to segregate the UID functionality from the DATA functionality until I can get my hands on NFC cards which can reproduce the behaviour you're experiencing.

Thanks for reporting - much appreciated.

conphilpott commented 5 years ago

Cheers for the change 👍 Heres a link to the ultralight cards that i'm using and having issues with https://www.amazon.co.uk/dp/B07BB65HV9/ref=cm_sw_em_r_mt_dp_U_o5JpCbF5D6YB8

It also does the same thing with an Oyster card or ITSO Railway Keycard if that helps.

andrethomas commented 5 years ago

@Conphilpott PR https://github.com/arendst/Sonoff-Tasmota/pull/4943 has been merged so if you can now conditionally exclude the data functionality and will only have UID for now. Just pull the xsns_40_pn532.ino and just the changes in my_user_config.h

I did not think of checking the rail pass - I know I read them before but cannot remember what type they were... will check in the next few days if we are lucky then we can make that work also.

andrethomas commented 5 years ago

@Conphilpott

things like this are sent as JSON which make it unfriendly to decode. "DATA":"\x14\x01\x03\xe1\x03\xe1\x03\xe1\x03\xe1\x03\xe1\x03\xe1\x03\xe1\x03"

Just curious - this is obviously data that is already stored on block 1

Have you tried setting the DATA to something new using either

Sensor40 E to erase the DATA block

or

Sensor40 S,TEST to set the DATA block to contain "TEST"

?

conphilpott commented 5 years ago

I didn't try that no sorry , I've already reflashed and sealed the unit into a box though. I did erase the tag and format it with NFC Tools on Android and that made the data string longer.

andrethomas commented 5 years ago

Right, the driver expects characters within the normal text range so maybe the format just writes some predetermined bytes to block 1 which do not fall within the %s (string/char array) range - worth trying if you ever open it again, but don't sweat it as I am not 100% sure - just a hunch.

captFuture commented 5 years ago

I was just facing an issue with Sensor15 -> there has been a name change to the correct value Sensor40. getting Data works fine on all my mifare tags or cards, setting data is not working at all - it says "Data must be alphanumeric"

By the way - thank you for adding support for the PN532 reader, i was starting to implement this in my dev environment yesterday and stumbled over it today by accident :D

andrethomas commented 5 years ago

Data must be alphanumeric

i.e. A to Z and 0 to 9, no special characters like - etc

andrethomas commented 5 years ago

Just adding for reference - PR https://github.com/arendst/Sonoff-Tasmota/pull/5162 changed support for the PN532 from I2C to HSU (Serial Rx/Tx)

There was also a bug discovered by @Jason2866 which caused false errors for "Data must be alphanumeric" to be presented so that was also fixed earlier in the I2C version and the same methodology was carried through to the HSU version which is now merged into development.

olix74 commented 5 years ago

Hi, me again. I'm referring to my issue "PN532 HSU not working on ELECHOUSE card and WEMOS D1" again. I can't see the link to this issue, since in my case I had a problem with communication between PN532 board and Wemos/ESP8266 - not a wireless communication issue to the card. Anyway I changed code of xsns_40_pn532.ino to use I2C (merged from elechouse/PN532 repository) instead of HSU and now communication is working just fine. Bye the way, it looks like I2C was initialy supported and has just recently been changed to HSU? What was the reason you chenged from I2C to HSU? Thank you, Oliver

Jason2866 commented 5 years ago

I2C support was dropped because it wasnt 100% reliable and with serial processor load is much lower

denisvreshtazi commented 5 years ago

Hi Oliver, I wanted to ask if you resolved your problem and if you did can you please send me the code? Thank you Denis

andrethomas commented 5 years ago

Support for I2C was dropped as indicated by @Jason2866

From experience, we noticed that the ESP8266 cores (whether it emanates from the SDK or the core is not certain) have issues with chips that require clock stretching. This appears to affect certain i2c sensors/chips and unfortunately, the PN532 seems to be one of them.

The original code is kept here for posterity purposes so you're welcome to play with it but as the HSU interface provided by the PN532 solved the problem it is not likely to be re-introduced into development.

Edit: I must have been half asleep when I wrote this :)

LeandroGi commented 5 years ago

Hi, i m trying to configure pn532 with wemos d1 mini using tasmota firmware. FIRST TRY: i upgraded with release sonoff-sensors.bin v6.5 SECOND TRY: i compiled my own binary following steps on https://github.com/arendst/Sonoff-Tasmota/wiki/PN532

in both cases i did the following:

i dont get detection message on my console 00:00:00 NFC: PN532 NFC Reader detected

am i missing something? thank you!

andrethomas commented 5 years ago

Make sure you don't have anything else connected to the serial interface... like the usb cable you used to flash the wemos.

Use the web console...

LeandroGi commented 5 years ago

Make sure you don't have anything else connected to the serial interface... like the usb cable you used to flash the wemos.

thank you for your reply i m using usb alimentation connected to a phone 5V battery charger.

andrethomas commented 5 years ago

Also, make sure you disabled serial logging using seriallog 0 to disable any data from being sent out the serial interface but I can't remember this being an issue for me or not - I may have disabled it without giving it much thought.

Other than that it should just work according to how it is outlined in the wiki https://github.com/arendst/Sonoff-Tasmota/wiki/PN532

LeandroGi commented 5 years ago

i put some log command into _xsns_40pn532.ino. checking the console, the code stops at line 72 if(PN532_Serial->hardwareSerial()){ClaimSerial();} i am powering pn532 with 3.3v from wemos.

EDIT: i was wrong. it stops at line 75

uint32_t ver = PN532_getFirmwareVersion();
      if (ver) {
andrethomas commented 5 years ago

i am powering pn532 with 3.3v from wemos.

That could be a problem - The on board regulators on the wemos mini's are known not to be able to deliver a high amount of current.

So you have two options.

  1. Power it from 5V through its own regulator to 3.3V using a LD1117-3.3 or equivalent.
  2. If the PN532 board has an on board 5V to 3.3V regulator you can power it directly from the 5V rail on the wemos. Mine has one and I played with both 5V and 3.3V and both worked.
LeandroGi commented 5 years ago

2. If the PN532 board has an on board 5V to 3.3V regulator you can power it directly from the 5V rail on the wemos. Mine has one and I played with both 5V and 3.3V and both worked.

mine is not working in both cases! after uploading i set back #define CFG_HOLDER 4617 to the original value Im using a ELECHOUSE pn532 board, as in the case that @olix74 reported.

i tested the nfc module on a arduino mega using https://github.com/Seeed-Studio/PN532 the module has been recognized with .getFirmwareVersion()

Jason2866 commented 5 years ago

So it seems the ELECTHOUSE board is not compatible.

ascillato2 commented 5 years ago

Closing this issue as several cards are supprted.

Thanks everyone for working on this :+1:

FrancYescO commented 3 years ago

i've also an ELECHOUSE (no T in the name) NFC MODULE V3, with a sample code on an arduino is working, but seems there is no way to get it recognized from my D1 and Tasmota (no detection message in console, and tags not detected)... wiring and config are as explained https://tasmota.github.io/docs/PN532/

So we should consider this board not usable?

Jason2866 commented 3 years ago

Yes, Elechouse board is not working with Tasmota

FrancYescO commented 3 years ago

:( ok probably need to go via ESPHome as this guy is using same board https://www.youtube.com/watch?v=YqwRppUsFIQ and looks working with esphome

tremichl commented 2 years ago

Is there a recommendation for a working board? They are all looking similar to the board shown at the wiki. Some have printed ELECHOUSE some not...

Jason2866 commented 2 years ago

image Try to find one where the serial connections are easy available (as above) Most of the bought ones not saying elechouse do work

matteodallefeste commented 2 years ago

I think the picture in the tutorial may confuse users because to enable the HSU the position of the switches in the picture must be to the left as in the attached picture. I tried this tutorial and it worked with a device marked Elechouse. Tasmota v12.1.1 on esp32 s2 mini board pins 2 and 3 for tx/rx Screenshot_20220831-075101

barbudor commented 2 years ago

@matteodallefeste you are welcome to update the photo and the text in the docs