LoopKit / Loop

An automated insulin delivery app for iOS, built on LoopKit
https://loopdocs.org
Other
1.48k stars 1.29k forks source link

Feature: Using Nightscout as CGM data source #1134

Closed Andrei0105 closed 10 months ago

Andrei0105 commented 4 years ago

Some CGMs don't support connecting to Loop and the easiest way to do this is to upload their data to Nightscout and retrieve it from there. This was already discussed in https://github.com/LoopKit/Loop/issues/84, but this does not consider CGMs that are not compatible with xDrip+. It also seems that this was possible in Loop v1.4.0 (https://github.com/LoopKit/Loop/pull/535, https://github.com/LoopKit/Loop/pull/492) but it's not possible currently.

I created a pull request (https://github.com/LoopKit/dexcom-share-client-swift/pull/9) in https://github.com/LoopKit/dexcom-share-client-swift that allows the user to use his own Dexcom share server. This can be used with https://github.com/dabear/NightscoutShareServer to retrieve data from Nightscout.

How to use this feature as of now:

What is this useful for: I have the Medtronic Guardian Connect standalone CGM which connects directly to my iPhone and data is retrieved from the Carelink portal and uploaded to Nightscout. The CGM can't be connected in any other way so this is the only solution to use it with Loop. I'm assuming there are more systems that can be used this way.

Kdisimone commented 4 years ago

https://github.com/LoopKit/Loop/issues/84 duplicate

miriamkw commented 4 years ago

Hello! I have followed this guide through, but every time i try to build Loop after I made the changes to the Cartfile, the Cartfile automatically resets the changes I have done. You know why this is?

Andrei0105 commented 4 years ago

Hello! I have followed this guide through, but every time i try to build Loop after I made the changes to the Cartfile, the Cartfile automatically resets the changes I have done. You know why this is?

Hi! Can you please post the contents of the cartfile before you edit and after you edit it. Also, are you using the master branch? Are you sure that you are updating Cartfile and not Cartfile.resolved? Can you delete Cartfile.resolved, update Cartfile, and try to build again?

miriamkw commented 4 years ago

Hi! Can you please post the contents of the cartfile before you edit and after you edit it. Also, are you using the master branch? Are you sure that you are updating Cartfile and not Cartfile.resolved? Can you delete Cartfile.resolved, update Cartfile, and try to build again?

1: I find two Cartfiles with the line from the guide. One in Carthage⁩/Checkouts⁩/G4ShareSpy and one in Carthage⁩/Checkouts⁩/CGMBLEKit. They are identical, and I change both of them. Before:

github "LoopKit/LoopKit" ~> 3.0 github "LoopKit/dexcom-share-client-swift" ~> 1.2

After: github "LoopKit/LoopKit" ~> 3.0 github "miriamkw/dexcom-share-client-swift" "master"

2: I am not in any branch because i downloaded the source code locally to my computer from Loopdocs: https://loopkit.github.io/loopdocs/build/step13/.

3: Tried to delete Cartfile.resolved and build but the same happened.

Thank you so much for answering so quickly!

Andrei0105 commented 4 years ago
  1. When you downloaded the source code did you choose Loop: Master branch or Loop: Dev branch? I didn't test this on Dev, so you should download Loop: Master.
  2. You are not editing the right Cartfile. The Cartfile you should be editing is located at the top level of the source directory you downloaded. Pictured below: loop1 Since a new version of dexcom-share-client was released, the line you should be changing now is github "LoopKit/dexcom-share-client-swift" ~> 1.2. After this you should delete Cartfile.resolved (from the same directory where the Cartfile you edited is located), and build again.
  3. To check that your changes were applied look at the Cartfile.resolved contents after the build. You should have a line like this: github "miriamkw/dexcom-share-client-swift" "[some hash]"

Please try this, and if you still have problems paste your Cartfile.resolved (the one generated after the build) here.

miriamkw commented 4 years ago

The version I had downloaded was Loop-master, but to me the Cartfile in the root didn't contain the mentioned line. So I cloned the project from Git instead, and edited the Cartfile.

When I built it the changes stayed, but the Cartfile.resolved remained the same. Deleting the Cartfile.resolved before building solved the problem.

Now my problem is that my Glucose levels do not start appearing in my Loop app. The username and password should not matter, right? I have already

Can the problem be that in my branch of dexcom-share-client-swift I made the changes directly in Github? It says that "CompareThis branch is 2 commits ahead of Andrei0105:master". Do I have to clone the repository and push the changes?

Andrei0105 commented 4 years ago

I checked your branch and it seems fine. You are right that the username and password don't matter. It usually takes 5-10 minutes for the first glucose values to appear. Did you tap Add account before tapping Save when you have to add a Dexcom Share account in Loop? If you don't click Add account then your credentials will be saved and it will look like everything is set up correctly but actually the account is not enabled in Loop. If after you click Add account you don't get any error it means that Loop connected successfully to your Share Server.

miki3421 commented 4 years ago

I have the same problem, I did everything but in the heroku logs i'm not receiving calls to the webserver. UI is perfect and without errors. The only way that is found to receive only one call is: try to configure a Dexcom Webserver US for example and after try again the custom. In that case I can see in the log the Authentication request and the first Glucose request, but nothing else after. Even if i'm leaving running hours this configuration. Thanks

miriamkw commented 4 years ago

Even when I added account like you illustrated @Andrei0105 , it still didn't work. But now suddenly the option "Custom" disappeared again. I have tried restart the computer, update xCode, clean and build but nothing works. Now I suspect all my errors appear because I have the same project in several repositories.

Will update when i figure out more. Thank you so much for the help so far.

Andrei0105 commented 4 years ago

Hi! I don't think the problem is from your shareserver since it seems to be working fine. If the following solution does not work, I can test with your URL and see if the shareserver works properly.

Now, to try another solution:

Then build the application. To check that the changes have been applied, check Cartfile.resolved. The line github "LoopKit/dexcom-share-client-swift" "v1.2" should no longer be in there.

miriamkw commented 4 years ago

Update: It is finally working, since 5 minutes ago! I am not completely sure what made it work, but after I added the insulin pump, I deleted the CGM and added it all over again, and it started working.

Checklist for people that might meet the same problem:

I am greatful for this solution, as this is my only opportunity to be able to Loop (Freestyle Libre 2 x Omnipod x iPhone). Thank you again!!

Andrei0105 commented 4 years ago

Great! I'm happy it's finally working. With the Freestyle Libre I think you can use Spike and this will not need an internet connection (I'm not sure but I'll switch to the Libre in less than 2 weeks and I was hoping to not need internet anymore).

As a sidenote: If you have both Nightscout and ShareServer running on the same Heroku account you will probably exceed the 1000 free dyno hours per month. You can run the ShareServer in Azure and thus avoid having to pay for a dyno in Heroku. The ShareServer has a Deploy to Azure option which makes setting it up very easy.

miriamkw commented 4 years ago

Spike does not yet support Freestyle Libre 2, so if you have the opportunity I would recommend Libre 1. I hope it will be available for Libre 2 soon, though.

Oh, I did not notice this limit. I ran into trouble with the setup of Azure but I will try again. Thanks!

miki3421 commented 4 years ago

Thanks @miriamkw . i think mine is not working because i'm using the simulator as a Pump. i can't connect the Omnipod so i'm using "manually" @Andrei0105 do you think can be this the case for my issue? Thanks

miriamkw commented 4 years ago

Thanks @miriamkw . i think mine is not working because i'm using the simulator as a Pump. i can't connect the Omnipod so i'm using "manually"

Maybe try to go to Settings --> Loop and give Loop app access to Bluetooth?

I cannot understand that the CGM is dependent on being connected to a real insulin pump. But when I connected to the OmniPod Loop asked me for the access to BlueTooth, so that might have made the difference?

Andrei0105 commented 4 years ago

Thanks @miriamkw . i think mine is not working because i'm using the simulator as a Pump. i can't connect the Omnipod so i'm using "manually" @Andrei0105 do you think can be this the case for my issue? Thanks

I think it might be. Loop might be waiting for a response from a pump before requesting glucose values but I'm not sure about this. Will you be able to connect your Omnipod to test with it?

miki3421 commented 4 years ago

@Andrei0105 unfortunatelly no i'm not able i don't have rileylink jet. before order i want understand if i can get values without Spike using only Xdrip Ios. For the moment i'm getting data with health database but not in background.. so it's not complete se solution of course.

Andrei0105 commented 4 years ago

@Andrei0105 unfortunatelly no i'm not able i don't have rileylink jet. before order i want understand if i can get values without Spike using only Xdrip Ios. For the moment i'm getting data with health database but not in background.. so it's not complete se solution of course.

I deleted my pump and changed it to the Simulator and I don't get glucose values anymore. So this might be your problem. Your setup is probably fine, but you need a pump connected to be able to get CGM values.

miki3421 commented 4 years ago

thanks @Andrei0105 . now i'm not able anymore to build the app with the option Custom. I've tried everything. Anyway it's fine I'm in "manual" drive. Consider that RF technology it will replaced soon with BT i can wait. Thanks for your support. Michele

Andrei0105 commented 4 years ago

thanks @Andrei0105 . now i'm not able anymore to build the app with the option Custom. I've tried everything. Anyway it's fine I'm in "manual" drive. Consider that RF technology it will replaced soon with BT i can wait. Thanks for your support. Michele

Hey @miki3421. I just changed to the MiaoMiao and I'm using Xdrip IOS and it works well. I get bg values when Xdrip is in background mode too. So if you can use Xdrip IOS, you should be able to use Loop master directly.

miki3421 commented 4 years ago

Hi @Andrei0105 , i'm doing the same but you can use the CGM function if you have enabled only the simulator of the pump. I'm getting values from the healthdb and simulating the trends manually. I asked to some developer if there is a way to bypass but i haven't received response jet. Next week i'm in USA and i will order the Rileylink .. and problem solved I hope.

Andrei0105 commented 4 years ago

Hi @Andrei0105 , i'm doing the same but you can use the CGM function if you have enabled only the simulator of the pump. I'm getting values from the healthdb and simulating the trends manually. I asked to some developer if there is a way to bypass but i haven't received response jet. Next week i'm in USA and i will order the Rileylink .. and problem solved I hope.

I actually had a wrong setup. Xdrip for iOs will not work directly because Loop only gets health data when the phone is unlocked. However this works with a custom share server and Xdrip uploading the values to nightscout. This is what I'm using now. So install Loop with the custom dexcom share server option and it will work with Xdrip for iOS.

miki3421 commented 4 years ago

yeah, but i think you are using the RileyLink Device. correct?

miki3421 commented 4 years ago

Hi @Andrei0105 have you tried to use the Custom server on a DEV branch of Loop? apparently is not taking the changes.

Andrei0105 commented 4 years ago

I tried some time ago but I didn't manage to do it and didn't want to spend too much time on it since Loop master was updated to 2.0.

rutgerbousche commented 4 years ago

Hi Andrei0105,

I've read and tried and read som more and tried some more. But I just can't get "custom" in my loop app available under Dexcom Share. I've got no idea what's going wrong and where it goes wrong. The nightscoutshareserver works as it should do (https://rutgerbouschens.herokuapp.com) And I've got an freestyle libre with miaomiao 2 (in combination with the tomato app) to send data every 5 minutes to nightscout.

I followed the steps you've written above and I just can't get it to work... what am I missing? Can you help me? So that I can help others who experience the same problems?

miki3421 commented 4 years ago

Hi @rutgerbousche I had the same problem, you need to edit the cartfile and delete the .resolve

for example thisone is mine for working with the dev branch of Loop.

github "LoopKit/LoopKit" "dev" github "miki3421/CGMBLEKit" "dev" github "i-schuetz/SwiftCharts" == 0.6.5 github "miki3421/dexcom-share-client-swift" == 2.0 github "miki3421/G4ShareSpy" "master" github "ps2/rileylink_ios" "dev" github "LoopKit/Amplitude-iOS" "decreepify"

and also it's a good practice open terminal in the Loop folder and launch carthage update as you can see for the dev branch you need also fork CGMBLEKit and G4ShareSpy

if you still have problem try also to increase the version of you branch version.

@Andrei .. I found the way to use the last features that are on Loop Dev :)

rutgerbousche commented 4 years ago

Hi @miki3421 the following has been done:

Change my cart file to:

github "LoopKit/LoopKit" "dev" github "rutgerbousche/CGMBLEKit" "dev" github "i-schuetz/SwiftCharts" == 0.6.5 github "rutgerbousche/dexcom-share-client-swift" "master" github "rutgerbousche/G4ShareSpy" "master" github "ps2/rileylink_ios" "dev" github "LoopKit/Amplitude-iOS" "decreepify"

Started the terminal, removed all the cached files and dependencies, updated carthage everything is downloaded fresh.

opened Xcode and build the loop app again. Result is some depressing :( on the CGM > dexcom share > servers (2 option: US and non-US) not the 1 needed " CUSTOM".

even restarted my iPhone deleted the CGM and added it fresh but still no custom... I'm very certain I'm missing an important detail but I don't know which one.... :(

The 2 files are already edited on my dexcom-share-client-swift (line 44 & line 34, 35) do I need to change the cart file in the dexcom share also?

miki3421 commented 4 years ago

you are right @rutgerbousche i did the same in the dependecy forked. CGMBLEKit and G4ShareSpy. check my repositories are updated. Sorry but i did so many things and I forgot this part. and if is not working try with tagging a version. like 1.0 ... i saw that your using "master"

rutgerbousche commented 4 years ago

Hi @miki3421,

No problem, if i'm understanding you correctly you're telling me that binding a nightscoutshareserver to CGM input data for a ios loop app is possible. If that's true than i have to search harder and further (although any help is appreciated) loopkit says it's possible in their documentation by altering the files and dependencies and possible the loop code. It's up to me to find out how to implement nightscoutshareserver to loop to get the complete dutch society (which has been granted free use of FreeStyle Libre) as part of the insurrance policy to use loop in combination with fsl in the right way. I'll keep searching, if i've found out how i will document this and share this.

dabear commented 4 years ago

Nightscoutshareserver is deprecated and wont be supported any longer by Its creator (me)

hardit826 commented 4 years ago

Hi, I have followed these steps as per above posts.

1) Downloaded loop-dev from https://loopkit.github.io/loopdocs/build/step13/. Removed Cartfile.resolved. Modified the Cartfile as below.

 github "LoopKit/LoopKit" "dev"
github "hardit826/CGMBLEKit" "dev"
github "i-schuetz/SwiftCharts" == 0.6.5
github "hardit826/dexcom-share-client-swift" "master"
github "hardit826/G4ShareSpy" "master"
github "ps2/rileylink_ios" "dev"
github "LoopKit/Amplitude-iOS" "decreepify"

2) Forked G4ShareSpy and CGMBLEKit. Removed the Cartfile.resolved file in both. Modified both their Cartfile's as below.

