Skip to content

Commit

Permalink
Merge pull request #99 from mcrossley/master
Browse files Browse the repository at this point in the history
build 3101 changes
  • Loading branch information
mcrossley authored Jan 20, 2021
2 parents 27708cf + 0bdde08 commit b659d55
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 218 deletions.
240 changes: 124 additions & 116 deletions CumulusMX/Cumulus.cs

Large diffs are not rendered by default.

242 changes: 192 additions & 50 deletions CumulusMX/DavisAirLink.cs

Large diffs are not rendered by default.

59 changes: 34 additions & 25 deletions CumulusMX/DavisWllStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public DavisWllStation(Cumulus cumulus) : base(cumulus)

// Perform Station ID checks - If we have API deatils!
// If the Station ID is missing, this will populate it if the user only has one station associated with the API key
if (useWeatherLinkDotCom && (string.IsNullOrEmpty(cumulus.WllStationId) || int.Parse(cumulus.WllStationId) < 10))
if (useWeatherLinkDotCom && cumulus.WllStationId < 10)
{
var msg = "No WeatherLink API station ID in the cumulus.ini file";
cumulus.LogMessage(msg);
Expand All @@ -129,7 +129,7 @@ public DavisWllStation(Cumulus cumulus) : base(cumulus)
}

// Sanity check the station id
if (useWeatherLinkDotCom && (string.IsNullOrEmpty(cumulus.WllStationId) || int.Parse(cumulus.WllStationId) < 10))
if (useWeatherLinkDotCom && cumulus.WllStationId < 10)
{
// API details supplied, but Station Id is still invalid - do not start the station up.
cumulus.LogMessage("WLL - The WeatherLink.com API is enabled, but no Station Id has been configured, not starting the station. Please correct this and restart Cumulus");
Expand Down Expand Up @@ -1343,7 +1343,7 @@ private void GetWlHistoricData()
return;
}

if (cumulus.WllStationId == string.Empty || int.Parse(cumulus.WllStationId) < 10)
if (cumulus.WllStationId < 10)
{
const string msg = "No WeatherLink API station ID in the configuration";
cumulus.LogMessage(msg);
Expand Down Expand Up @@ -1373,7 +1373,7 @@ private void GetWlHistoricData()
SortedDictionary<string, string> parameters = new SortedDictionary<string, string>
{
{ "api-key", cumulus.WllApiKey },
{ "station-id", cumulus.WllStationId },
{ "station-id", cumulus.WllStationId.ToString() },
{ "t", unixDateTime.ToString() },
{ "start-timestamp", startTime.ToString() },
{ "end-timestamp", endTime.ToString() }
Expand Down Expand Up @@ -2456,7 +2456,7 @@ private void GetWlHistoricHealth()
return;
}

if (cumulus.WllStationId == string.Empty || int.Parse(cumulus.WllStationId) < 10)
if (cumulus.WllStationId < 10)
{
const string msg = "No WeatherLink API station ID in the cumulus.ini file";
cumulus.LogConsoleMessage("GetWlHistoricHealth: " + msg);
Expand All @@ -2473,7 +2473,7 @@ private void GetWlHistoricHealth()
SortedDictionary<string, string> parameters = new SortedDictionary<string, string>
{
{ "api-key", cumulus.WllApiKey },
{ "station-id", cumulus.WllStationId },
{ "station-id", cumulus.WllStationId.ToString() },
{ "t", unixDateTime.ToString() },
{ "start-timestamp", startTime.ToString() },
{ "end-timestamp", endTime.ToString() }
Expand Down Expand Up @@ -2683,7 +2683,7 @@ private void GetAvailableStationIds(bool logToConsole = false)
{
cumulus.LogConsoleMessage($" - Found WeatherLink station id = {station.station_id}, name = {station.station_name}, active = {station.active}");
}
if (station.station_id == int.Parse(cumulus.WllStationId))
if (station.station_id == cumulus.WllStationId)
{
cumulus.LogDebugMessage($"WLLStations: Setting WLL parent ID = {station.gateway_id}");
cumulus.WllParentId = station.gateway_id;
Expand All @@ -2694,15 +2694,15 @@ private void GetAvailableStationIds(bool logToConsole = false)
}
}
}
if (stationsObj.stations.Count > 1 && int.Parse(cumulus.WllStationId) < 10)
if (stationsObj.stations.Count > 1 && cumulus.WllStationId < 10)
{
if (logToConsole)
cumulus.LogConsoleMessage(" - Enter the required station id from the above list into your WLL configuration to enable history downloads.");
}
else if (stationsObj.stations.Count == 1 && int.Parse(cumulus.WllStationId) != stationsObj.stations[0].station_id)
else if (stationsObj.stations.Count == 1 && cumulus.WllStationId != stationsObj.stations[0].station_id)
{
cumulus.LogMessage($"WLLStations: Only found 1 WeatherLink station, using id = {stationsObj.stations[0].station_id}");
cumulus.WllStationId = stationsObj.stations[0].station_id.ToString();
cumulus.WllStationId = stationsObj.stations[0].station_id;
// And save it to the config file
cumulus.WriteIniFile();

Expand All @@ -2728,7 +2728,7 @@ private void GetAvailableSensors()
return;
}

if (cumulus.WllStationId == string.Empty || int.Parse(cumulus.WllStationId) < 10)
if (cumulus.WllStationId < 10)
{
cumulus.LogMessage("GetAvailableSensors: No WeatherLink API station ID has been configured, aborting!");
return;
Expand Down Expand Up @@ -2766,6 +2766,8 @@ private void GetAvailableSensors()
var logUrl = stationsUrl.ToString().Replace(cumulus.WllApiKey, "<<API_KEY>>");
cumulus.LogDebugMessage($"GetAvailableSensors: URL = {logUrl}");

WlSensorList sensorsObj = new WlSensorList();

try
{
// We want to do this synchronously
Expand All @@ -2786,38 +2788,45 @@ private void GetAvailableSensors()
return;
}

var sensorsObj = responseBody.FromJson<WlSensorList>();
sensorsObj = responseBody.FromJson<WlSensorList>();
}
catch (Exception ex)
{
cumulus.LogDebugMessage("GetAvailableSensors: WeatherLink API exception: " + ex.Message);
}

// Sensor types we are interested in...
// 323 = Outdoor AirLink
// 326 = Indoor AirLink
// 504 = WLL Health
// 506 = AirLink Health
var types = new[] { 45, 323, 326, 504, 506 };
foreach (var sensor in sensorsObj.sensors)
// Sensor types we are interested in...
// 323 = Outdoor AirLink
// 326 = Indoor AirLink
// 504 = WLL Health
// 506 = AirLink Health
var types = new[] { 45, 323, 326, 504, 506 };
foreach (var sensor in sensorsObj.sensors)
{
try
{
cumulus.LogDebugMessage($"GetAvailableSensors: Found WeatherLink Sensor type={sensor.sensor_type}, lsid={sensor.lsid}, station_id={sensor.station_id}, name={sensor.product_name}, parentId={sensor.parent_device_id}, parent={sensor.parent_device_name}");

if (types.Contains(sensor.sensor_type) || sensor.category == "ISS")
{
var wlSensor = new WlSensor(sensor.sensor_type, sensor.lsid, sensor.parent_device_id, sensor.product_name, sensor.parent_device_name);
sensorList.Add(wlSensor);
if (wlSensor.SensorType == 323 && sensor.station_id == int.Parse(cumulus.AirLinkOutStationId))
if (wlSensor.SensorType == 323 && sensor.station_id == cumulus.AirLinkOutStationId)
{
cumulus.LogDebugMessage($"GetAvailableSensors: Setting AirLink Outdoor LSID to {wlSensor.LSID}");
cumulus.airLinkOutLsid = wlSensor.LSID;
}
else if (wlSensor.SensorType == 326 && sensor.station_id == int.Parse(cumulus.AirLinkInStationId))
else if (wlSensor.SensorType == 326 && sensor.station_id == cumulus.AirLinkInStationId)
{
cumulus.LogDebugMessage($"GetAvailableSensors: Setting AirLink Indoor LSID to {wlSensor.LSID}");
cumulus.airLinkInLsid = wlSensor.LSID;
}
}
}
}
catch (Exception ex)
{
cumulus.LogDebugMessage("GetAvailableSensors: WeatherLink API exception: " + ex.Message);
catch (Exception ex)
{
cumulus.LogDebugMessage("GetAvailableSensors: Processing sensors exception: " + ex.Message);
}
}
}

