joelhi / glucose-viewer-pico

Project to view Freestyle Libre 2 glucose readings in real-time on a Raspberry Pico
MIT License
3 stars 0 forks source link

Information please ? #7

Open Odroid13 opened 4 months ago

Odroid13 commented 4 months ago

Thank you for this wonderful project, I have been looking for the possibility of having my child's blood sugar at home for a while.

I have no knowledge of programming, but I learn quickly, can you explain to me how to do it please?

I need to install MicroPython, the documentation is available and no particular problem for that: https://www.raspberrypi.com/documentation/microcontrollers/micropython.html

Once MicroPython is installed, how to copy your files to the Raspberry Pi Pico HW

Also tell me if it is possible to use another OLED screen with Resolution: 64 × 128: https://www.kubii.com/fr/ecrans-supports/3423-module-d-affichage-oled-13-pouces-pour-raspberry-pi-pico-64-128-spii2c-5903351249775.html If so I think it will be necessary to change a configuration file for the display?

Thank you in advance for everything.

If I succeed, I will make a video for other people who don't have any knowledge.

joelhi commented 4 months ago

Hey! Glad you took interest in this project.

As you correctly pointed out, you need to download micropython and install it on your pico. Following the steps in the manual should work fine.

To get the files from this project onto the pico, I would advice installing Visual Studio Code and get the MicroPico extension. Using this extension, you should be able to run and upload the files to your pico. I would advice cloning this repository, and open it with VSCode, once you have managed to setup you pico.

The next topic, regarding using a different display is more tricky. While possible, the current code is very tightly tied to the one I use. If you look in the code, you will find a file in driver/display_driver.py which provide the interface with the display. To use a different display, you will need to figure out how to interface with you particular display, and replace this adapter with your file. However, you will also need to update all the uses of the LCD_1inch8 class, as your driver will provide something different.

For example, in graphics/number_font.py (which draws the glucose value in a large font), the display is used.

def draw_numbers(lcd:LCD_1inch8, numbers, scale:int, x:int, y:int):
    for index, number in enumerate(numbers):
        x_pos = x + index * scale * (_WIDTH + _SPACING)
        y_pos = y
        scaled = get_scaled_pixels(NUMBER_BITMAPS[str(number)], _WIDTH, _HEIGHT, scale)
        for i, val in enumerate(scaled):
            (j, i) = map_index_to_2d(i, _WIDTH, scale)
            if(val == 1):
                lcd.pixel(x_pos + i, y_pos + j, lcd.WHITE) 

The call to lcd.pixel() which sets the value of the pixel at a specific coordinate, is specific to the display I use and you will need to replace it with the equivalent for you display.

If you manage to figure out how to write to you particular display, by finding an adapter file or similar, I could try to help you and update the code accordingly.

Hope this helps,

Joel

spordiab commented 4 months ago

Hey! Glad you took interest in this project.

As you correctly pointed out, you need to download micropython and install it on your pico. Following the steps in the manual should work fine.

To get the files from this project onto the pico, I would advice installing Visual Studio Code and get the MicroPico extension. Using this extension, you should be able to run and upload the files to your pico. I would advice cloning this repository, and open it with VSCode, once you have managed to setup you pico.

The next topic, regarding using a different display is more tricky. While possible, the current code is very tightly tied to the one I use. If you look in the code, you will find a file in driver/display_driver.py which provide the interface with the display. To use a different display, you will need to figure out how to interface with you particular display, and replace this adapter with your file. However, you will also need to update all the uses of the LCD_1inch8 class, as your driver will provide something different.

For example, in graphics/number_font.py (which draws the glucose value in a large font), the display is used.

def draw_numbers(lcd:LCD_1inch8, numbers, scale:int, x:int, y:int):
    for index, number in enumerate(numbers):
        x_pos = x + index * scale * (_WIDTH + _SPACING)
        y_pos = y
        scaled = get_scaled_pixels(NUMBER_BITMAPS[str(number)], _WIDTH, _HEIGHT, scale)
        for i, val in enumerate(scaled):
            (j, i) = map_index_to_2d(i, _WIDTH, scale)
            if(val == 1):
                lcd.pixel(x_pos + i, y_pos + j, lcd.WHITE) 

