Here’s how to share data from Particle Gen 3 devices using Bluetooth or NFC

Gen3 NFC does not read anything as there is no “incoming message” capability. The callback only handles the NFC events. From the docs:

NFC (Near-Field Communication) is typically used to communicate small amounts of data to a mobile app in very close range, within a few inches.

Particle Gen 3 devices only support emulating an NFC tag. They cannot locate or communicate with tags themselves, or support protocols such as for NFC payments.

1 Like

Is reading data from a NFC phone is the works or did I just wait a year and half some something that will never work?

@magchecks, you can read FROM the Gen3 device WITH an NFC-capable phone. You cannot Read FROM an NFC-capable phone WITH a Gen3 device.

Where can i find a comparison between thread and BLE? Why prefer one over another? Specifically when aiming for a low power product?

Very cool post, @bsatrom , thank you!

One thing I am not 100% clear is this formula. Where is the 4.7 coming from?

battVoltage = analogRead(BATT) * 0.0011224 / 4.7 * 100;

I’ve seen the 0.0011224 factor coming up in other threads, but first time I see the 4.7.
Thanks!
Gustavo.

Thanks @gusgonnet you caught a typo! Should be 3.7 not 4.7. Assuming a 3.7 v Lipo, that * 100 gives me a (rough) % of the batt.

1 Like

super, that explains, thanks!

Nice tutorial @bsatrom !

I’m curious about what would it take to send the battery voltage and SOC broadcast out over BLE UART so you can view the data using the Adafruit Bluefruit app or the Nordic App using their UART reader.

I tried @rickkas7 UART code in the BLE tutorials but the Devices do not show up as UART enabled after I run that code like it does when I run the BLE Logging Tutorial code.

I basically want to be able to broadcast variables over BLE using the BLE UART service.

Thanks @RWB! Are you referring to the “UART Peripheral” sample as the one not working for you? Are you looking to do bi-directional UART between your peripheral and central devices so the central can trigger a voltage read on a peripheral, or just have the peripheral broadcast on an interval?

I’m basically just wanting to see code that boardcast the Battery Voltage & SOC over the BLE UART so I can see that data show up as it’s boradcast over BLE on the Adafruit Bluefruit App.

Then I could take that example code and throw different variables in there to broadcast.

Does that make sense?

Question about NFC - when I read the original blurb about what was supported I understood that it could not power an ariel loop for a passive tag. I didn’t appreciate that the NFC communication is only one way, i.e. from the Gen3 device (acting as a tag) to a NFC reader - a mobile phone app. Could someone explain a bit more about the NFC events?

Turn NFC on, optionally with a callback function.

// PROTOTYPE
int on(nfc_event_callback_t cb=nullptr);

The callback function has this prototype:

void nfcCallback(nfc_event_type_t type, nfc_event_t* event, void* context);
  • type The type of event (described below)
  • event The internal event structure (not currently used)
  • context An optional context pointer set when the callback is registered (not currently used).

The event types are:

  • NFC_EVENT_FIELD_ON NFC tag has detected external NFC field and was selected by an NFC polling device.
  • NFC_EVENT_FIELD_OFF External NFC field has been removed.
  • NFC_EVENT_READ NFC polling device has read all tag data.

Using the example that @bsatrom created I only ever get an event NFC_EVENT_FIELD_ON - which turns on the LED on D7 and NFC_EVENT_READ which enables the next reading of the battery level. Do I have to call NFC.off(); to get the NFC_EVENT_FIELD_OFF event? @ScruffR referred to callback being able to collect data, i.e. for the NFC Reader to write to the tag?

2 Likes

Hey @armor, happy to provide a bit more context. The NFC_EVENT_FIELD_OFF even should fire whenever the reader (phone) moves out of range of the tag. Calling NFC.off() turns of tag emulation on the Particle device, so you wouldn’t need to call it in that case. Are you not seeing the OFF event fire when you move your phone out of range?

Correct - the D7 LED only lights when phone near antenna and is scanned. Moving the phone away does not turn off the LED. I am using an iphone and NFC Tag app - NFC Reader behaves the same way.

Should there be a callback when there is no reader present? Wouldn’t this need some sort of active check?

Also, not being able to get any data from the mobile device (some ID?) when it has scanned the tag is really disappointing. Are you able to point me to the NFC specification?

Hey @armor I’ll pull my NDC Demo device back out and test, but as far as I understand it, its not an active check on the part of the NFC tag (which must be passive, per spec) but rather the removal of the magnetic field generated by the reader (phone) that triggered the data exchange.

As for getting data from the mobile device, to my knowledge, this is a limitation of the NFC-A design. The active device is a polling device that pulls information from a passive tag. By design, there is no capability to send information to the tag when polling. If you’re looking for something more bidirectional, I think BLE is a better fit.

I don’t have a copy of the NFC Spec, but the Nordic dev center has some additional info that may prove useful: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v14.0.0%2Fexamples_nfc.html

Thanks - the NFC UART Example is the one I would really like to see working!

The nordic documents definitely say the LED should go off when the polling device is moved away!

I would like to see the BLE UART data stream example also so we can connect via another device via BLE Serial app and see the data updates as they update.

I thought the BLE UART was working?

It does work, it’s just the example does not show a simple way for a beginner to understand how to pass different variables into the data that is broadcast out over the BLE UART link. The example shows system log info being broadcast and it’s hard for me to decipher how to modify it send out different variable data.

I think rick is working on a Web BLE example that would allow us to see this info without a need for a BLE Serial app which is ideal in my opinion since it does not rely on a Serial BLE data application but a Chrome web browser instead which can run on just about anything.
.

To understand how it could be done, you’d need to understand what datatypes fundamentally are and transferring binary datatypes between two platforms would require the two sides to agree on a particular endianness (just to name one).
To rid yourself from that need the common strategy is to use an “intermediate” format both sides do agree on by definition - one such format is text optionally with higher level conventions like JSON.

2 Likes

@RWB, this is a fair comment. I myself have hit the wall a few times adapting the existing examples to use non-numeric data types, so I agree that there’s an opportunity to create some basic content that really digs into how to properly format various types of data for BLE communication.

If you think it would be useful, I can probably add a blog post of some additional docs to my upcoming list.