Expand Down
11 changes: 8 additions & 3 deletions CumulusMX/ExtraSensorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public string GetExtraSensorAlpacaFormData()
{
enabled = cumulus.AirLinkInEnabled,
ipAddress = cumulus.AirLinkInIPAddr,
hostname = cumulus.AirLinkInHostName,
isNode = cumulus.AirLinkInIsNode,
stationId = cumulus.AirLinkInStationId
};
Expand All @@ -33,6 +34,7 @@ public string GetExtraSensorAlpacaFormData()
{
enabled = cumulus.AirLinkOutEnabled,
ipAddress = cumulus.AirLinkOutIPAddr,
hostname = cumulus.AirLinkOutHostName,
isNode = cumulus.AirLinkOutIsNode,
stationId = cumulus.AirLinkOutStationId
};
Expand Down Expand Up @@ -126,17 +128,19 @@ public string UpdateExtraSensorConfig(IHttpContext context)
cumulus.AirLinkInEnabled = settings.airLink.indoor.enabled;
cumulus.AirLinkInIsNode = settings.airLink.indoor.isNode;
cumulus.AirLinkInIPAddr = settings.airLink.indoor.ipAddress;
cumulus.AirLinkInHostName = settings.airLink.indoor.hostname;
cumulus.AirLinkInStationId = settings.airLink.indoor.stationId;
if (string.IsNullOrEmpty(cumulus.AirLinkInStationId) && cumulus.AirLinkInIsNode)
if (cumulus.AirLinkInStationId < 10 && cumulus.AirLinkInIsNode)
{
cumulus.AirLinkInStationId = cumulus.WllStationId;
}

cumulus.AirLinkOutEnabled = settings.airLink.outdoor.enabled;
cumulus.AirLinkOutIsNode = settings.airLink.outdoor.isNode;
cumulus.AirLinkOutIPAddr = settings.airLink.outdoor.ipAddress;
cumulus.AirLinkOutHostName = settings.airLink.outdoor.hostname;
cumulus.AirLinkOutStationId = settings.airLink.outdoor.stationId;
if (string.IsNullOrEmpty(cumulus.AirLinkOutStationId) && cumulus.AirLinkOutIsNode)
if (cumulus.AirLinkOutStationId < 10 && cumulus.AirLinkOutIsNode)
{
cumulus.AirLinkOutStationId = cumulus.WllStationId;
}
Expand Down Expand Up @@ -242,8 +246,9 @@ public class JsonExtraSensorAirLinkDevice
{
public bool enabled { get; set; }
public string ipAddress { get; set; }
public string hostname { get; set; }
public bool isNode { get; set; }
public string stationId { get; set; }
public int stationId { get; set; }
}

public class JsonExtraSensorBlakeLarsen
Expand Down
4 changes: 2 additions & 2 deletions CumulusMX/GW1000Station.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,15 @@ private bool DoDiscovery()
cumulus.WriteIniFile();
}
}
else
else
{
// Multiple devices discovered, and we do not have a clue!

string iplist = "";
msg = "Discovered more than one potential GW1000 device.";
cumulus.LogMessage(msg);
cumulus.LogConsoleMessage(msg);
msg = "Please select the IP adress from the list and enter it manually into the configuration";
msg = "Please select the IP address from the list and enter it manually into the configuration";
cumulus.LogMessage(msg);
cumulus.LogConsoleMessage(msg);
for (var i = 0; i < discoveredDevices.IP.Count; i++)
Expand Down
4 changes: 2 additions & 2 deletions CumulusMX/NOAA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public List<string> CreateMonthlyReport(DateTime thedate)
timestr = dayList[i].maxtemptimestamp.ToString("HH:mm");
}
repLine.Append(string.Format("{0,8}", timestr));
repLine.Append(string.Format("{0,6:F1}",dayList[i].mintemp));
repLine.Append(string.Format(culture, "{0,6:F1}", dayList[i].mintemp));
if (cumulus.NOAA12hourformat)
{
timestr = dayList[i].mintemptimestamp.ToString("h:mmtt");
Expand All @@ -624,7 +624,7 @@ public List<string> CreateMonthlyReport(DateTime thedate)
repLine.Append(string.Format(culture, "{0,6:F1}", dayList[i].heatingdegdays));
repLine.Append(string.Format(culture, "{0,6:F1}", dayList[i].coolingdegdays));
}
repLine.Append(string.Format(culture, "{0,6}", dayList[i].rain.ToString(cumulus.RainFormat)));
repLine.Append(string.Format("{0,6}", dayList[i].rain.ToString(cumulus.RainFormat, culture)));

if (dayList[i].avgwindspeed < -999)
repLine.Append(" ----");
Expand Down
34 changes: 22 additions & 12 deletions CumulusMX/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ private static void Main(string[] args)
//var ci = new CultureInfo("en-GB");
//System.Threading.Thread.CurrentThread.CurrentCulture = ci;

if (windows)
{
// set the working path to the exe location
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
}


var logfile = "MXdiags" + Path.DirectorySeparatorChar + "ServiceConsoleLog.txt";
if (File.Exists(logfile))
File.Delete(logfile);
Expand Down Expand Up @@ -57,7 +64,10 @@ private static void Main(string[] args)
// Wait for a signal to be delivered
unixSignalWaitAny?.Invoke(null, new object[] {signals});

cumulus.LogConsoleMessage("\nExiting system due to external SIGTERM signal");
if (cumulus != null)
{
cumulus.LogConsoleMessage("\nExiting system due to external SIGTERM signal");
}

exitSystem = true;
}
Expand All @@ -68,20 +78,18 @@ private static void Main(string[] args)
// Now we need to catch the console Ctrl-C
Console.CancelKeyPress += (s, ev) =>
{
cumulus.LogConsoleMessage("Ctrl+C pressed");
cumulus.LogConsoleMessage("\nCumulus terminating");
cumulus.Stop();
if (cumulus != null)
{
cumulus.LogConsoleMessage("Ctrl+C pressed");
cumulus.LogConsoleMessage("\nCumulus terminating");
cumulus.Stop();
}
Trace.WriteLine("Cumulus has shutdown");
ev.Cancel = true;
exitSystem = true;
};

}
else
{
// set the working path to the exe location
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
}

AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;