The call to lcd.pixel() which sets the value of the pixel at a specific coordinate, is specific to the display I use and you will need to replace it with the equivalent for you display.

If you manage to figure out how to write to you particular display, by finding an adapter file or similar, I could try to help you and update the code accordingly.

Hope this helps,

Joel

Thank you for your reply

Finally I ordered the same screen as yours. This will make it easier to implement your project.

I am waiting to receive my order and will provide feedback on your explanations.

Hoping it's not too difficult for me, I'll see you soon.

Thank you so much

Odroid13 commented 4 months ago

Thanks for your feedback.

I will try to carry out your project.

I have difficulties to understand :

'API_TOKEN':"TOKEN", how to obtain the API-TOKEN? 'API_USER':"USER_EMAIL", Librevew login? 'API_PASSWORD':"PASSWORD", Password Libreview?

Can you tell me how to obtain the API-TOKEN please.

Thank you so much ^^

joelhi commented 4 months ago

Yes, the user and password are the usual ones for LibreView.

The API_TOKEN is needed as part of the authentication process as well. It has to be generated via an API call. The method login called in login.py should make this request and print the generated token. User and password is needed to retrieve it. This can be run in any python env, not necessary to do on the pico. Save this token and put it in your config file.

I have only used the login script once so let me know if it doesn’t work.

Odroid13 commented 4 months ago

Hi,

I'm using the same hardware as you and I'm getting an error on screen when it connects.

I remind you that I have no knowledge of programming, I have documented myself to understand the main points.

However, I use Thonny to copy the files that are located in the "src" directory to the root of the Raspberry Pi Pico. Then I modified the config.py file and entered the SSID and WIFI Pass parameters. Login Libreview and Passord For the Token API, I don't know how to do with your explanation but I found a simple solution, from the internet browser we can obtain the TOKEN API.

When I turn on the raspberry pi, it connects to wifi then it tells me "failed to read gucose"

I'll give you the screenshot of Thonny and also the API Token and Raspberry Pi videos.

If you can direct me that would be great ^^

I forgot, I'm from Europe and maybe something needs to be changed in the settings?

Thank you very much for your help, if it works I will sleep more peacefully

The global api url is https://api.libreview.io. If you are placed in europe you can use https://api-eu.libreview.io instead. Capture d'écran 2024-05-17 003549 Capture d'écran 2024-05-17 003600 Capture d'écran 2024-05-17 003613 Capture d'écran 2024-05-17 003747 Capture d'écran 2024-05-17 001046

joelhi commented 4 months ago

Hey! Sounds like you made some good progress!

A general note is to not share your private API token in any public context. This should be private to you as a means to access your data. Sharing it will allow others to access your personal data.

On a second note, it seems like LibreView has introduced some security layer as per this issue. It seems they now block our requests from the pico, which I assume are flagged as web-scraping / malicious activity. As of now, mine is not working anymore, so you may just be experiencing the same block.

I will have a look at this tomorrow and see if I can figure anything out. I contacted the support, but they had, unsurprisingly, no interest in helping out with this sort of interaction with the API.

I'm sorry, but this is looking a bit tricky and was very bad timing for you. 😞 Hopefully there is a way to unblock it.

Odroid13 commented 4 months ago

Hey! Sounds like you made some good progress!

A general note is to not share your private API token in any public context. This should be private to you as a means to access your data. Sharing it will allow others to access your personal data.

On a second note, it seems like LibreView has introduced some security layer as per this issue. It seems they now block our requests from the pico, which I assume are flagged as web-scraping / malicious activity. As of now, mine is not working anymore, so you may just be experiencing the same block.

I will have a look at this tomorrow and see if I can figure anything out. I contacted the support, but they had, unsurprisingly, no interest in helping out with this sort of interaction with the API.

I'm sorry, but this is looking a bit tricky and was very bad timing for you. 😞 Hopefully there is a way to unblock it.

Thanks for your response, I'm really sad this doesn't work anymore. So this doesn't come from bad handling on my part, that reassures me ^^

However, wouldn't it be better to modify your code to instruct it to connect to a Nighscout server?

I think this would be more secure for the future?

Thanks for your help