Skip to content

Commit

Permalink
Improved collision avoidance in Davis WLL
Browse files Browse the repository at this point in the history
Add missing average temperature calculation during Ecowitt catch-up
  • Loading branch information
Mark Crossley committed Dec 29, 2022
1 parent 31d75a2 commit d893fd4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
6 changes: 3 additions & 3 deletions CumulusMX/DavisWllStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,11 @@ private async void GetWllCurrent(object source, ElapsedEventArgs e)
{
var urlCurrent = $"http://{ip}/v1/current_conditions";

var timeSinceLastMessage = (int) DateTime.Now.Subtract(LastDataReadTimestamp).TotalMilliseconds;
var timeSinceLastMessage = (int) (DateTime.Now.Subtract(LastDataReadTimestamp).TotalMilliseconds % 2500);
if (timeSinceLastMessage > 1500)
{
// Another broadcast is due, half a second or so
var delay = Math.Max(200, 2500 - timeSinceLastMessage);
// Another broadcast is due in the next second or less
var delay = Math.Max(200, 2600 - timeSinceLastMessage);
cumulus.LogDebugMessage($"GetWllCurrent: Delaying {delay} ms");
tmrCurrent.Stop();
await Task.Delay(delay);
Expand Down
59 changes: 45 additions & 14 deletions CumulusMX/EcowittApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public EcowittApi(Cumulus cuml, WeatherStation stn)
}

// Let's decode the Unix ts to DateTime
JsConfig.Init(new Config {
JsConfig.Init(new Config {
DateHandler = DateHandler.UnixTime
});

Expand Down Expand Up @@ -229,7 +229,7 @@ internal bool GetHistoricData(DateTime startTime, DateTime endTime)
// get the sensor data
var histObj = responseBody.FromJson<EcowittHistoricResp>();

if (histObj != null)
if (histObj != null)
{
// success
if (histObj.code == 0)
Expand Down Expand Up @@ -371,7 +371,7 @@ private void ProcessHistoryData(EcowittHistoricData data)
if (data.outdoor != null)
{
try
{
{
// Temperature
if (data.outdoor.temperature != null && data.outdoor.temperature.list != null)
{
Expand Down Expand Up @@ -418,7 +418,7 @@ private void ProcessHistoryData(EcowittHistoricData data)
}
}
}

// Dewpoint
if (data.outdoor.dew_point != null && data.outdoor.dew_point.list != null)
{
Expand Down Expand Up @@ -497,7 +497,7 @@ private void ProcessHistoryData(EcowittHistoricData data)
}
}
}

// Direction
if (data.wind.wind_direction != null && data.wind.wind_direction.list != null)
{
Expand Down Expand Up @@ -566,7 +566,7 @@ private void ProcessHistoryData(EcowittHistoricData data)
{
if (cumulus.Gw1000PrimaryRainSensor == 0)
{
// rain rate
// rain rate
if (data.rainfall.rain_rate != null && data.rainfall.rain_rate.list != null)
{
foreach (var item in data.rainfall.rain_rate.list)
Expand Down Expand Up @@ -614,7 +614,7 @@ private void ProcessHistoryData(EcowittHistoricData data)
}
else // rainfall piezo
{
// rain rate
// rain rate
if (data.rainfall_piezo.rain_rate != null && data.rainfall_piezo.rain_rate.list != null)
{
foreach (var item in data.rainfall_piezo.rain_rate.list)
Expand Down Expand Up @@ -693,7 +693,7 @@ private void ProcessHistoryData(EcowittHistoricData data)
}
}
}

// uvi
if (data.solar_and_uvi.uvi != null && data.solar_and_uvi.uvi.list != null)
{
Expand Down Expand Up @@ -808,7 +808,7 @@ private void ProcessHistoryData(EcowittHistoricData data)
}
}
}

// humidity
if (srcTH.humidity != null && srcTH.humidity.list != null)
{
Expand Down Expand Up @@ -956,7 +956,7 @@ private void ProcessHistoryData(EcowittHistoricData data)
}
}
}

// 24 Avg
if (data.indoor_co2.average24h != null && data.indoor_co2.average24h.list != null)
{
Expand Down Expand Up @@ -1012,7 +1012,7 @@ private void ProcessHistoryData(EcowittHistoricData data)
}
}
}