github "LoopKit/LoopKit" ~> 3.0
github "hardit826/dexcom-share-client-swift" "master"

3) This is how my Cartfile.resolved file looks after the build.

github "LoopKit/Amplitude-iOS" "[some hash]"
github "LoopKit/LoopKit" "[some hash]"
github "LoopKit/MKRingProgressView" "[some hash]"
github "LoopKit/dexcom-share-client-swift" "v1.2"
github "hardit826/CGMBLEKit" "[some hash]"
github "hardit826/G4ShareSpy" "[some hash]"
github "hardit826/dexcom-share-client-swift" "[some hash]"
github "i-schuetz/SwiftCharts" "0.6.5"
github "ps2/rileylink_ios" "[some hash]"

I also tried to change the version from "master" to == 1.0 but still I'm not seeing the Custom option for Dexcom Share. I'm sure there are other changes that need to be made. So can you help out with the changes that I'm missing here. Which version of Loop should I download?

@rutgerbousche Were you able to get this working?

Andrei0105 commented 4 years ago

@hardit826 I will try the steps you posted to get this working and update the steps if required. In your Cartfile.resolved you shouldn't have github "LoopKit/dexcom-share-client-swift" "v1.2" anymore if you modified all the references to your version. I will check if something is missing.

hardit826 commented 4 years ago

