esprfid / esp-rfid

ESP8266 RFID (RC522, PN532, Wiegand, RDM6300) Access Control system featuring WebSocket, JSON, NTP Client, Javascript, SPIFFS
MIT License
1.37k stars 424 forks source link

Pincode saved incorrectly in memory #641

Closed pvtex closed 5 months ago

pvtex commented 5 months ago

the pincode of a user is not read succesfully. sometimes a pincode form an other user is shown. looking in the user files in the SPIFFS filesystem the pincodes are right.

image

in the filesystem:

{"command":"userfile","uid":"???????","pincode":"8721","user":"Bjoern","acctype":99,"acctype2":null,"acctype3":null,"acctype4":null,"validsince":0,"validuntil":2145916800}
pvtex commented 5 months ago

the pin that you enter in the user mask is active and can be used. but if you reload the user list all users are showing the same pincode of one random user.

pvtex commented 5 months ago

with debugoutputs i can see that the right pins are read in void ICACHE_FLASH_ATTR sendUserList

but on the way through serializeJson and ws to the browser it get lost

pvtex commented 5 months ago

the json opject item hold the right pincode. the jsonarray users has wrong pincodes.

pvtex commented 5 months ago

think i found the solution the variable pincode was declared as const char. const chars are used as pointers in nestedobject. cast pincode to a string should help

pvtex commented 5 months ago

had to change the file wsResponses.esp

line 28-32

String pincode = "";
if(json.containsKey("pincode"))
{
    pincode = String((const char*)json["pincode"]);
}
matjack1 commented 5 months ago

Thank you very much @pvtex for reporting this bug. I can confirm it.

The problem I think it's earlier than the lines highlighted in your last comment, unfortunately. I was able to reproduce the pincode corruption even by just updating manually a few of the pincodes. I'm going to fix this surely before v2 is done.

Sorry for this and thank you very much for reporting.

matjack1 commented 5 months ago

You were right @pvtex !

I've applied your fix and that's fine :) I'm going to close this as the fix is in dev.

Thank you :+1: