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

Possible Issue at Startup #380

Closed
mumblebaj opened this issue Jun 6, 2024 · 18 comments
Closed

Possible Issue at Startup #380

mumblebaj opened this issue Jun 6, 2024 · 18 comments

Comments

@mumblebaj
Copy link

Hi,

I have noticed a few people posting that the module is not working when they startup in the morning. I believe that the below code is where the issue is.

    // get a new token at start-up. When receive, GET_CAMERA_EVENTS will be requested
    setTimeout(function () {
      self.sendSocketNotification(self.notifications.DATA, self.config)
    }, this.config.initialDelay * 1000)

I believe that you may want to call self.notifications.AUTH at startup which would then get a new token using the old token it had. Unless I am mistaken.

Can you please check this out?

Thanks

@Gabian34
Copy link

Gabian34 commented Jun 7, 2024

Hi,

Same issue at startup since a few days, no change when replacing DATA by AUTH in the module code. The only way to display informations is to generate a new refresh token but the problem appears again at next MM launch.

@Empyreum
Copy link

Empyreum commented Jun 9, 2024

Hi,

I'm experiencing the same issue here.
As @Gabian34 mentioned it can be solved by generating a new refresh token, but will be a problem again on next startup of the module.

@swopeman
Copy link

Hi,

I also have these errors like @Empyreum @Gabian34

@mumblebaj
Copy link
Author

How about using the Client Credentials API to request a token instead of relying on the user to provide a token?

https://dev.netatmo.com/apidocumentation/oauth#client-credential

This should resolve the issue. Unfortunately I do not have any credentials for Netatmo as I do not have any devices else I would have made the changes for you.

@Gabian34
Copy link

Hi, @bugsounet fixed it in his MMM-NetatmoThermostat module (same API … so same Issue). Solution consists in stocking a token in token.json local file. I m not a developper , so if someone could apply his solution...

@bugsounet
Copy link
Contributor

bugsounet commented Jun 14, 2024

No... From doc, When authenticate Netatmo server will send an access_token (for any query) AND it will send NEXT refresh token to use when access_token expire (10800 sec)

So... just save token result on authenticate and use saved refresh_token on restart MM²

Let's Restart MM² with this rule:

[2024-06-14 12:10:31.030] [LOG]   [NETATMO] Starting MMM-NetatmoThermostat module... 
[2024-06-14 12:10:31.031] [LOG]   [NETATMO] Use token.json for Authenticate 
[2024-06-14 12:10:32.135] [LOG]   [NETATMO] token.json was written successfully 
[2024-06-14 12:10:32.136] [LOG]   [NETATMO] Authenticated! 
[2024-06-14 12:10:32.138] [LOG]   [NETATMO] Token Expire Friday, June 14, 2024 3:09 PM 

access_token on config file is used ONLY on the first authenticate (first use of the module) and is no longer used after On restart of MM² must use saved token file (check presence of the file)

For helping from my module MMM-NetatmoThermostat:

  • It's not the same module but API is the same (only used for read_thermostat scope)
  • this is my change

It's up to you to adapt it to this module
I have no weather station for make a PR and test it

@bugsounet

@CFenner
Copy link
Owner

CFenner commented Jun 14, 2024

Thanks! I'll try to reserve some time on the weekend to look at this.

@bugsounet
Copy link
Contributor

No problem, Thanks for them ;)

@mumblebaj
Copy link
Author

Thanks @CFenner and @bugsounet

@swopeman
Copy link

Is there anything new?

@bugsounet
Copy link
Contributor

bugsounet commented Jun 21, 2024

need help @CFenner ?

If you have not time really, I can try in my side (auth/refresh /save part)
I think with my netatmo account I can code (recode) it
But you have to see if it's work really with sensor

@bugsounet
Copy link
Contributor

(because i'm kind, i will code it)

@bugsounet
Copy link
Contributor

Good news:

  • I finish to recode it ;))
  • Tested successfully by @Lusbueb69

@Lusbueb69
Copy link

Lusbueb69 commented Jun 22, 2024

Good news:

  • I finish to recode it ;))
  • Tested successfully by @Lusbueb69

i have choose an this way to test:

  • pm2 stop mm
  • rename the existing folder netatmo to netatmo.240622
  • cd ~/MagicMirror/modules && git clone https://github.com/bugsounet/MMM-Netatmo netatmo
  • cd netatmo && npm ci --production --ignore-scripts
  • generate a new refresh-token an insert the new token in config.js
  • pm2 start mm

i'm so happy, everything works fine, still after a RPI reboot or a pm2 restart mm.

@bugsounet
Copy link
Contributor

I 'm not completely agree with this method because I will destroy my fork once the modifications are made on the @CFenner repo

So... it's only for testing :)
In All case, Happy use!

@Gabian34
Copy link

@bugsounet Good job, it works perfectly ! Many thanks for your help ...

@bugsounet
Copy link
Contributor

bugsounet commented Jun 23, 2024

Right !

@CFenner have merge my Pull Request

Thanks for this testing but you have to return to @CFenner repository and make a git pull
I will delete my fork, so that @CFRunner have the exclusivity of this module

Happy use,
@bugsounet

Note: @mumblebaj , you can now close this issue :)

@mumblebaj
Copy link
Author

Fix merged from @bugsounet

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

7 participants