Home › Forums › Ask the Flomies › ACR35-A1 iOS Read/Write Sample
Tagged: ACR35, iOS, NDEF, Writing NFC
-
AuthorPosts
-
March 27, 2017 at 7:29 am #59068
I recently purchased a couple ACR35-A1’s for a project that will need to read and write NFC. In looking through the documentation on the site I am only seeing sample code for reading tags. Where can I find information/documentation/code on writing tags?
Cheers
-KB- This topic was modified 7 years, 9 months ago by Keith.
March 27, 2017 at 7:35 am #59070Hi Keith,
We currently do not support writing to tags so documentation is very limited (we are working to provide lots more documentation soon). Writing to tags is something we are looking to add to the SDK and facilitate further in the future.
What tags are you using? I would have to refer you to the specs to get information on what APDU commands you would need to send to read blocks of bytes from the tag. I can help you get up and going with this endeavour.
Kind Regards,
ScottMarch 27, 2017 at 9:31 am #59071Hey Scott,
We typically use NTAG213. Are you saying writing is not possible at all or that it would just require to code directly against the Flomio hardware instead of using the SDK?
March 27, 2017 at 9:46 am #59072You can still use the SDK to write tags.
To clarify, you may already be aware of this, but to read / write data you need to send APDU commands to tags. Within the SDK we manage sending APDUs when reading data to provide customers with easy to use functions for an array of readers and tags. For writing data, you can use the SDK to write, but you would need to manage the sending of APDUs yourself.You would use the method
- (void)sendApdu:(NSString *)apdu toDevice:(NSString *)deviceSerialNumber;
to write to the tag.Sorry for the lack of documentation on writing to tags. If you have any questions on the above info, please let me know.
Kind Regards,
ScottMarch 31, 2017 at 10:08 am #59110Scott,
So I have sendApdu hooked up to a button. I am passing a simple GUID string and the correct device Id but nothing appears to be happening. Any assistance would be greatly appreciated.March 31, 2017 at 11:32 am #59111Hi Keith,
A few questions to help me get an idea about your problem.
Is there any logs in the console? Have you tested the tag in the Flomio Test app? Is the MSR light green?Kind Regards,
ScottApril 1, 2017 at 10:38 am #59126Nothing in the log. I have tested the tag in the Flomio Test app as well as a PoC app that I created. The light is green.
April 1, 2017 at 11:16 am #59127Here is a link to the repo for the project: https://github.com/kburnell/FlomioPoC
April 4, 2017 at 11:03 am #59178Bump^^ Scott, any help would be greatly appreciated!
April 4, 2017 at 5:08 pm #59200Hi Keith, Scott is out of the office this week so I will try to help. I looked over your Swift code and everything seems in order. However, before getting into code let’s make sure the Flomio Test app is working for you.
You should launch the app, select FloJack MSR (ACR35) and see the reader detected and listed at the top of the screen. The reader LED should illuminate green and stay on for more than 30 seconds. If it goes off while in the FloJack MSR device view then something it wrong with the audio communication between the host and the reader.
You may need to raise the volume on your phone to the max to correct this. You may also need to kill any apps running in the background that may be interfering with the audio (Pandora, Spotify, etc). Finally you may need to make sure the unit is fully charged (red LED goes on during charging and off when completely charged).
hope that helps,
RichardApril 6, 2017 at 8:20 am #59223Hello Richard,
Thanks for getting back to me. I have confirmed that the Flomio test app is working. What are the next steps to trouble shooting my issues?April 6, 2017 at 1:03 pm #59226Hi Keith, if the Flomio Test app is working then the issue is with your sample app code or the Flomio SDK library itself. Scott is our Swift resident expert so we’ll have to wait for him to get back from holiday to look through your code. In the meantime, can you confirm that you followed README_swift.md instructions in the SDK bundle as gisted here??
https://gist.github.com/grundyoso/aff3b458f24cf6972bdaf985566cc202
best,
RichardApril 11, 2017 at 7:37 am #59264From what I can tell my stuff matches what is in the README_swift.md. Again, any assistance would be greatly appreciated.
April 11, 2017 at 7:43 am #59265Hi Keith,
Weird, it’s working for me on my iPhone. It is even finding NDEF payloads of an Mifare Ultralight tag using the Flojack MSR. I saw that you are targeting an iPad… I don’t have an iPad to test with, that’s the only thing I changed in the app.
Kind Regards,
ScottApril 11, 2017 at 7:44 am #59266Is the write working for you as well? I am able to read w/out issue but not able to write.
April 11, 2017 at 7:53 am #59267I will check that now and get back to you.
The audiojack readers have always been a pain to write because of the constant polling needed. An alternative would be to use the FloBLE Plus, we have successfully used the FloBLE Plus to write.
I may be able to find a suitable solution using the Flojack MSR, I will have info for you in a few hours.Kind Regards,
ScottApril 11, 2017 at 11:45 am #59268Hi Keith,
I have tested your code for writing and it showed that you were setting the DeviceId in the wrong delegate method. You are using the ‘ReadData’ option so “didFindTag:withData” is where you would get delegate responses. But really didUpdateConnectedDevices is where you should set your deviceId parameter.
func didUpdateConnectedDevices(_ devices: [Any]!) { let fmDevices = devices as! [FmDevice] theDeviceId = fmDevices[0].serialNumber }
Here is an updated SDK for you to try, it removes some errors that can happen when writing tags. Let me know how you get on.
Kind Regards,
ScottApril 16, 2017 at 10:56 am #59343Scott,
I updated the SDK and and make the change you suggested above regarding setting “theDeviceId” but write is still not working.I have confirmed that the tags I am using are writeable using a Windows Phone with built in NFC reader/writer.
Can you walk me through how to write the tag from the Flomio Test app?
If you have a working project with source with write functionality that you could provide that would be greatly appreciated.
Also, I am unable to run the Flomio Test app. I get a dialog that says “‘Test’ Beta Has Expired”
Thanks,
KeithApril 18, 2017 at 8:59 am #59363First we should test using the Flomio Test App to confirm that the tags are usable with the FloJack MSR. That should now be available via the Test Flight app, please let me know if this is not the case. I don’t have any NTAG213 to test the FloJack MSR with them so I cannot confirm whether it will work.
Your source code works fine and I was able to use it to write to a Mifare Ultralight tag.Kind Regards,
ScottApril 18, 2017 at 9:42 am #59364Scott,
1 – I am still getting “Test” Beta Has Expired when trying to run the Flomio Test App2 – Could you please walk me through the steps for writing a tag and verifying the write from the Flomio Test App?
Thanks,
KeithApril 18, 2017 at 10:00 am #59365Hey Keith,
I have hopefully resolved that Flomio Test App issue for you.
Now, within the app you would click FloJack MSR, plug in your reader, and present the tag.
That’s the first step, if it shows a UUID and device info, then we can move forward.
~Scott
April 18, 2017 at 10:16 am #59366I am still seeing same message on my end when trying to open the Flomio Test App.
April 18, 2017 at 10:28 am #59367Maybe delete the app and reinstall it via Test Flight… I cannot reproduce this on my end. Apologies for this.
Kind Regards,
ScottApril 18, 2017 at 10:39 am #59368Deleted the app and clicked on the link from the original email TestFlight sent and it opens the TestFlight app and I see a message that says “No iOS Builds Available”
April 18, 2017 at 11:16 am #59369Got notification that 2.2 is available. Installed and running.
When I present the tag I get the
Tag detected: 04 C3 ... 90 00 from Device: F3...24
This has always worked.
April 18, 2017 at 11:37 am #59370Great.Now you can send APDUs to the reader using the send APDU button at the bottom of the page. This should allow you to write data to your tag. Is there any problem with this?
You should be able to read data by changing the setting to Read Data in the settings panel at the bottom of the app.
Scott
April 18, 2017 at 1:39 pm #59372Scott,
So I present the tag and then click send and I getTag detected: 04 ... 00 from Device: F39...24 Data detected: 01 ... ... ... 33 from Device: F39...24 No Ndef data found. Tag detected: 04 ... 00 from Device: F39...24
Then when I change it to “Read Data” and present the tag I get
Data detected: 01 ... ... ... 33 from Device: F39...24
How do I know if what I am telling it to write is what is actually written? I would expect it to write whatever is in the APDU text box and then read back the same thing.
April 18, 2017 at 1:49 pm #59373Hi Keith,
That’s good progress. You would have to present the tag while in ‘Read Data’ mode. This should give you all the data stored in the tag. Once you confirm that you can write to the tag one block to the tag, you can then begin trying to write multiple blocks within your code.
Scott
April 18, 2017 at 1:53 pm #59374When I do that should I see whatever is in the ADPU box that I wrote included in the data when I read it?
April 18, 2017 at 2:16 pm #59375Unfortunately not. You need to send the APDUs to speak directly with the cards in a specific format. For your tag, I think “FF D6 00
0X
04YY YY YY YY
” is the format, where X is the position of the data, and YY YY YY YY is the data itself. Where X is between 0-F (in hexadecimal). So to write the data 00 00 00 00 to block 05, you would send “FF D6 00 05 04 00 00 00 00”.
You would then iterate up the data blocks to send the specific blocks to their desired places.Scott
- This reply was modified 7 years, 8 months ago by Scott.
April 19, 2017 at 6:55 am #59478Wow that sounds painful. For the application I am hoping to use your hardware for I will need to write a string in the format {0}|{1}|{2} where {0} is a GUID and {1} and {2} are 1 – 50 character strings. How difficult is that going to be? Are there any samples available to assist?
Thanks,
KeithApril 19, 2017 at 10:35 am #59483It is quite painful, Keith, and without synchronous APDUs it will be more difficult.
A few suggestions, wait until v2.3 is released view synchronous APDUs, in the meantime here is a code to at least generate APDUs for each 4 bytes of data.int currentPage; int positionInEncodedString = 0; //offset between position in encodedDataString and data block in tag NSString* encodedDataString = "23 d1 01 1f 55 73 6d 73 3a 35 35 35 35 35 35 35 35 35 26 62 6f 64 79 3d 69 20 6c 6f 76 65 20 79 6f 75 FE" encodedDataString = [encodedDataString stringByReplacingOccurrencesOfString:@" " withString:@""]; // remove whitespace NSString *encodedHexStringWithTLVValues = [self addTLVValues:encodedDataString]; while (encodedHexStringWithTLVValues.length % 8 != 0){ encodedHexStringWithTLVValues = [encodedHexStringWithTLVValues stringByAppendingString:@"0"]; } for (FmDevice *device in connectedDevicesList) { BOOL isCorrectDeviceId = [[device serialNumber] isEqualToString:[deviceId uppercaseString]]; NSLog(@"isCorrectDeviceId: %@", [NSNumber numberWithBool:isCorrectDeviceId]); if ([[device serialNumber] isEqualToString:[deviceId uppercaseString]]) { for (currentPage = 4; currentPage*4 <= encodedHexStringWithTLVValues.length; currentPage+=1){ NSUInteger length = encodedHexStringWithTLVValues.length; NSLog(@"currentPage*4: %d", currentPage*4 ); NSLog(@"length %lu", (unsigned long)length); NSLog(@"currentPage: %@", [NSString stringWithFormat:@"%02X", currentPage]); NSString *next4BytesToWrite = [encodedHexStringWithTLVValues substringWithRange:NSMakeRange(positionInEncodedString, 8)]; NSLog(@"next4BytesToWrite: %@", next4BytesToWrite); NSString *apdu = [NSString stringWithFormat: @"FF D6 00 %02X 04 %@",currentPage, next4BytesToWrite]; positionInEncodedString+=8; int64_t delayInSeconds = 0.1; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [device sendApduCommand:apdu]; }); if ([next4BytesToWrite containsString:@"fe"]){ return; } } } } - (NSString *)addTLVValues: (NSString *)hexString { NSLog(@"encodedDataString: %@", hexString); NSString *tagString = @"03"; //null values and tag NSString *length = [NSString stringWithFormat:@"%02lX", hexString.length/2]; NSLog(@"lenght: %@", length); NSString *terminator = @"fe"; NSString *encodedHexStringWithTLVValues = [NSString stringWithFormat:@"%@%@%@%@",tagString,length,hexString,terminator]; NSLog(@"encodedHexStringWithTLVValues: %@", encodedHexStringWithTLVValues); return encodedHexStringWithTLVValues; }
Found here
You could also buy a FloBLE Plus along with downloading the free iOS app NFC Actions. This app comes with the feature to write NFC tags using the FloBLE Plus (we are aiming to add the MSR in the future but cannot guarantee a timeline).
Please let me know if you have any more questions.
Kind Regards,
ScottApril 19, 2017 at 11:15 am #59484Just to clarify, using your hardware and API I would need to write the tag data 4 bytes at a time? And that is only programmatic option?
-
AuthorPosts
You must be logged in to reply to this topic.