Expand Down Expand Up @@ -299,12 +307,14 @@ public ExitHandler()
private static bool Handler(CtrlType sig)
{
var reason = new[] { "Ctrl-C", "Ctrl-Break", "Close Main Window", "unknown", "unknown", "User Logoff", "System Shutdown" };
//Console.WriteLine("Cumulus terminating");
Program.cumulus.LogConsoleMessage("Cumulus terminating");

Trace.WriteLine("Exiting system due to external: " + reason[(int)sig]);

Program.cumulus.Stop();
if (Program.cumulus != null)
{
Program.cumulus.LogConsoleMessage("Cumulus terminating");
Program.cumulus.Stop();
}

Trace.WriteLine("Cumulus has shutdown");
Console.WriteLine("Cumulus stopped");
Expand Down
6 changes: 3 additions & 3 deletions CumulusMX/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CumulusMX")]
[assembly: AssemblyDescription("Build 3100")]
[assembly: AssemblyDescription("Build 3101")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CumulusMX")]
Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.9.5.3100")]
[assembly: AssemblyFileVersion("3.9.5.3100")]
[assembly: AssemblyVersion("3.9.6.3101")]
[assembly: AssemblyFileVersion("3.9.6.3101")]
4 changes: 2 additions & 2 deletions CumulusMX/StationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ internal string UpdateStationConfig(IHttpContext context)
cumulus.WLLAutoUpdateIpAddress = settings.daviswll.network.autoDiscover;
cumulus.WllApiKey = settings.daviswll.api.apiKey;
cumulus.WllApiSecret = settings.daviswll.api.apiSecret;
cumulus.WllStationId = settings.daviswll.api.apiStationId == "-1" ? "" : settings.daviswll.api.apiStationId;
cumulus.WllStationId = settings.daviswll.api.apiStationId;

cumulus.WllPrimaryRain = settings.daviswll.primary.rain;
cumulus.WllPrimarySolar = settings.daviswll.primary.solar;
Expand Down Expand Up @@ -848,7 +848,7 @@ internal class JsonStationSettingsWLLApi
{
public string apiKey { get; set; }
public string apiSecret { get; set; }
public string apiStationId { get; set; }
public int apiStationId { get; set; }
}

internal class JsonStationSettingsWllPrimary
Expand Down
6 changes: 3 additions & 3 deletions CumulusMX/WeatherStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9826,9 +9826,9 @@ public string GetAirLinkCountsIn()
var json = new StringBuilder("{\"data\":[", 256);
if (cumulus.airLinkIn != null)
{
json.Append($"[\"1 μm\",\"{cumulus.airLinkDataIn.pm1}\",\"--\",\"--\",\"--\",\"--\"],");
json.Append($"[\"2.5 μm\",\"{cumulus.airLinkDataIn.pm2p5}\",\"{cumulus.airLinkDataIn.pm2p5_1hr}\",\"{cumulus.airLinkDataIn.pm2p5_3hr}\",\"{cumulus.airLinkDataIn.pm2p5_24hr}\",\"{cumulus.airLinkDataIn.pm2p5_nowcast}\"],");
json.Append($"[\"10 μm\",\"{cumulus.airLinkDataIn.pm10}\",\"{cumulus.airLinkDataIn.pm10_1hr}\",\"{cumulus.airLinkDataIn.pm10_3hr}\",\"{cumulus.airLinkDataIn.pm10_24hr}\",\"{cumulus.airLinkDataIn.pm10_nowcast}\"]");
json.Append($"[\"1 μm\",\"{cumulus.airLinkDataIn.pm1:F1}\",\"--\",\"--\",\"--\",\"--\"],");
json.Append($"[\"2.5 μm\",\"{cumulus.airLinkDataIn.pm2p5:F1}\",\"{cumulus.airLinkDataIn.pm2p5_1hr:F1}\",\"{cumulus.airLinkDataIn.pm2p5_3hr:F1}\",\"{cumulus.airLinkDataIn.pm2p5_24hr:F1}\",\"{cumulus.airLinkDataIn.pm2p5_nowcast:F1}\"],");
json.Append($"[\"10 μm\",\"{cumulus.airLinkDataIn.pm10:F1}\",\"{cumulus.airLinkDataIn.pm10_1hr:F1}\",\"{cumulus.airLinkDataIn.pm10_3hr:F1}\",\"{cumulus.airLinkDataIn.pm10_24hr:F1}\",\"{cumulus.airLinkDataIn.pm10_nowcast:F1}\"]");
}
else
{
Expand Down
14 changes: 14 additions & 0 deletions Updates.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
3.9.6 - b3101
—————————————
- Fix: NOAA monthly report min temp/rain not formatting in dot decimal correctly
- Fix: Windows console log no longer being created
- Fix: Fix for exit handlers being called before cumulus instance is initialised causing an unhandled exception
- Fix: Airlink auto-discovery/update when you have more than one Airlink device
- Fix: Upgrade & Spike alarm latch hours not being saved/read correctly. You will need to check the values after installing this release.
- Fix: Rework both the interface graphs and default web site graphs JavaScript files
- Fix: SampleStrings.ini changes/fixes. The following entries should not longer be quoted - Davis Forecast strings and CO₂ captions

- Change: Recent graph hours now defaults for new installs to 72 hours instead of 24
- Change: All alarm latch hours now default to 24 hours


3.9.5 - b3100
—————————————
- Fix: Alarms being cleared after their defined latch time even if latching was disabled
Expand Down

0 comments on commit b659d55

Please sign in to comment.