Skip to content

Commit

Permalink
Merge pull request #144 from mcrossley/master
Browse files Browse the repository at this point in the history
v3.16.1
  • Loading branch information
mcrossley authored May 6, 2022
2 parents 96b24da + 2a4f66c commit 0d5d201
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 131 deletions.
20 changes: 17 additions & 3 deletions CumulusMX/Cumulus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,23 @@ public struct MqttSettings

public string[] StationDesc =
{
"Davis Vantage Pro", "Davis Vantage Pro2", "Oregon Scientific WMR-928", "Oregon Scientific WM-918", "EasyWeather", "Fine Offset",
"LaCrosse WS2300", "Fine Offset with Solar", "Oregon Scientific WMR100", "Oregon Scientific WMR200", "Instromet", "Davis WLL", "GW1000",
"HTTP WUnderground", "HTTP Ecowitt", "HTTP Ambient", "WeatherFlow Tempest"
"Davis Vantage Pro", // 0
"Davis Vantage Pro2", // 1
"Oregon Scientific WMR-928", // 2
"Oregon Scientific WM-918", // 3
"EasyWeather", // 4
"Fine Offset", // 5
"LaCrosse WS2300", // 6
"Fine Offset with Solar", // 7
"Oregon Scientific WMR100", // 8
"Oregon Scientific WMR200", // 9
"Instromet", // 10
"Davis WLL", // 11
"GW1000", // 12
"HTTP WUnderground", // 13
"HTTP Ecowitt", // 14
"HTTP Ambient", // 15
"WeatherFlow Tempest" // 16
};

public string[] APRSstationtype = { "DsVP", "DsVP", "WMR928", "WM918", "EW", "FO", "WS2300", "FOs", "WMR100", "WMR200", "IMET", "DsVP", "Ecow", "Unkn", "Ecow", "Ambt", "Tmpt" };
Expand Down
65 changes: 52 additions & 13 deletions CumulusMX/DavisWllStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ internal class DavisWllStation : WeatherStation
private bool wllVoltageLow;
private CancellationTokenSource tokenSource = new CancellationTokenSource();
private CancellationToken cancellationToken;
private Task broadcastTask;
private AutoResetEvent bwDoneEvent = new AutoResetEvent(false);
private readonly List<WlSensor> sensorList = new List<WlSensor>();
private readonly bool useWeatherLinkDotCom = true;

Expand All @@ -66,6 +68,7 @@ public DavisWllStation(Cumulus cumulus) : base(cumulus)
string utcTimeFormat = "yyyy-MM-dd'T'HH:mm:ss.fff'Z'";
string localTimeFormat = "yyyy-MM-dd'T'HH:mm:ss";

cancellationToken = tokenSource.Token;

ServiceStack.Text.JsConfig<DateTime>.DeSerializeFn = datetimeStr =>
{
Expand Down Expand Up @@ -281,10 +284,8 @@ public override void Start()
cumulus.WriteIniFile();
}

cancellationToken = tokenSource.Token;