@Andrei0105 Thank you for the quick response. I was wondering the same thing. Every time I build I see the "LoopKit/dexcom-share-client-swift" "v1.2" in the resolved. I have also checked in the Carthage Checkouts folder for dexcom-share-client-swift. It's not the dexcom-share-client-swift with my changes in my repository. I have modified and commited changes to these 3 in my version as per above posts. https://github.com/hardit826/CGMBLEKit https://github.com/hardit826/G4ShareSpy https://github.com/hardit826/dexcom-share-client-swift

Andrei0105 commented 4 years ago

I did not get the chance to test yet, but in your Cartfile you have github "hardit826/CGMBLEKit" "dev". But by checking your repo, you modified the master branch not the dev. So this is why it's getting the Loopkit version of dexcom-share-client. This guide was made for the master branch. If you use dev be sure to use (and modify) the branches that are used in the original Cartfile.

hardit826 commented 4 years ago

@Andrei0105 You are correct there. That was the issue. I changed "hardit826/CGMBLEKit" from dev to master. Now I can see the Custom option on Dexcom Share. My servers are all set up. I guess I'll have to wait till my Riley Link arrives to test the whole thing. Since people aren't seeing their glucose levels without connecting to the pump. Same is the case with me. Thanks for the quick help!

shortanu commented 4 years ago

