Phonegap NFC reader

  

Greetings,

I'm using Phonegap NFC module to use NFC, and I founded an application where the plugin has been used successfully and it works also on my application, however, I have two issue which I'm not able to resolve and seeking bit on advice as I'm not familiar with JavaScripts. Goal is to get hexa output by reading NFC bagde ID

1. Currently, output comes with bytes when I read NFC badge (some of those are negative, so, for example, I'm receiving 75,-28,-101,-82 which I need an hexa)

2. I don't get where in Java script it has been defined which variable it is storing this value, as I can see it comes there, but I can't find any reference to that

Below working JS

function onListen(callback, data) {
    if (data && data.tag)
    {
       callback(data.tag.id.toString());
    }
}

function startNFC(callback) {
    if (nfc) {
        nfc.addTagDiscoveredListener(function(data) { onListen(callback, data); }, function(b) { console.log('OK'); }, function(c) { console.log('NOK'); })
    }
    else
        console.log('No NFC plugin');
}

Also, I founded this advice how to convert this one to hexa but how to implement it, that is the challenge for me.

https://stackoverflow.com/questions/10708614/is-it-possible-to-read-nfc-tag-uid-with-phonegap-how

Merry Xmas and appreciated all the help!


Hi Marcus,

Did you have a look at the following forge component?

https://www.outsystems.com/forge/component/1454/nfc-plugin/

This plugin encapsulates the functionalities available on https://github.com/OutSystems/phonegap-nfc, providing an easy to use set of client actions and web blocks.

Hope it helps you!

Thanks Daniel,

I have gone through that code and problem is that is using NDEFListener when I'm using TagListener from phonegap. So I won't be able to record UID with that plugin, however, in forge there is an application called MyBreeze and in that, there is a plugin which is working, only issue is that output is byte array, and I would need to get it somehow as hexa.

Solution

Hi Markus,


So i would suggest to adapt your code to:

function onListen(callback, data) {
    if (data && data.tag)
    {
     var tag = data.tag;
     var tagId = nfc.bytesToHexString(tag.id);
       callback(tagId);
    }
}


That way the callback will receive the tag with Hexadecimal string.


Let me know if your worked.

Solution

Working! Only change what I did on that was nfc.bytesToHexString(tag.id). 

Thank you so much!



You are welcome!

Glad it worked!

Hi Markus and Daniel,

I also need this feature, and i'm trying to use the breeze app, but i does not work. 

I already try:

I've generate native apps for android and IOS, but does not work. 

Can you share a working module or help me to understand what i'm doing wrong? 

Attached you will find my modules.

Thank you in advanced.

Carlos Rodrigues wrote:

Hi Markus and Daniel,

I also need this feature, and i'm trying to use the breeze app, but i does not work. 

I already try:

I've generate native apps for android and IOS, but does not work. 

Can you share a working module or help me to understand what i'm doing wrong? 

Attached you will find my modules.

Thank you in advanced.

Hi Carlos,

I had an issue with that NFC plugin as well but first, what information you are trying to read from tag and type of NFC tag you are using e.g. Mifare?


Markus