esprfid / esp-rfid

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

Pincode saved incorrectly in memory #641

Closed pvtex closed 3 weeks ago

pvtex commented 3 weeks 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 3 weeks 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 3 weeks 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 3 weeks ago

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

pvtex commented 3 weeks 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 3 weeks 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 3 weeks 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 3 weeks 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: