diff --git a/.gitignore b/.gitignore index 7ef0d7d..11533c8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ .idea/modules.xml .idea/weatherlinklive-driver-weewx.iml .idea/workspace.xml +docs/_config.yml +docs/index.md diff --git a/bin/user/WLLDriver.py b/bin/user/WLLDriver.py index da5a36b..11a5938 100644 --- a/bin/user/WLLDriver.py +++ b/bin/user/WLLDriver.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 DRIVER_NAME = "WLLDriver" -DRIVER_VERSION = "0.3a" +DRIVER_VERSION = "2020.12-1" import json import requests @@ -317,13 +317,6 @@ def calculate_rain(self, dt_wll, rainFall_Daily, rainRate, rainSize): rain = None rain_multiplier = None - # Reset previous rain at midnight - if dt_wll is not None and self.last_midnight < dt_wll: - loginf('Reset rainfall_Daily at midnight') - self.rain_previous_period = 0 - self.last_midnight = self.get_last_midnight(int(dt_wll)) - logdbg("Last midnight set is : {}".format(self.last_midnight)) - # Check bucket size if rainSize is not None: if rainSize == 1: @@ -333,24 +326,36 @@ def calculate_rain(self, dt_wll, rainFall_Daily, rainRate, rainSize): if rainSize == 3: rain_multiplier = 0.1 - # Calculate rain - if rainFall_Daily is not None and rain_multiplier is not None: - if self.rain_previous_period is not None: - if (rainFall_Daily - self.rain_previous_period) < 0: - logerr("rain can't be a negative number. Skip this and set rain to 0") - rain = 0 - else: - rain = (rainFall_Daily - self.rain_previous_period) * rain_multiplier - - if rain is not None and rainSize is not None and rain > 0: - logdbg("Rain now : {}".format(rain)) - - if rainSize == 2: - rain = rain / 25.4 - if rainSize == 3: - rain = rain / 2.54 + # Reset previous rain at midnight + if dt_wll is not None and self.last_midnight < dt_wll: + loginf('Reset rainfall_Daily at midnight. Skip rainfall_daily calculate to prevent overflow value') + self.rain_previous_period = 0 + self.last_midnight = self.get_last_midnight(int(dt_wll)) + logdbg("Last midnight set is : {}".format(self.last_midnight)) else: - rain = None + # Calculate rain + if rainFall_Daily is not None and rain_multiplier is not None: + if self.rain_previous_period is not None: + if (rainFall_Daily - self.rain_previous_period) < 0: + logerr("rain can't be a negative number. Skip this and set rain to 0") + rain = 0 + else: + rain = (rainFall_Daily - self.rain_previous_period) * rain_multiplier + + if rain is not None and rainSize is not None and rain > 0: + logdbg("Rain now : {}".format(rain)) + + if rainSize == 2: + rain = rain / 25.4 + if rainSize == 3: + rain = rain / 2.54 + else: + rain = None + + # Set rainFall_Daily to previous rain + if rainFall_Daily is not None and rainFall_Daily >= 0: + self.rain_previous_period = rainFall_Daily + logdbg("Rainfall_Daily set after calculated : {}".format(self.rain_previous_period)) # Calculate rainRate if rainRate is not None and rain_multiplier is not None: @@ -365,11 +370,6 @@ def calculate_rain(self, dt_wll, rainFall_Daily, rainRate, rainSize): else: rainRate = None - # Set rainFall_Daily to previous rain - if rainFall_Daily is not None and rainFall_Daily >= 0: - self.rain_previous_period = rainFall_Daily - logdbg("Rainfall_Daily set after calculated : {}".format(self.rain_previous_period)) - return rain, rainRate # ------------------------------------------------------------------------------------------------------------------ diff --git a/docs/_config.yml b/docs/_config.yml deleted file mode 100644 index c419263..0000000 --- a/docs/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-cayman \ No newline at end of file diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index 2ae6bd8..0000000 --- a/docs/index.md +++ /dev/null @@ -1,128 +0,0 @@ -WLLDriver -============ -Created this driver to make request to WeatherLinkLive module including archive from Weatherlink.com when data be lost on Weewx. - -## Installation - -- Download the latest release of WLLDriver : https://github.com/Drealine/weatherlinklive-driver-weewx/releases -- Install the driver : ```wee_extension --install WLLDriver.zip``` -- Find on **weewx.conf** ```station_type``` and change by this : ```station_type = WLLDriver``` -- If you want to retrieve new data when the driver fail, set ```loop_on_init = True``` on **weewx.conf** -- Restart weewx : ```service weewx restart``` - -### Accumulator for rainRate - -When install the driver, a parameter is write to the **weewx.conf** : -``` -[Accumulator] - [[rainRate]] - extractor = max -``` - -**Not delete this** because this allow the driver -to set the correct rainRate max each archive interval of Weewx. - -## Configuration on Weewx - -After installing driver, a new stanza appear at the end of the file **weewx.conf**. - -The correct syntax for set a parameter is : ```blabla = 1``` - -### Default setting needed to run the driver - -- ```max_tries``` - Max tries before Weewx raise an exception and finished the loop.
-- ```retry_wait``` - Time to retry in second between each.
-- ```poll_interval``` - Time to sleep in second between 2 requests.
-- ```realtime_enable``` - Enable realtime each 3 secondes for Wind and Rain.
-- ```hostname``` - Set your IP or hostname of WLL module.
-- ```time_out``` - Set this for timeout in second of HTTP and realtime request.
-- ```device_id``` - Set the ID of your ISS that you've configured on the WLL Module.
-- ```wl_archive_enable``` - Enable retrieve data from Weatherlink.com.
- -NB : For the driver work good, set ```retry_wait = 2 x poll_interval```. In this case, the driver do not sent a lot of requests.
-To calculate the time after the driver raise en exception and stop Weewx, do ```max_tries x retry_wait``` - -### Realtime for wind and rain - -**/!\ Realtime not work if Weewx is out of your lan network.** - -With the WLLDriver, you can enable realtime to retrieve data from wind and rain sensors each 2.5s.
-If you have enabled ```realtime_enable = 1```, please note that all others sensors would be reach each ```poll_interval```
-So, make sur that ```poll_interval``` has a number wich is more than 2 * 2.5s. For better use, set ```poll_interval = 10```
-The temperature or barometer for example does not vary greatly.
- -### Retrieve data from Weatherlink.com - -If you want to use weatherlink.com to retrieve lost data when Weewx crash for example,
you have to create an API Key : - -- Create your API Key v2 on https://www.weatherlink.com/account -- Use this tool to know your station ID : https://repl.it/repls/MeaslyExternalMegabyte#main.php by change ```api-key``` and ```api-secret``` and run the script. - -Enable the feature ```wl_archive_enable = 1``` and set parameters on **weewx.conf** in [WLLDriver] : - -- ```wl_apikey``` - Create an API Key on your Weatherlink account. -- ```wl_apisecret``` - By creating API Key, you've also need an API Secret. -- ```wl_stationid``` - Check your station ID by using the method explain before. -- ```wl_archive_interval``` - Be carefull by set this because it depending on your subscription on Weatherlink.com. For better use, please set the same archive interval than the Weewx engine. - -### Add extra sensor or deported sensor - -WLLDriver support at the moment only 5 extraTemp, 5 extraHumid or 1 Wind deported. - -Correct syntax is ```device:id_of_device``` where : - -- ```device``` is the **sensor** -- ```id_of_device``` is the **id** that you've set when you configure the sensor with the WLL module - -| Sensor | Type | -| ------|-----| -| **iss** | Set the ISS | -| **extraTempX** | Set an extra temperature sensor with X is the number | -| **extraHumidX** | Set an extra humidity sensor with X is the number | -| **extraAnemometer** | Set a deported anemometer if it's not connected to the ISS | - -**/!\ ISS and ID must be put first on ```device_id```.**
-**/!\ When adding sensors, make sur that schema is correct on Weewx. If not, please add a schema by following this tutorial : https://github.com/poblabs/weewx-belchertown/wiki/Adding-a-new-observation-type-to-the-WeeWX-database** - -If you want to enable for example an extra temp sensor, set like this : ```device_id = iss:1-extraTemp1:2```
-You can ajust and add more extra sensors like this : ```device_id = iss:1-extraTemp1:2-extraTemp2:4-extraHumid1:7```
-Each parameter is separated by **```-```** - -### Wind gust 2min - -**/!\ Not supported if realtime is enabled.** - -Weatherlink Live module can calculate wind gust each 2min instead of 10min by default.
-To enable this, set this parameter on [WLLDriver] : ```wind_gust_2min_enable = 1``` - -### Change HTTP port - -You can change the default port 80 to set a new port to request to the WLL module. To change to 8080 for example, set this parameter on [WLLDriver] : ```port = 8080``` - -### Health status of ISS & WLL - -**/!\ If you disable ```wl_archive_enable = 0```, you will not have the health status.** - -WLLDriver recuperate value for health ISS and WLL module each 15 minutes on Weatherlink.com : - -| Parameter | Type | -| ------|-----| -| **txBatteryStatus** | Transmitter battery | -| **rxCheckPercent** | Signal quality | -| **consBatteryVoltage** | Battery in volt of the WLL module | -| **supplyVoltage** | Supply voltage of the WLL module | - -## Default value for each parameter - -| Parameter | Default value | Min/Max | -| ------|-----|-----| -| **max_tries** | 10 | 0/200 | -| **retry_wait** | 10 | 0/NA | -| **poll_interval** | 5 | 0/NA | -| **realtime_enable** | 0 | 0 = Disable / 1 = Enable | -| **time_out** | 10 | 0/15 | -| **wl_archive_enable** | 0 | 0 = Disable / 1 = Enable | -| **device_id** | iss:1 | NA | -| **wl_archive_interval** | NA | 1, 5 or 15 | -| **wind_gust_2min_enable** | Not set so, 0 | 0 = Disable / 1 = Enable | -| **port** | 80 | NA |