hi Andrei, thanks for this workaround, I managed to build Loop following these and get data uploaded by Guardian to Nightscout then written by Spike into Health. I am currently on the learning part of Loop, preparing to switch from MDI/Pen to OmniPod pump and having this in place allows me to "simulate" looping while injecting by entering carbs & insulin in Spike. I wonder if it would be same if I build the Loop-Spike version and use Spike's internal HTTP, what do you say? Would that be better or worse?

cyoung1024 commented 4 years ago

@shortanu it's imperative not to use Health with Spike. Spike cannot have access to Health in any capacity not only for Loop to function properly, but more importantly to avoid double carb entries. If Spike has access to Health, you could end up having double the carbs, and therefore be given double the insulin. Furthermore, using Health as your CGM data source would require your phone to be open (screen on, phone unlocked) constantly, as apps do you have access to Health while turned off. This would mean that the minute you lock your phone, Loop stops looping. Therefore your current method is not viable. Your options are either to use this method and have Nightscout as your data source, or to use a Spike branch and have Spike in follower mode as your data source.

shortanu commented 4 years ago

@cyoung1024 thanks for details, those are the options or switch to Dexcom as I self-fund fully ;) but would like to get best out of remaining GC and test-drive Loop early to get accustomed as I was already using Spike in follower mode for carbs and insulin input to Nightscout. At the moment I am manually adding injected boluses and carbs in Spike so is the only app writing in Health, thanks to your comment I realised that an improvement I can make is to start entering carbs in Loop to get used with the UX if Loop will push entries to Nightscout.

