Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token does not survive reboot #14

Closed
GertVanderstukken opened this issue Jan 10, 2024 · 8 comments
Closed

Token does not survive reboot #14

GertVanderstukken opened this issue Jan 10, 2024 · 8 comments

Comments

@GertVanderstukken
Copy link

Hello Ondrej,

I am using the proxy to feed some M5stack devices. It's working great!!!!
I also see that you client was used as a source for the Home Assistant plugin: Great.

But there's 1 functionality that I miss: if the proxy (or the server it's running on) is rebooted (I perform patch management :) ), the token has to be (manually) fetched again.
It would be GREAT if this token could be saved to disk, so that it could be re-used at startup (unless the server was down for a longer period off course).

Is this (easily) possible. Did you think about this option?

@ondrej1024
Copy link
Owner

Hi,

I have just recently implemented a new Carelink client which is based on the API used by the Carelink Connect app. This new client has the advantage that it uses a refresh token in addition to the access token. The refresh token can be used to get a new access token, even of it is expired (for a week afterwards). The latest tokens are always saved to a file on disk, so everything works also after reboot.

You can have a look here:
https://github.com/ondrej1024/carelink-python-client/tree/new_client/new_api

The proxy is still missing in this folder, I am still porting and testing it. But you can already try the login script carelink_carepartner_api_login.py (which generates the new token file) and the carelink_client2_cli.py program, to see if it works for you.

@GertVanderstukken
Copy link
Author

Cool!

I will try it while waiting for the proxy....
Thanks a lot.

@ondrej1024
Copy link
Owner

ondrej1024 commented Jan 14, 2024

I have just added the new proxy new_api/carelink_client2_proxy.py and updated the README. It's running fine here. Only the WebGUI with the proxy status information is still very basic. I plan to add the possibility to upload the token file via this GUI. Currently you have to copy it manually to the device where the proxy is running.

Please give it a try and report back.

@GertVanderstukken
Copy link
Author

Great
I will test it tomorrow and let you know!

@GertVanderstukken
Copy link
Author

OK, I could not wait, so I tested it right away and it works!

I only have to look into the systemd Unit/Service file.
I had to insert an ExecStartPre with a delay, because for some reason the start fails without it.
However: this has off course nothing to do with your script/work.

Right now, I can reboot my server and after the reboot, the proxy is working and exposing the webclient without any manual intervention: Perfect!

I will keep on monitoring and also try to find the exact reason why I have to insert the delay into the service file.
If I find something I will post it here so other people can benefit from it.

Great work!!!

@GertVanderstukken
Copy link
Author

OK,
I just adapted the systemd service file like this:

From:
After=syslog.target network.target

To:
After=syslog.target network-online.target

All is good now.
FYI: I'm running this on Rocky Linux 8.9

@ondrej1024
Copy link
Owner

Thanks for testing and your feedback. Good to hear that things are working also for you.
I plan to add some more info in the README to describe how to install the proxy as systemd service.

@ondrej1024
Copy link
Owner

The new proxy based on the Carelink client2 has been running continuously for 2 weeks here. So it seems stable, at least for me. I have merged the new client code to the main branch (the old code is still in the client1 folder).

Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants