NightscoutFoundation / xDrip

Nightscout version of xDrip+
https://jamorham.github.io/#xdrip-plus
GNU General Public License v3.0
1.4k stars 1.14k forks source link

Integrate Pendiq Pen 2.0 into xDrip? #239

Closed alwayssimifuzi closed 3 years ago

alwayssimifuzi commented 6 years ago

Is it possible to integrate Pendiq Pen to show Bolus?

jamorham commented 6 years ago

It may be possible, do you have one of these pens?

alwayssimifuzi commented 6 years ago

Yes I have one, since yesterday.

jamorham commented 6 years ago

I will contact the manufacturer about it in the first instance. Do you have any insights as to why their official app has only 1 star ratings?

alwayssimifuzi commented 6 years ago

The official App is very bad, isn't komfortable to write diary. A integration in xDrip would be very nice! Mysugr will be compatible with Pendiq in early 2018. (Website Info)

alwayssimifuzi commented 6 years ago

Do you have some news about that? Happy New Year!

ralf-ms commented 6 years ago

I'm also interested... would be nice having the bolus insulin units transferred automatically to xdrip.

jwoglom commented 6 years ago

Assuming the pen connects to the application using Bluetooth, it would likely be a matter of reverse-engineering the bluetooth communication between the two devices. Decompiling the Android app might help with this. If you or someone else with the pen has the technical know-how, then from there it'd just be a matter of putting the right plugs into Xdrip such that the boluses get added whenever the pen and phone pair. Probably would want to start with building a dummy Android app that does the necessary BT communication parsing as a step one.

jamorham commented 6 years ago

Get me one to borrow and there is a strong chance I can get it working like was done with the Verio meters and Contour next one.

ghost commented 6 years ago

1+ for the xdrip option, getting the pendiq injection data via bluetooth. @jamorham: Have you already got an instance of the device? Otherwise i could borrow you mine. Thanks al lot for this great software! Wolfgang

ghost commented 6 years ago

Any News for this topic? As I told, I may borrow my device To someone who may try to reverse engeneering the Bluetooth interface to communicate with xdrip.

jamorham commented 6 years ago

I am in the UK. Anyone in europe with one of these devices could post it to me without any problems with customs charges. I can return it after support is added but I can't guarantee what that time frame would be. If anyone is interested in loaning me one then please drop me an email jamorham at gmail and we can work it out.

alwayssimifuzi commented 6 years ago

I'll send it to him. :)

ghost commented 6 years ago

@alwayssimifuzi Have you allready sent your Pendiq to @jamorham? I also wrote him a message letting him know that I may borrow him mine, but didn't get a anser yet. So is this subject on its way already? @jamorham I realy would love to see this feature in xdrip+ and of course I'am willing to donate something for it. Please let me know how I can to value your great work!

alwayssimifuzi commented 6 years ago

Hey guys! The package is ready to send it to @jamorham I'll send it tomorrow with DHL!

ghost commented 6 years ago

Yes! Thanks for that.

jamorham commented 6 years ago

To help me better implement support for this. Can you guys briefly describe how you would use the Pendiq pens? Would you use one for long acting and one for short acting insulin? Would you have more than two active pens?

ralf-ms commented 6 years ago

I use it only for short acting insulin, due to my high sensitivity and because I don't need long acting (basal) insulin yet. If that were the case, I very likely would by a second one.

ghost commented 6 years ago

I also use it only with the fast insulin for now. Of hours it would be nice to get a second Pendiq for the basal insulin one day, so one could track the whole amount of working insulin. but that's not a high priority for me because its not a big thing to insert those two inputs a day manualy. THANK YOU!

jamorham commented 6 years ago

Ok, I am making progress with the loaned pen. It is complex though. I haven't seen protocols like this since the 1980's!

So far I can retrieve the last bolus time and amount and cartridge remaining units.

ralf-ms commented 6 years ago

That sounds promising! Last bolus amount and time are the most important data, the rest is (imho) just nice to have. Thanks a lot for your work!

ghost commented 6 years ago

@ralf-ms: yes, bolus and time are the most important things, but I think the whole bolus/time-history will be needed to read out the pendiq (yust recent last data is not enought imo.)… Any way great to hear that work is going on that fast. @jamorham: Please let me know how I can donate for your work.

ralf-ms commented 6 years ago

Agreed having a full history is desirable. But I fear that you could get duplicate entries if date/time is getting out of sync between pendiq and xdrip (eg think of forgetting to switch back from day light saving time to central time on your pendiq). To avoid this, xdrip should be able to update the time on the pendiq. And I don't know, if that is possible.

jamorham commented 6 years ago

I am making steady progress and working towards being able to read the full log history. I also expect to be able to make it so the pen can be woken up and a bolus amount pre-set. This has some interesting possibilities for example in combination with AndroidAPS in open-loop mode or using a bolus wizard or just as part of the treatment input in xDrip.

@sodesignberlin I will update my amazon wish list if you want to get me a technical book?

ralf-ms commented 6 years ago

@jamorham: You can add more than one to your wishlist... ;-)

jamorham commented 6 years ago

Okay, I can now set the pen time and I think properly account for timezone and daylight saving time when doing this.. I can make the pen wake up and prompt for the insulin treatment entry when a treatment is entered on xDrip.

I'm still having some issues getting historical log information beyond the most recent entry. I will keep working on this. Beyond that, the only issues are related to exactly how to integrate the driver in to xDrip. For example whether to attempt "always on" connection or to poll the pen periodically for new data.

Maintaining always on connection is going to be hard if there are multiple pens in play and even then its not so simple to make reliable.

I'm hoping to have something out for you guys by the weekend, fingers crossed.

jamorham commented 6 years ago

Ok history log solved!! I'm now wrapping it up in to a test implementation.

What will be missing from this initial implementation is that it wont periodically poll the pen. It will only do it when you open the xDrip home screen to sync the records.

I would like to iron out any issues with the implementation generally before looking at periodic polling or potentially always connected modes which are more complex to integrate in to the xDrip architecture.

ghost commented 6 years ago

conratulation and thankl you very much for your helpfull work. Iam exited how this will do.

ralf-ms commented 6 years ago

Great News! Can't wait to test it...!!! So far I've entered the insulin amount manually in xdrip. What will retrieving the history log via bluetooth do? Add the same entries again? Shall I start a new database in xdrip? Unfortunately there is no way of deleting the pen's memory (I've asked the pendiq-guys).
What do you advise?

jamorham commented 6 years ago

It will only sync records from the last 48 hours so if you stop entering them manually now then you should have minimum overlap.

ralf-ms commented 6 years ago

Perfect! Thank you!

ghost commented 6 years ago

Found the new experimentel Pendiq-section and activated it. But do I have to pare the two devices somehow? I left the pin as it was for now, but don't know how the sync should work.

ralf-ms commented 6 years ago

Where did you find this? Do you have engineering mode enabled? If so, then it might not be for us yet...

jamorham commented 6 years ago

So with an addition of ~2000 lines of code there is now the first level of support for the Pendiq 2.0 in the latest xDrip nightly!! (28th June version onwards)

To activate this, go to settings, and scroll right to the bottom for the experimental section and go in to the Pendiq settings. Change the Pen Pin Code to match your pen and enable Pendiq 2.0 Support switch.

If you want to have it so treatments entered on xDrip cause the pen to wake up and prompt the insulin dose then enable Send Treatments to Pen remember the minimum dose the pen can administer is 0.5 units.

With these features enabled, what should happen is that when you view the xDrip home screen it will attempt to contact the pen and sync any injection records within the last 48 hours and also set the pen time. You should see any injection entries pop up on the xDrip graph and hear a bleep noise to indicate any new record being created.

In a similar way if you use the treatment dialog (accessed via the syringe icon on the home screen) and enter a bolus, eg 1 unit, then shortly afterwards the pen should wake up in the Prime mode and the amount of the bolus will be pre-entered on the screen.

Once you create a treatment like this there is a 2 minute window to perform the injection. Beyond that there is the possibility for xDrip to get confused about whether the bolus data it syncs from the pen is a duplicate or not. Likewise if you do an xDrip treatment and then within 2 minutes do another treatment for the same amount of insulin then it is going to think those are the same treatment when syncing. If this is an operational problem for anyone please talk to me in more detail about when the problem occurs.

If the connection isn't working at any time you can go to your phone apps screen and then back to xDrip and that will restart the process. (Not more than once per minute though)

Future road map:

1) Testing of the current implementation - does it work? is it reliable? are there any duplicates? Does it properly handle different timezones and daylight saving time? 2) Do we need to/can we support multiple pens simultaneously - how can that best work? 3) Should the current polling method be changed so that for example xDrip connects periodically in the background to sync new data without the app being opened? 4) Are there any other pen features we need to think about - for example different insulin types?

General Notes

My biased opinion about this device from observing the protocols is that it could have been done better. There are inconsistencies in how it works and some features simply are not implemented. The terrible ratings of the official app show that the manufacturer has not managed to achieve the dream of making people's lives easier with the product. I would have loved to have been involved in the software development process with them!

jamorham commented 6 years ago

Additional notes, on your pen make sure that the bluetooth is set to On and Always On the pin code needs to be the same as in the software. Mine is still set to the default of 0000

ralf-ms commented 6 years ago

It's working! I've tested without and with "Send treatments to pen" enabled, no issues. What I've seen during the first (initial) sync from treatments yesterday they all have been inserted into xdrip with an hour later than actually given (insulin dose given yesterday at 07:22 was synced to 08:22). New doses where added with the correct time though. As for stability and reliability I'll continue testing for the next days. As for future features: maybe having background sync without opening xdrip would be on top of the list (for me)...

jamorham commented 6 years ago

@ralf-ms Great news, it sounds like the timezone on the pen wasn't set until xDrip updated it or I'm using a different timezone format perhaps. What sort of frequency should I implement a background sync at? How timely does the data need to be? Bear in mind it will also drain the pen battery. The other way we could try is maintaining an always on connection to the pen where I think we will get new data pushed. Its harder to maintain those type of connections though.

jamorham commented 6 years ago

@sodesignberlin if you use amazon then you can login to amazon.co.uk and search for my books wish-list under the name jamorham

jamorham commented 6 years ago

@ralf-ms thanks!!

ghost commented 6 years ago

@jamorham are we at the right place here: http://amzn.eu/ar1lo0u ?

jamorham commented 6 years ago

@sodesignberlin yes thanks!

jamorham commented 6 years ago

Thanks for all the wish list items. I've a lot of reading ahead!

How is life with the Pendiq support so far? Is it working reliably?

ghost commented 6 years ago

About my life with the Pendiq: So far almost everything went quite fine. In general I would prefer to pull the Pendiq-values manually as needed, rather than syncing in a for me quite "random" seeming frequency.

First Issue accured today (still lasting): No sync since tonight. First suspicious Pendiq log: "Throwable inside setup motification: com.polidea.rxandroidble.exceptions.BleScanException: Dosconnected from B0:72:BF:03:65:3F" Sinsce then: "Trying to Turn Bluetooth on, Enable bluetooth and thry again com.polidea.rxandroidble.exceptions.BleScanException: Bluetooth disabled (code 1)"

I checked Pendiq settigns: "bluetooth always on" but I can't see the Pendiq in any bluetooth- device at all. Maybe my device ist just broken (you self have seen the quality ;-( ?

ralf-ms commented 6 years ago

I'm very satisfied. Sometimes I've to close xdrip and reopen it again to get values synced. But that's no really an issue.

