w3c / web-nfc

Web NFC
https://w3c.github.io/web-nfc/
Other
310 stars 68 forks source link

Read record from RFID card string UUID via nfc scan reader #653

Open ankitraut05 opened 1 year ago

ankitraut05 commented 1 year ago

#WebNFC I am using Web NFC in my project. i coming difficulties to read values from RFID card through scan card on nfc reader in Web application. can you help me for how to read hexadecimal, decimal (UUID) from RFID card.

beaufortfrancois commented 1 year ago

Can you share the model of the NFC device and some of your code so that we can help you? Do you get at least one NDEF record when you try https://googlechrome.github.io/samples/web-nfc/?

ankitraut05 commented 1 year ago

Hi,

I am using Sunmi V2 pro device. I created a small html page and wrote javascript code. and i scan rfid card through NFC device. Can you help me to read the hexadecimal, decimal (UUID) from the RFID card?

Thanks, Ankit Raut.

On Mon, Feb 20, 2023 at 1:49 PM François Beaufort @.***> wrote:

Can you share the model of the NFC device and some of your code so that we can help you? Do you get at least one NDEF record when you try https://googlechrome.github.io/samples/web-nfc/?

— Reply to this email directly, view it on GitHub https://github.com/w3c/web-nfc/issues/653#issuecomment-1436529453, or unsubscribe https://github.com/notifications/unsubscribe-auth/A57W2VK4HTTKWUDHTFXW7SLWYMSINANCNFSM6AAAAAAVA2OIHQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks & Regards,

Ankit N. Raut. Contact : +91-9764210234

beaufortfrancois commented 1 year ago

Can you share a screenshot of what kind of results you get?

ankitraut05 commented 1 year ago

PFA.

On Mon, Feb 20, 2023 at 3:19 PM François Beaufort @.***> wrote:

Can you share a screenshot of what kind of results you get?

— Reply to this email directly, view it on GitHub https://github.com/w3c/web-nfc/issues/653#issuecomment-1436651506, or unsubscribe https://github.com/notifications/unsubscribe-auth/A57W2VM2MZFZIJRULE4JEVDWYM425ANCNFSM6AAAAAAVA2OIHQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks & Regards,

Ankit N. Raut. Contact : +91-9764210234

beaufortfrancois commented 1 year ago

You may want to use GitHub website interface to upload the screenshot.

image

ankitraut05 commented 1 year ago

WebAppwithNFC

Open this link and see

beaufortfrancois commented 1 year ago

Thank you! Now, where's the value you're trying to read? It looks like you only have one NDEF record for now. If you wanted to write an hexadecimal value for instance, you could do something like below:

const ndef = new NDEFReader();
await ndef.write(0x1234);

And for reading it, you could do:

const textDecoder = new TextDecoder(record.encoding);
const text = textDecoder.decode(record.data);
console.log(text.toString(16));  // 1234
}

FYI https://developer.chrome.com/articles/nfc/#read-and-write-a-text-record contains plenty of code examples.

ankitraut05 commented 1 year ago

When i write data to card the i getting message "Argh! Network Error : Failed to write due to an IO error : null"

Thanks, Ankit.

On Mon, Feb 20, 2023 at 4:15 PM François Beaufort @.***> wrote:

Thank you! Now, where's the value you're trying to read? It looks like you only have one NDED record for now. If you wanted to write an hexadecimal value for instance, you could do something like below:

const ndef = new NDEFReader();await ndef.write(0x1234);

And for reading it, you could do:

const textDecoder = new TextDecoder(record.encoding);const text = textDecoder.decode(record.data);console.log(text.toString(16)); // 1234}

FYI https://developer.chrome.com/articles/nfc/#read-and-write-a-text-record contains plenty of code examples.

— Reply to this email directly, view it on GitHub https://github.com/w3c/web-nfc/issues/653#issuecomment-1436730938, or unsubscribe https://github.com/notifications/unsubscribe-auth/A57W2VIWFBUDKTJP6DB5P7LWYNDLNANCNFSM6AAAAAAVA2OIHQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks & Regards,

Ankit N. Raut. Contact : +91-9764210234

beaufortfrancois commented 1 year ago

Then it means you can't write to this device right? Can you copy/paste the result of NDEF records you successfully read?

ankitraut05 commented 1 year ago

Hi,

NDEF Record successfully read on device and running properly.

Can i running NDEF record without https.means can i run on http.

On Mon, Feb 20, 2023 at 5:13 PM François Beaufort @.***> wrote:

Then it means you can't write to this device right? Can you copy/paste the result of NDEF records you successfully read?

— Reply to this email directly, view it on GitHub https://github.com/w3c/web-nfc/issues/653#issuecomment-1436830721, or unsubscribe https://github.com/notifications/unsubscribe-auth/A57W2VO3ENRDT7OK7TCSY6DWYNKELANCNFSM6AAAAAAVA2OIHQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks & Regards,

Ankit N. Raut. Contact : +91-9764210234

eklem commented 1 year ago

It's only available in secure context, @ankitraut05 I'm guessing every production environment should be https, but it makes it a bit more difficult when developing.

I'm using VSCode and using Ngrok and Live Server to make it work when developing. Just a little work the first time, and then it works smoothly. Here's a little bit more about the setup I use.