Getting started with Open NFC emulator
Asked Answered
C

3

13

I would like to get started with developing NFC apps for android. I have started with android recently and I'm finding it a very interesting platform to develop for. Before I go out and invest in an Android device that has a built in NFC reader and purchase tags, I would like to get a feel of how one actually writes code for them.

I found the Open NFC Android emulator and it appears to be what I'm looking for. I have downloaded : 1. The Open NFC for Android 2. The Open NFC core Edition

After creating an avd that for Open NFC, I followed the instructions.

Now the problem that I face is that in the emulator, when I go to the Wireless Settings and then I enable NFC, It says that there was an error. I have tried setting the IP to 10.0.2.2 and also the IP that I get from ipconfig but to no avail. There's no log that I can see. Also I have tried to disable the firewall completely while running it so that it doesn't get blocked accidentally.

As a side note, I would like to mention that I have the Connection Manager Started before I launch the emulator.

Does anybody have experience with Open NFC for Android, If somebody can point me to a better set of instructions I'd be most grateful alternatively If someone could suggest another simulator by which I can try out some sample code and get a better understanding about NFC.

The output of the adb logcat is

W/KeyCharacterMap(  165): No keyboard for id 0
W/KeyCharacterMap(  165): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
D/NfcSettings(  165): onPreferenceChange: Setting NFC key: nfc_cc_ip
D/NfcSettings(  165): onPreferenceChange: Setting NFC value: 10.0.2.2
D/NfcSettings(  165): onPreferenceChange: Setting System NFC NFC_CC_IP: 10.0.2.2
D/NfcSettings(  165): onPreferenceChange: Setting NFC key: nfc_hal_mode_list
D/NfcSettings(  165): onPreferenceChange: Setting NFC value: 1
D/NfcSettings(  165): onPreferenceChange: Setting NFC mPreferenceNfcHalMode: SIMULATOR:1
D/NfcSettings(  165): onPreferenceChange: Setting System NFC NFC_HAL_MODE: 1
W/InputManagerService(   68): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@406df430
D/NfcEnabler(  165): Setting NFC enabled state to: true
D/OpenNFCService(  250): Enabling NFC.  previous =false
D/OpenNFCService(  250): mIsNfcEnabled NFC =false
D/OpenNFCService(  250): _enable =true
D/OpenNFCService(  250): IOpenNFCService:setNFCEnabled(true)
D/OpenNFCService(  250): Invalid IP address
D/OpenNFCService(  250): can't create configuration !
D/OpenNFCService(  250): updateNfcOnSetting: false
D/OpenNFCService(  250): NFC success of _enabletrue) is false
D/OpenNFCService(  250): $$$NFC$$$ Will connect ! $$$NFC$$$
W/NfcEnabler(  165): Error setting NFC enabled state to true

I get the same error when I change the IP to the one obtained with ipconfig.

D/NfcSettings(  165): onPreferenceChange: Setting NFC key: nfc_cc_ip
D/NfcSettings(  165): onPreferenceChange: Setting NFC value: 114.31.179.86
D/NfcSettings(  165): onPreferenceChange: Setting System NFC NFC_CC_IP: 114.31.179.86
D/NfcEnabler(  165): Setting NFC enabled state to: true
D/OpenNFCService(  250): Enabling NFC.  previous =false
D/OpenNFCService(  250): mIsNfcEnabled NFC =false
D/OpenNFCService(  250): _enable =true
D/OpenNFCService(  250): IOpenNFCService:setNFCEnabled(true)
D/OpenNFCService(  250): Invalid IP address
D/OpenNFCService(  250): can't create configuration !
D/OpenNFCService(  250): updateNfcOnSetting: false
D/OpenNFCService(  250): NFC success of _enabletrue) is false
D/OpenNFCService(  250): $$$NFC$$$ Will connect ! $$$NFC$$$
W/NfcEnabler(  165): Error setting NFC enabled state to true
Carraway answered 20/7, 2011 at 3:31 Comment(3)
As you're asking about a programming tool, this question would likely be better served at Stack Overflow.Iconology
@Carraway How did you create an AVD with Open NFC? Even I have downloaded the Open NFC for Android. I have added that as an Add-on in my Android SDK folder. After that I don't how to make the changes in my Android Studio so that I can use the emulator in my Android application. Can you please help me with this?Retral
It seems open nfc is discontinued. There is only a sourceforge repository left and the domain www.open-nfc.org seems to be offline.Luettaluevano
N
14

@nikhil: Thanks for the link to TCP Echo Server. I got my OpenNFC stack to work after running the echo server. So that other users can benefit from this exercise, here's a summary of what to do to set up the OpenNFC stack with the NFC controller (NFCC) simulator.

--The stack (with NFCC simulator) is supported on Windows host only, since both the Connection Center and the NFCC simulator are Windows apps.

--Need to download all 3 packages:

  1. OpenNFC Android SDK addon
  2. OpenNFC core Edition, which has the Connection Center and the NFCC simulator apps.
  3. The echo server: EchoTool

--Install the SDK addon, and create an AVD using the SDK Addon.

--start Connection Center (run "Connection Center.exe") and config it to accept client connections from other machines.

--start NFCC simulator (run "NfcSimulator.exe").

--start echo server (on port 7), using the cmd: echotool /p tcp /s 7

--start Android emulator using the AVD just created.

--from the emulator, select Settings->Wireless & networks->NFC settings

--enter 10.0.2.2 in IP Connection Center

--select Simulator for NFC HAL implementation