Occasionally the bluettooth on the pendiq gets stucked, you will notice this when you can't see the device in bluetooth settings. In this case switching bluetooth off and on will make the pendiq inoperable for a few minutes. You have to reset the pen by pressing the button hidden by the little hole on the backside for a few seconds till the led gives a short red flash . Settings will survive, just date/time have to be reentered, bluetooth is switched off and has to be set to "on" again. I've had this once since using the pendiq with xdrip.

ghost commented 6 years ago

@ralf-ms thank you for this hint, the litle whole-button did the job. @jamorham one question that I allways wanted to know: is there a way to edit/correct old treatments? For me this is especially relevant since I'am geting mistakenly synced insulin values over Pendiq Maybe this is not possible at all, because the Pendiq would overwrite the manual edits anyway?

ralf-ms commented 6 years ago

Having it used for 2 weeks now, I can say, it works flawlessly. No issues. In the majority I'm using the xdrip treatment dialog and rarely the pendiq directly, which also means, that I'd have no use for a periodic background sync and I'm absolutely happy with what I've got.

Maybe for just slight change: If you've a change of mind regarding the dose, having already the pendiq in your hands and correcting the value here, it would be nice if that value would replace the value entered in xdrip (only within the timeframe of 2 minutes of course) instead of getting an additional insulin value in xdrip. Can that be done without investing too much time?

Ordnare commented 5 years ago

Hi I'm new to Pendiqs pens and will recive them in the end of the week, does it work with 2 diffrent pens yet?

Ordnare commented 5 years ago

jamorham Hi I made a little contribution to your Amazon Wishlist. They wan't to know if you got it? 20161114

Further more I now have 2 Pendiq 2.0 for my basic and bolus insulin. I was in a serios accident 20161223 eg. High energi collision. My shortterm memory is not so good now, and I'm not a programmer only a user. I think highly of all you guys that have made xDrip ang integration with Pendiq possible. Now to my question would it be possible to use 2 Insulinpens? It seems that it is only one at the moment. I wolud be most grateful if it would be possible // Greetings Lars :-)

jjaone commented 5 years ago

Thanks all, this is very interesting for me/us as we (my son) have been using LibreFreestyle sensor w/ Miaomiao BT-transmitter and Countur Next One BG meter all linked to Xdrip+ Android app - and everything is working great 👌😀

Now, my son has two Novo-Pens (can't remember the type/model, but they are quite new xause they are acquired 6 months ago in Europe/Finland), the other for basal Levemir-insulin and the otjher for bolus NovoRapid-insulin. Now when I found this thread and the related option in Xdrip+ app, I wanted to know what options do we have to link/upload/pull the dose/treatment data from both of these existing pens to Xdrip+?

Do we have the change to some other pens (the Pendiqs mentioned here) or are there caps available that could attached to these pens that would transimit dose data to, or allow it to be read from, Xdrip+?

If new code for this needs to be implemented, I'm sw engineer for 30+ years and have some experience on Android/Java-mobile development and a lot of systems and FullStack-develepment in Linux and other open source environments, so would gladly contribute to Xdrip for thid kind of functionalities. 😀

Cheers for now, -jukka (@jjaone at GitHub and gmail and Twitter) Jukka Aaltonen, Lapland/Finland.

jamorham commented 5 years ago

@jjaone Do your insulin pens have a bluetooth or NFC interface?

jjaone commented 5 years ago

Well, I asked my son and the pens are NovoPenEcho's (identical but different colors for basal/Levemir and bolus/Novorapid) and seems that they don't have NFC nor Bluetooth, at least the docs by NovoNordisk and by medical system in Finland don't mention anything about those (see below the link to these pens): https://www.novonordisk.com/patients/diabetes-care/pens--needles-and-injection-support/NovoPenEcho.html

I'm guessing that this means these pens can not be used to to read from or push to Xdrip the dose data.