To get back on this topic, somehow Loop was getting Glucose values even before me adding any CGM source in the app, so I wondered if it's because of Spike usage as I have internal HTTP on and if building Loop with Spike branch would have major added value. IMG_2803 IMG_2804 IMG_2805

@Andrei0105 is Loop always showing that yellow ! for glucose by using this method or something is wrong on my side?

cheers, the journey to Loop is exciting

Andrei0105 commented 4 years ago

@shortanu As @cyoung1024 said, you are currently getting values in Loop from Health. Loop reads the data the Spike is uploading there. This does not work when the phone is locked.

Yes, you can add carbs in Loop, but I don't think this will be very useful to you now as you will not see any predictions without both the pump and cgm added. You can try with the simulator pump, I haven't used that so I'm not sure how it works.

As @cyoung1024 said, you have 2 options, either build Loop with this change, or use Loop with Spike and get data from Spike's internal HTTP server that Spike will read from your nightscout site via follower mode.

If you use this method, you will need in addition to you nightscout site, the nightscout share server (which you should host in Azure to avoid reaching your free limit in Heroku). It's more difficult than just installing Loop with Spike support, but it has one advantage: you won't depend on Spike. As much as I like Spike and I'm using it now, there are moments when I have to restart my phone because the HTTP server just won't work.