--now click the NFC toggle (check box) to start the NFC stack!

Nitro answered 4/8, 2011 at 16:20 Comment(7)
Excellent Step by step guide.Carraway
@nikhil: so I tried the sample program SampleManagerNFC and tried to read a tag. When the program prompts me to "present a tag", I selected PICOPASS_2K-Tg5_14443B3-R_1 virtual card from the Object List of the NFC controller Simulator. The protocol indicator (ISO 14443-B-3) did turn green. Messages in LogCat also indicates that a Tag is detected. However, it experienced a NULL pointer right after that. Full log is listed at pastebin.com/CZfsD4wJ. Do you have any luck with the sample program and the simulator?Nitro
No, the developers say that this release is buggy, Should hopefully be fixed in the next release.Carraway
how to start nfc emulator on ubuntuTishtisha
Hi @Nitro can you please tell me how to start echotool, I am not getting this line properly. start echo server (on port 7), using the cmd: echotool /p tcp /s 7Seibert
@Nitro The "/Open NFC 4.3.0 (108..n v4.3.0 (10877).zip" file could not be found or is not available. Please select another file. -- The "/Open NFC 4.3 beta (..n v4.3.0 (10381).zip" file could not be found or is not available. Please select another file.Becerra
[helpful link] (https://mcmap.net/q/430129/-how-install-the-open-nfc-add-on-in-my-android-sdk-environment) . one more issue. After adding the open_nfc to sdk - add-on, it isn't visible in sdk manager in Android studio.Becerra
N
1

I've experienced similar issues. Turns out that the Connection Center mentioned in the doc is a Windows app. This is from the developer at Inside: "The Connection Center is a tool released in binary form for Windows. You can find it, as well as the NFC simulator, in the Core Edition of Open NFC". I have my build environment (Eclipse) running on a Ubuntu host. So I am out of luck with this one. Are you also on a Linux host?

The Connection Center needs to be running for the NFC controller simulator to work, as indicated in the doc: "Prior launching the AVD, the Connection center must be launched and configured to accept client connections from other machines".

Anyways, after firing off logcat and it is clear from the debug messages that the Simulator cannot connect to the connection center. The following logcat output are collected after the NFC toggle button is clicked:

root@android:/ # logcat
D/NfcEnabler(  170): Setting NFC enabled state to: true
D/OpenNFCService(  273): Enabling NFC.  previous =false
D/OpenNFCService(  273): mIsNfcEnabled NFC =false
D/OpenNFCService(  273): _enable =true
D/OpenNFCService(  273): IOpenNFCService:setNFCEnabled(true)
D/NFCService(  273): Java_org_opennfc_service_Interface_OpenNFCServerStart
D/NFCService(  273): Java_org_opennfc_service_Interface_OpenNFCServerStart : Simulator has been selected
D/Microread(  273): static_nfcc_device_open
D/Microread(  273): static_nfcc_device_get_binding
E/SIMULATOR(  273): 00071 ERROR HAL   : GetNALBinding
E/CCCLIENT(  273): static_CCClientCreateSocket / connect() failed 111 
E/SIMULATOR(  273): 00072 WARN  HAL   : =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
E/SIMULATOR(  273): 
E/SIMULATOR(  273): 00073 WARN  HAL   : CANNOT CONNECT TO THE CONNECTION CENTER.
E/SIMULATOR(  273): 
E/SIMULATOR(  273): 00074 WARN  HAL   : SYMPTOM: Impossible to connect to the Connection Center
E/SIMULATOR(  273): 
E/SIMULATOR(  273): 00075 WARN  HAL   : DIAGNOSTIC: Connection Center not started, firewall, ...
E/SIMULATOR(  273):            Check Connection Center and your network configuration.
E/SIMULATOR(  273): 
D/SIMULATOR(  273): 00076 TRACE HAL   : =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
D/SIMULATOR(  273): 
E/SIMULATOR(  273): 00077 ERROR SIM   : static_NALBindingCreateFunction: Cannot create the com port
E/OPENNFC_SERVER(  273): 00031 ERROR NFC_HAL PNALServiceCreate: Error returned by the initialization of the NFC HAL
E/OPENNFC_SERVER(  273): 00032 ERROR EVENT : static_PContextCreate: Cannot create the NFC HAL Service
E/OPENNFC_SERVER(  273): 00033 ERROR STARTUP  BootNFCC : PDriverCreate() failed
E/NFCService(  273): Java_org_opennfc_service_Interface_OpenNFCServerStart: StartNFCC failed
E/OpenNFCService(  273): OpenNFCServerStart failed
D/OpenNFCService(  273): updateNfcOnSetting: false
D/OpenNFCService(  273): NFC success of _enabletrue) is false
D/OpenNFCService(  273): $$$NFC$$$ Will connect ! $$$NFC$$$
W/NfcEnabler(  170): Error setting NFC enabled state to true

The developer said that for this to work on a Linux host "you might have to set up a TCP echo server in parallel to the Connection Center on the machine to answer on port 7". I am not sure how it is done and what is required.

I suggest that you try the same set up on a Windows host, which is what I am going to do.

Nitro answered 21/7, 2011 at 20:30 Comment(1)
I am on a windows host and have finally had success in getting it to run after dropping in an email to the developers explaining the issue.Carraway
K
1

with the new versions of NFC Core, SDK, Connection Center, NFC Emulator and new image of Android Add-on is possible. I have tested and it works... Just chek out the page of the Open NFC Project and download the new versions of these things.

Kessinger answered 3/11, 2011 at 13:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.