// Create a broadcast listener
Task.Run(() =>
broadcastTask = Task.Run(() =>
{
using (var udpClient = new UdpClient())
{
Expand Down Expand Up @@ -361,17 +362,40 @@ public override void Stop()
cumulus.LogMessage("Closing WLL connections");
try
{
tokenSource.Cancel();
tmrRealtime.Stop();
tmrCurrent.Stop();
tmrBroadcastWatchdog.Stop();
tmrHealth.Stop();
StopMinuteTimer();
if (tmrRealtime != null)
tmrRealtime.Stop();
if (tmrCurrent != null)
tmrCurrent.Stop();
if (tmrBroadcastWatchdog != null)
tmrBroadcastWatchdog.Stop();
if (tmrHealth != null)
tmrHealth.Stop();
}
catch
{
cumulus.LogMessage("Error stopping station timers");
}

StopMinuteTimer();
try
{
if (tokenSource != null)
{
tokenSource.Cancel();
}
if (bw != null && bw.WorkerSupportsCancellation)
{
bw.CancelAsync();
}
if (broadcastTask != null)
broadcastTask.Wait();

bwDoneEvent.WaitOne();
}
catch
{
cumulus.LogMessage("Error stopping station background tasks");
}
}

private async void GetWllRealtime(object source, ElapsedEventArgs e)
Expand Down Expand Up @@ -1380,7 +1404,7 @@ public override void startReadingHistoryData()
LoadLastHoursFromDataLogs(cumulus.LastUpdateTime);

cumulus.LogMessage("WLL history: Reading archive data from WeatherLink API");
bw = new BackgroundWorker();
bw = new BackgroundWorker { WorkerSupportsCancellation = true };
//histprog = new historyProgressWindow();
//histprog.Owner = mainWindow;
//histprog.Show();
Expand Down Expand Up @@ -1433,6 +1457,8 @@ private void bw_DoStart(object sender, DoWorkEventArgs e)

private void bw_ReadHistory(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;

int archiveRun = 0;
cumulus.LogDebugMessage("Lock: Station waiting for the lock");
Cumulus.syncInit.Wait();
Expand Down Expand Up @@ -1461,19 +1487,20 @@ private void bw_ReadHistory(object sender, DoWorkEventArgs e)

do
{
GetWlHistoricData();
GetWlHistoricData(worker);
archiveRun++;
} while (archiveRun < maxArchiveRuns);
} while (archiveRun < maxArchiveRuns && worker.CancellationPending == false);
}
catch (Exception ex)
{
cumulus.LogMessage("Exception occurred reading archive data: " + ex.Message);
}
cumulus.LogDebugMessage("Lock: Station releasing the lock");
Cumulus.syncInit.Release();
bwDoneEvent.Set();
}

private void GetWlHistoricData()
private void GetWlHistoricData(BackgroundWorker worker)
{
cumulus.LogMessage("GetWlHistoricData: Get WL.com Historic Data");

Expand Down Expand Up @@ -1647,6 +1674,9 @@ private void GetWlHistoricData()

for (int dataIndex = 0; dataIndex < noOfRecs; dataIndex++)
{
if (worker.CancellationPending == true)
return;

try
{
// Not all sensors may have the same number of records. We are using the WLL to create the historic data, the other sensors (AirLink) may have more or less records!
Expand Down Expand Up @@ -1698,6 +1728,9 @@ private void GetWlHistoricData()

foreach (var sensor in histObj.sensors)
{
if (worker.CancellationPending == true)
return;

int sensorType = sensor.sensor_type;
int dataStructureType = sensor.data_structure_type;
int lsid = sensor.lsid;
Expand All @@ -1709,6 +1742,9 @@ private void GetWlHistoricData()
var found = false;
foreach (var dataRec in sensor.data)
{
if (worker.CancellationPending == true)
return;

var rec = dataRec.FromJsv<WlHistorySensorDataType17>();
if (rec.ts == refData.ts)
{
Expand All @@ -1734,6 +1770,9 @@ private void GetWlHistoricData()
var found = false;
foreach (var dataRec in sensor.data)
{
if (worker.CancellationPending == true)
return;

var rec = dataRec.FromJsv<WlHistorySensorDataType17>();

if (rec.ts == refData.ts)
Expand Down
17 changes: 12 additions & 5 deletions CumulusMX/EcowittApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,14 @@ internal bool GetHistoricData(DateTime startTime, DateTime endTime)
else
{
// There was no data returned.
cumulus.LastUpdateTime = endTime;
return false;
}
}
catch (Exception ex)
{
cumulus.LogMessage("API.GetHistoricData: Error decoding the response - " + ex.Message);
cumulus.LastUpdateTime = endTime;
return false;
}
}
Expand All @@ -258,10 +260,11 @@ internal bool GetHistoricData(DateTime startTime, DateTime endTime)

// have we reached the retry limit?
if (--retries <= 0)
return false;
cumulus.LastUpdateTime = endTime;
return false;

cumulus.LogMessage("API.GetHistoricData: System Busy or Rate Limited, waiting before retry...");
System.Threading.Thread.Sleep(1500);
cumulus.LogMessage("API.GetHistoricData: System Busy or Rate Limited, waiting 5 secs before retry...");
System.Threading.Thread.Sleep(5000);
}
else
{
Expand All @@ -270,6 +273,7 @@ internal bool GetHistoricData(DateTime startTime, DateTime endTime)
}
else
{
cumulus.LastUpdateTime = endTime;
return false;
}

Expand Down Expand Up @@ -1183,9 +1187,11 @@ private void ProcessHistoryData(EcowittHistoricData data)

// add in archive period worth of sunshine, if sunny
if (station.SolarRad > station.CurrentSolarMax * cumulus.SolarOptions.SunThreshold / 100 &&
station.SolarRad >= cumulus.SolarOptions.SolarMinimum)
station.SolarRad >= cumulus.SolarOptions.SolarMinimum &&
!cumulus.SolarOptions.UseBlakeLarsen)
{
station.SunshineHours += 5 / 60.0;

}


// add in 'following interval' minutes worth of wind speed to windrun
Expand Down Expand Up @@ -1739,6 +1745,7 @@ internal class EcowittHistoricDataSoil
{
public EcowittHistoricDataTypeInt soilmoisture { get; set; }
}

internal class EcowittHistoricDataTemp
{
public EcowittHistoricDataTypeDbl temperature { get; set; }
Expand Down
100 changes: 63 additions & 37 deletions CumulusMX/GW1000Station.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public GW1000Station(Cumulus cumulus) : base(cumulus)
cumulus.LogMessage("Overriding the default outdoor temp/hum data with Extra temp/hum sensor #" + cumulus.Gw1000PrimaryTHSensor);
}

if (cumulus.Gw1000PrimaryRainSensor == 0)
{
// We are using the traditional rain tipper
cumulus.LogMessage("Using the default traditional rain sensor data");
}
else
{
cumulus.LogMessage("Using the piezo rain sensor data");
}

cancellationToken = tokenSource.Token;

ipaddr = cumulus.Gw1000IpAddress;
Expand Down Expand Up @@ -624,15 +634,15 @@ private bool PrintSensorInfoNew(byte[] data, int idx)
case string wh34 when wh34.StartsWith("WH34"): // ch 1-8
case string wh35 when wh35.StartsWith("WH35"): // ch 1-8
case "WH90":
// if a WS90 is connected, it has a 4.75 second update rate, so reduce the MX update rate from the default 10 seconds
if (updateRate > 4000 && updateRate != 4000)
// if a WS90 is connected, it has a 8.8 second update rate, so reduce the MX update rate from the default 10 seconds
if (updateRate > 8000 && updateRate != 8000)
{
cumulus.LogMessage($"PrintSensorInfoNew: WS90 sensor detected, changing the update rate from {updateRate / 1000} seconds to 4 seconds");
updateRate = 4000;
cumulus.LogMessage($"PrintSensorInfoNew: WS90 sensor detected, changing the update rate from {updateRate / 1000} seconds to 8 seconds");
updateRate = 8000;
}
battV = data[battPos] * 0.02;
batt = $"{battV:f2}V ({(battV > 2.4 ? "OK" : "Low")})";
break;
break;

case string wh31 when wh31.StartsWith("WH31"): // ch 1-8
batt = $"{data[battPos]} ({TestBattery1(data[battPos], 1)})";
Expand Down Expand Up @@ -1297,36 +1307,42 @@ private void GetPiezoRainData()
// 1 - 0xff - header
// 2 - 0x57 - rain data
// 3-4 - size(2)
// 05 - 0E = rain rate
// 06-07 - data(2)
// 08 - 10 = rain day
// 09-12 - data(4)
// 13 - 11 = rain week
// 14-17 - data(4)
// 18 - 12 = rain month
// 19-22 - data(4)
// 23 - 13 = rain year
// 24-27 - data(4)
// 28 - 0D = rain event
// 29-30 - data(2)
// 31 - 0F = rain hour
// 32-33 - data(2)
// 34 - 80 = piezo rain rate
// 35-36 - data(2)
// 37 - 83 = piezo rain day
// 38-41 - data(4)
// 42 - 84 = piezo rain week
// 43-46 - data(4)
// 47 - 85 = piezo rain month
// 48-51 - data(4)
// 52 - 86 = piezo rain year
// 53-56 - data(4)
// 57 - 81 = piezo rain event
// 58-59 - data(2)
// 60 - 87 = piezo gain 0-9
// 61-80 - data(2x10)
// 81 - 88 = rain reset time (hr, day [sun-0], month [jan=0])
// 82-84 - data(3)
//
// Field Value
// - data size
//
// 0E = rain rate
// - data(2)
// 10 = rain day
// - data(4)
// 11 = rain week
// - data(4)
// 12 = rain month
// - data(4)
// 13 = rain year
// - data(4)
// 0D = rain event
// - data(2)
// 0F = rain hour
// - data(2)
// 80 = piezo rain rate
// - data(2)
// 83 = piezo rain day
// - data(4)
// 84 = piezo rain week
// - data(4)
// 85 = piezo rain month
// - data(4)
// 86 = piezo rain year
// - data(4)
// 81 = piezo rain event
// - data(2)
// 87 = piezo gain 0-9
// - data(2x10)
// 88 = rain reset time (hr, day [sun-0], month [jan=0])
// - data(3)
// 7A = primary rain selection (0=No sensor, 1=Tipper, 2=Piezo)
// - data(1)
// 85 - checksum

//data = new byte[] { 0xFF, 0xFF, 0x57, 0x00, 0x54, 0x0E, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x02, 0xF2, 0x13, 0x00, 0x00, 0x0B, 0x93, 0x0D, 0x00, 0x00, 0x0F, 0x00, 0x64, 0x80, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x01, 0xDE, 0x86, 0x00, 0x00, 0x0B, 0xF2, 0x81, 0x00, 0x00, 0x87, 0x00, 0x64, 0x00, 0x64, 0x00, 0x64, 0x00, 0x64, 0x00, 0x64, 0x00, 0x64, 0x00, 0x64, 0x00, 0x64, 0x00, 0x64, 0x00, 0x64, 0x88, 0x00, 0x00, 0x00, 0xF7 };
Expand Down Expand Up @@ -1389,8 +1405,18 @@ private void GetPiezoRainData()
idx += 3;
#endif
break;
case 0x7A: // Seems to indicate no rain data available?
cumulus.LogDebugMessage("No rain data available? 0x7a=" + data[idx++]);
case 0x7A: // Preferred rain sensor on station
var sensor = data[idx++];
#if DEBUG
if (sensor == 0)
cumulus.LogDebugMessage("No rain sensor available");
else if (sensor == 1)
cumulus.LogDebugMessage("Traditional rain sensor selected");
else if (sensor == 2)
cumulus.LogDebugMessage("Piezo rain sensor selected");
else
cumulus.LogDebugMessage("Unkown rain sensor selection value = " + sensor);
#endif
break;
default:
cumulus.LogDebugMessage($"GetPiezoRainData: Error: Unknown value type found = {data[idx - 1]}, at position = {idx - 1}");
Expand Down
6 changes: 3 additions & 3 deletions CumulusMX/HttpStationAmbient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ public string ProcessData(IHttpContext context, bool main)
// 24hourrainin
// weeklyrainin
// monthlyrainin
// yearlyrainin
// yearlyrainin - missing on some stations, they supply totalrainin
// eventrainin
// totalrainin ??? MISSING ???
// totalrainin - only some stations

var rain = data["yearlyrainin"];
var rain = data["yearlyrainin"] ?? data["totalrainin"];
//var rRate = data["hourlyrainin"]; // no rain rate, have to use the hourly rain

if (rain == null)
Expand Down
Loading

0 comments on commit 0d5d201

Please sign in to comment.