// 24 Avg
if (data.co2_aqi_combo.average24h != null && data.co2_aqi_combo.average24h.list != null)
{
Expand Down Expand Up @@ -1205,6 +1205,9 @@ private void ProcessHistoryData(EcowittHistoricData data)
cumulus.LogDebugMessage("Adding 5 minutes to Sunshine Hours");
}

// add in archive period minutes worth of temperature to the temp samples
station.tempsamplestoday += 5;
station.TempTotalToday += (station.OutdoorTemperature * 5);

// add in 'following interval' minutes worth of wind speed to windrun
cumulus.LogMessage("Windrun: " + station.WindAverage.ToString(cumulus.WindFormat) + cumulus.Units.WindText + " for " + 5 + " minutes = " +
Expand Down Expand Up @@ -1265,7 +1268,10 @@ private void ApplyHistoricData(KeyValuePair<DateTime, EcowittApi.HistoricData> r
var dirVal = (int)rec.Value.WindDir.Value;

station.DoWind(gustVal, dirVal, spdVal, rec.Key);

}
else
{
cumulus.LogMessage("ApplyHistoricData: Insufficient data process wind");
}
}
catch (Exception ex)
Expand All @@ -1281,11 +1287,20 @@ private void ApplyHistoricData(KeyValuePair<DateTime, EcowittApi.HistoricData> r
{
station.DoIndoorHumidity(rec.Value.IndoorHum.Value);
}
else
{
cumulus.LogMessage("ApplyHistoricData: Missing indoor humidity data");
}

if (rec.Value.Humidity.HasValue && cumulus.Gw1000PrimaryTHSensor == 0)
{
station.DoOutdoorHumidity(rec.Value.Humidity.Value, rec.Key);
}
else
{
cumulus.LogMessage("ApplyHistoricData: Missing outdoor humidity data");
}

}
catch (Exception ex)
{
Expand All @@ -1302,6 +1317,10 @@ private void ApplyHistoricData(KeyValuePair<DateTime, EcowittApi.HistoricData> r
station.DoPressure(pressVal, rec.Key);
station.UpdatePressureTrendString();
}
else
{
cumulus.LogMessage("ApplyHistoricData: Missing pressure data");
}
}
catch (Exception ex)
{
Expand All @@ -1317,6 +1336,10 @@ private void ApplyHistoricData(KeyValuePair<DateTime, EcowittApi.HistoricData> r
var tempVal = (double)rec.Value.IndoorTemp;
station.DoIndoorTemp(tempVal);
}
else
{
cumulus.LogMessage("ApplyHistoricData: Missing indoor temperature data");
}
}
catch (Exception ex)
{
Expand All @@ -1332,6 +1355,10 @@ private void ApplyHistoricData(KeyValuePair<DateTime, EcowittApi.HistoricData> r
var tempVal = (double)rec.Value.Temp;
station.DoOutdoorTemp(tempVal, rec.Key);
}
else
{
cumulus.LogMessage("ApplyHistoricData: Missing outdoor temperature data");
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1360,6 +1387,10 @@ private void ApplyHistoricData(KeyValuePair<DateTime, EcowittApi.HistoricData> r
var rateVal = rRate;
station.DoRain(rainVal, rateVal, rec.Key);
}
else
{
cumulus.LogMessage("ApplyHistoricData: Missing rain data");
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1753,7 +1784,7 @@ internal class EcowittHistoricDataSoil
{
public EcowittHistoricDataTypeInt soilmoisture { get; set; }
}

internal class EcowittHistoricDataTemp
{
public EcowittHistoricDataTypeDbl temperature { get; set; }
Expand All @@ -1767,7 +1798,7 @@ internal class EcowittHistoricDataLeaf
internal class EcowittHistoricDataLightning
{
public EcowittHistoricDataTypeDbl distance { get; set; }
public EcowittHistoricDataTypeInt count { get; set; }
public EcowittHistoricDataTypeInt count { get; set; }
}

[DataContract]
Expand Down
1 change: 1 addition & 0 deletions Updates.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Fixed
- Fix Custom HTTP intervals from trying to process null entries
- Fix for Davis WLL missed broadcast package counter not being incremented
- Fix for Davis WLL processing broadcast messages twice or more on systems with both IPv4 and IPv6 enabled
- Fix for missing average temperature calculation during Ecowitt catch-up


3.22.4 - b3215
Expand Down

0 comments on commit d893fd4

Please sign in to comment.