In Need Of An NFC Guru...

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Googie85
Posts: 199
Joined: Tue Aug 05, 2014 10:07 am

In Need Of An NFC Guru...

Post by Googie85 » Sat Jun 05, 2021 8:39 am

Hiii Guys!

I am trying to read the "ndef" records on an NFC Card (I have 2 Cards and an NFC Ring with 2 Tags inbuilt. So 4 in total). I have the following code:

Code: Select all

on openStack
   
   get mobileIsNFCEnabled()
   if mobileIsNFCEnabled() is "true" then 
      answer "Device NFC has been turned on"
   end if
   
   
   get mobileIsNFCAvailable()
   if mobileIsNFCAvailable() is "true" then 
      answer "NFC tags can be read"
   end if
   
      mobileEnableNFCDispatch

   end openStack
   
   on nfcTagReceived pTag
               
      put pTag["id"] into tID
      put pTag["ndef"]["payload"] into tData
      answer tID
      answer tData

   end nfcTagReceived
The "tData" variable is always empty with no result at all when trying to read the "ndef" portion on the NFC Cards.

I have tried writing many different changes with NFC Writing Apps in the Google Play Store on my Android device with no luck...

Am I doing something wrong with my above code? Any help is greatly appreciated!!

Many Thanks,

Googie.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9250
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: In Need Of An NFC Guru...

Post by richmond62 » Sat Jun 05, 2021 9:37 am

What is an 'NFC'?

As far as I know, it is generally "the done thing" to define an acronym when using it for the first time.

Googie85
Posts: 199
Joined: Tue Aug 05, 2014 10:07 am

Re: In Need Of An NFC Guru...

Post by Googie85 » Sat Jun 05, 2021 10:01 am

I don't understand....

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: In Need Of An NFC Guru...

Post by bogs » Sat Jun 05, 2021 10:41 am

Googie85 wrote:
Sat Jun 05, 2021 10:01 am
I don't understand....
@Richmond, Yes, if Googie85 were posting this to the general population, defining it would be nice, but they posted for a "Guru", and a guru should know.
The list of NFC commands can be seen in the dictionary, but to answer your question, NFC stands for Near Field Communication on a mobile device, to my mind, similarly to how blue tooth works.

@Googie85, I'm not an expert (or even a green raw recruit) in mobile, so I'm not sure that this is the answer to your question, but on reading your code,

Code: Select all

put pTag["ndef"]["payload"] into tData
it looks to me like you are creating an array, and then trying to "answer" that array. That isn't going to work, you'd have to either combine the array, or answer the [key] and [value] separately.

In the IDE, open the messagebox and type in the multiLine pane:

Code: Select all

put "apple" into tArray[1]
put "carrot" into tArray[1]
answer tArray
You'll get a blank answer back, but if you change it by adding "combine tArray with return and tab", you should see your keys, then a space and your values. I changed the keys to "fruit" and "vegetable" so it is more like your code example:

Code: Select all

put "apple" into tArray["fruit"]
put "carrot" into tArray["vegetable"]
combine tArray with return and tab
answer tArray
You should now see the information you put in.

Good luck :)
Image

Googie85
Posts: 199
Joined: Tue Aug 05, 2014 10:07 am

Re: In Need Of An NFC Guru...

Post by Googie85 » Sat Jun 05, 2021 11:18 am

Thanks so much for your reply!!! It worked!!!

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: In Need Of An NFC Guru...

Post by bogs » Sat Jun 05, 2021 11:22 am

Glad to hear it helped Googie85 :)
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: In Need Of An NFC Guru...

Post by jacque » Sat Jun 05, 2021 6:07 pm

It's actually LC that creates the array, which is returned when a scan is done. To get the payload, you need to reference the number of the tag data (you have two per tag in this case) and then get the payload for that numerical entry. You can do that by asking for the correctly indexed entry when you read the tag. No need to combine the array, just request the part you need.

To get the payload for the first data block:

Code: Select all

put pTag["ndef"][1]["payload"] into tData 
Change the 1 to a 2 to get the second payload.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: In Need Of An NFC Guru...

Post by bogs » Sat Jun 05, 2021 9:11 pm

See? That was what you really needed, someone who knows what's being returned to begin with :D
jacque wrote:
Sat Jun 05, 2021 6:07 pm
No need to combine the array
Sure, if you know the keys your looking at and which one you want, I agree, but the way Googie85 put it, sounded to me like they wanted to see the entire array...
Googie85 wrote:
Sat Jun 05, 2021 8:39 am
I am trying to read the "ndef" records on an NFC Card

...and...

Code: Select all

   
    put pTag["ndef"]["payload"] into tData
    answer tData
Certainly if that is the case, and they want to read the whole thing in an answer dialog, there are 2 sure ways to go, either a return loop that puts the key, then the data, into a variable that you then answer, or combine it {as far as I know}. I just pointed them at what I think is the easier of the two.
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: In Need Of An NFC Guru...

Post by jacque » Sat Jun 05, 2021 11:40 pm

@bogs, you're right if he really wants the whole data set. It wasn't clear to me what the goal was. In my app I knew the exact bit I was looking for so it was quicker to just grab that.

Many ways to skin an LC cat.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: In Need Of An NFC Guru...

Post by bogs » Sun Jun 06, 2021 9:07 am

jacque wrote:
Sat Jun 05, 2021 11:40 pm
It wasn't clear to me what the goal was.
Me either heh, but at least they know what they are working with for sure :D
Image

Post Reply

Return to “Android Deployment”