You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.7 KiB

+++
title = 'Update weewx-netatmo extension'
aliases = '/posts/2023-07-15-update-weewx-netatmo-extension'
summary = 'Upgrade the authentication method from *password* to *preauthenticated refresh_token*'
date = '2023-07-15T17:02:10+02:00'
lastmod = '2023-12-10T16:34:13+0000'
categories = [ 'amateur-radio' ]
tags = [ 'wx', 'weewx', 'netatmo', 'server', 'selfhost' ]
+++
I got an email from another weewx-netatmo user Patrick yesterday, in which he asked if
my WeeWX installation was still running, because we use the same extension to fetch the
weather data from the netatmo servers (this method `cloud` is already rediculous, but it
works with that hardware, so yes...).
After looking on my servers logfiles I could confirm the extension wasn't working as
expected any more.
Today [I found an actual fork of the fork of the original extension][forked]:
<https://github.com/Buco7854/weewx-netatmo>
[forked]: https://github.com/matthewwall/weewx-netatmo/issues/21#issuecomment-1636757236
## And this is how I upgraded the netatmo weewx extension
Uninstall the old extension:
```console
$ doas -u weewx /home/weewx/bin/wee_extension --uninstall netatmo
```
Download and install the new extension:
```console
$ doas -u weewx wget -O weewx-netatmo.zip https://github.com/Buco7854/weewx-netatmo/archive/master.zip
$ doas -u weewx /home/weewx/bin/wee_extension --install weewx-netatmo.zip
```
Go to <https://dev.netatmo.com/apps/> and update your app to include a `refresh_token`.
Update the configuration with
```console
$ doas -u weewx /home/weewx/bin/wee_config --reconfigure
```
That should already ask for your refresh_token. Double check this in your `weewx.conf`
configuration file, as it might not get written properly (like in my case).
The configuration should look like this now:
```toml
[netatmo]
client_id = ************************
client_secret = ***************************
refresh_token = ************************|********************************
driver = user.netatmo
mode = cloud
```
I removed the `username` and `password` variables but added the `refresh_token` manually
because the configuration was not properly written by `wee_config --reconfigure`.
A restart of WeeWX should fetch the data again.
```console
$ doas rcctl restart weewx
```
## Random failure on authentication to netatmo server
It sometimes happens at my server that I only get a 400 response:
~~~plain
weewxd: netatmo: netatmo-client: failed attempt 1 of 5 to get data: HTTP Error 400:
weewxd: netatmo: netatmo-client: failed attempt 2 of 5 to get data: HTTP Error 400:
weewxd: netatmo: netatmo-client: failed attempt 3 of 5 to get data: HTTP Error 400:
weewxd: netatmo: netatmo-client: failed attempt 4 of 5 to get data: HTTP Error 400:
weewxd: netatmo: netatmo-client: failed attempt 5 of 5 to get data: HTTP Error 400:
weewxd: netatmo: netatmo-client: failed to get data after 5 attempts
~~~
![showing the menu](update-refresh-token.png "`read_station` is all you need")
I don't have found a solution for this yet...
## Problems on a Raspberry Pi?
I'm not sure about the cause of this behaviour, but **Andreas DG0LFL** reported, that his
Raspberry Pi 4 (running Debian 10 Buster) could not update the token so he solved this by
creating `/etc/systemd/system/weewx.timer` with the following contents:
```ini
[Unit]
Description=WeeWX-Timer
[Timer]
OnBootSec=5min
OnUnitActiveSec=120min
Unit=weewx.service
[Install]
WantedBy=multi-user.target
```
As for my understanding this should start `weewx.service` 5 minutes after system boot as well as
every 120 minutes after the services last start.
He had noticed, that the netatmo-driver wasn't updating the token so it got invalid after 10800
seconds (3 hours).
You would probably need to run `systemctl enable weewx.timer` to enable the timer.