Installing Loop with Spike is simple, and if Spike is working well for you this is what I recommend.

You also have a third option: using this change with Loop with Spike. If you apply the method described here to a Loop with Spike branch you'll get a version of Loop with both Spike and custom shareserver support. Thus, if you want to change from one to another you just have to change the CGM.

For the yellow !, did you add the CGM or is Loop reading the health data? If you added a CGM and you get data consistently you shouldn't worry about that.

shortanu commented 4 years ago

ok then, I didn't understood it right when @cyoung1024 (sorry about that Caroline) mentioned it but now it makes sense. Indeed, it was reading BG data written by Spike in Health. Tested by disabling Spike share to Health and confirmed. This is also reason behind the yellow !, it indicates inconsistent CGM data flow as mentioned in LoopDocs "If the yellow alert remains, something may be wrong with fetching BG data." Now I've done a build of Spike master branch and works, Loop writing in Health now. @Andrei0105 nice idea with 3rd option, will stay in my head and probably do it in the end :) Until then, as I'm not yet pumping, the Spike version suits me better, but have some doubts about the long run as I saw my phone struggling with Spike at heavy use moments.

thanks 🙏

liamzebedee commented 4 years ago

For those that come across this thread, I had difficulties getting NightScoutShareServer running using the Dockerfile due to the dotnet dependency, and reimplemented it a bit more simply in Node.js - https://github.com/liamzebedee/nightscout-share-server-node.

Cheers to @Andrei0105, I managed to get my Loop running thanks to this fork!

lukebandy commented 3 years ago

Hey @Andrei0105, thanks for the work on this. I had this working with Loop v2.2.2 and Xcode 12.0.0, but following the same steps with Loop v2.2.4 and Xcode 12.3 seems to produce various 'in scope'/'type does not conform' errors. Have you had much luck, or is it likely that I've made a mistake?

sp90 commented 3 years ago

@lukebandy @Andrei0105 I have the same issue upgraded to Xcode 12.4, Loop 2.2.4, iOS 14.4 & macOS 11.2.1. Now I cannot get my spike data to loop which is kinda hard when I really need this to work

Andrei0105 commented 3 years ago

@lukebandy @sp90 Hi, please try one of newer alternatives to get Nightscout data into Loop:

@sp90 If you are using Spike to read data from your CGM you can also use either FreeAPS or one of the Spike branches and get data directly from Spike, without having to upload it to Nightscout

sp90 commented 3 years ago

@Andrei0105 do you have a link to a spike branch that works with the latest and greatest

Xcode 12.4, Loop 2.2.4, iOS 14.4 & macOS 11.2.1

I have taken the @cyoung1024 Loop branch that worked in the past, then I have pulled the current loop master branch onto it "no conflicts" and are now building to my phone to see the result

Andrei0105 commented 3 years ago

@sp90 spike-master and spike-autobolus from the link I posted are up to date with Loop master and automatic-bolus. Cal is no longer maintaining the spike branches, and the up to date ones are the ones I posted which are maintained by me and should work without any issues with the latest versions of Xcode and iOS since they're based on the latest version of Loop.

sp90 commented 3 years ago

@Andrei0105 THANKS!! I will give it a shot - It works!

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 10 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.