Jc.OpenNov
- Published on
As I've been working on developing GlucoPilot, we realised a need for a library to read data from NFC Novo Nordisk insulin pens. This led to the creation of Jc.OpenNov, a .NET library that provides a simple and efficient way to access the data stored on these pens.
The Problem
So when building an app to help people with diabetes track their data, how can we easily record insulin injections?
Sure, we can ask the user politely to log their injections manually, but that requires the user remembers and/or has the time to do so.
The Solution
It turns out the solution for this already exists in the form of insulin pens by Novo Nordisk that support NFC technology. The NovoPen 6 and NovoPen Echo Plus are both "smart insulin pens" that automatically record insulin dosing information about each injection so you don't have to.
These pens use NFC technology to communicate with compatible devices, allowing for seamless data transfer and integration into various diabetes management systems.
Building Jc.OpenNov
The trouble is, while I've had experience working with Android in .NET, I've never done anything with NFC. And to make matters worse, the company only shares data specs with registered developers that build health products, which would be us, except going by the fact Nightscout failed to get access, there's no way on earth we would...
Thankfully, there exists a comprehensive implementation in xDrip (written in Java) which was used to develop a library in Kotlin. The latter coming in especially useful as it provided me with a data file I could use to do test-driven development.
The Final Product
Finally, after around a week of tearing my hair out at times in debugging, the project is in an early release as it's finally usable within our GlucoPilot project.
Using it is currently as simple as doing something like:
MainActivity.NfcController = new NfcController(activity, action => action());
MainActivity.NfcController.MonitorNfc(
onDataRead: result =>
{
if (result is PenResult.Success success)
{
Debug.WriteLine("Data read: " + success.Data);
}
else if (result is PenResult.Failure failure)
{
Debug.WriteLine("Data read failed");
}
},
onTagDetected: tag =>
{
Debug.WriteLine("NFC tag detected: " + tag.GetId());
},
onDataSent: data =>
{
Debug.WriteLine("Data sent: " + BitConverter.ToString(data));
},
onDataReceived: data =>
{
Debug.WriteLine("Data received: " + BitConverter.ToString(data));
},
onError: exception =>
{
Debug.WriteLine("Error occurred: " + exception.Message);
},
stopCondition: (model, doses) => false);
The project currently only supports iOS, but the reading is de-coupled from the NFC, where the core project contains the logic for reading the data, and the NFC implementation is simply bolted on top.
I will be actively working on implementing iOS for GlucoPilot in the coming weeks/months.
The Code
The code is available on GitHub here.