Skip to content

Commit

Permalink
Merge pull request #87 from mcrossley/master
Browse files Browse the repository at this point in the history
v3.8.4 merge
  • Loading branch information
mcrossley committed Sep 14, 2020
2 parents 5d25576 + 339a9f5 commit 6318bcb
Show file tree
Hide file tree
Showing 12 changed files with 444 additions and 158 deletions.
126 changes: 78 additions & 48 deletions CumulusMX/Cumulus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace CumulusMX
public class Cumulus
{
/////////////////////////////////
public string Version = "3.8.3";
public string Build = "3093";
public string Version = "3.8.4";
public string Build = "3094";
/////////////////////////////////

public static SemaphoreSlim syncInit = new SemaphoreSlim(1);
Expand Down Expand Up @@ -3583,7 +3583,7 @@ private void ReadIniFile()
WllExtraHumTx[i - 1] = ini.GetValue("WLL", "ExtraHumOnTxId" + i, false);
}

// GW1000 setiings
// GW1000 settings
Gw1000IpAddress = ini.GetValue("GW1000", "IPAddress", "0.0.0.0");
Gw1000AutoUpdateIpAddress = ini.GetValue("GW1000", "AutoUpdateIpAddress", true);

Expand Down Expand Up @@ -5543,8 +5543,8 @@ public void DoLogFile(DateTime timestamp, bool live) // Writes an entry to the n
// 28 Humidex
{
// make sure solar max is calculated for those stations without a solar sensor
LogMessage("Writing log entry for " + timestamp);
LogDebugMessage("max gust: " + station.RecentMaxGust.ToString(WindFormat));
LogMessage("DoLogFile: Writing log entry for " + timestamp);
LogDebugMessage("DoLogFile: max gust: " + station.RecentMaxGust.ToString(WindFormat));
station.CurrentSolarMax = AstroLib.SolarMax(timestamp, Longitude, Latitude, station.AltitudeM(Altitude), out station.SolarElevation, RStransfactor, BrasTurbidity, SolarCalc);
var filename = GetLogFileName(timestamp);

Expand Down Expand Up @@ -5584,7 +5584,7 @@ public void DoLogFile(DateTime timestamp, bool live) // Writes an entry to the n
}

LastUpdateTime = timestamp;
LogMessage("Written log entry for " + timestamp);
LogMessage("DoLogFile: Written log entry for " + timestamp);
station.WriteTodayFile(timestamp, true);

if (StartOfDayBackupNeeded)
Expand Down Expand Up @@ -5642,20 +5642,24 @@ public void DoLogFile(DateTime timestamp, bool live) // Writes an entry to the n
{
cmd.CommandText = queryString;
cmd.Connection = MonthlyMySqlConn;
LogDebugMessage(queryString);
LogDebugMessage("DoLogFile: MySQL - " + queryString);
MonthlyMySqlConn.Open();
int aff = cmd.ExecuteNonQuery();
LogMessage("MySQL: Table " + MySqlMonthlyTable + " " + aff + " rows were affected.");
}
}
catch (Exception ex)
{
LogMessage("Error encountered during Monthly MySQL operation.");
LogMessage("DoLogFile: Error encountered during Monthly MySQL operation.");
LogMessage(ex.Message);
}
finally
{
MonthlyMySqlConn.Close();
try
{
MonthlyMySqlConn.Close();
}
catch { }
}
}
else
Expand Down Expand Up @@ -7254,12 +7258,12 @@ 59 8.4 Feels Like temperature
// do the update
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.CommandText = queryString;
cmd.Connection = RealtimeSqlConn;
LogDebugMessage($"Realtime[{cycle}]: Running SQL command: {queryString}");

try
{
cmd.CommandText = queryString;
cmd.Connection = RealtimeSqlConn;
LogDebugMessage($"Realtime[{cycle}]: Running SQL command: {queryString}");

RealtimeSqlConn.Open();
int aff1 = cmd.ExecuteNonQuery();
LogDebugMessage($"Realtime[{cycle}]: {aff1} rows were affected.");
Expand Down Expand Up @@ -7295,10 +7299,7 @@ 59 8.4 Feels Like temperature
{
RealtimeSqlConn.Close();
}
catch
{
// do nothing
}
catch {}
}
}
}
Expand Down Expand Up @@ -7519,7 +7520,11 @@ private void CustomMysqlSecondsTimerTick(object sender, ElapsedEventArgs e)
}
finally
{
CustomMysqlSecondsConn.Close();
try
{
CustomMysqlSecondsConn.Close();
}
catch {}
customMySqlSecondsUpdateInProgress = false;
}
}
Expand Down Expand Up @@ -7547,7 +7552,11 @@ internal void CustomMysqlMinutesTimerTick()
}
finally
{
CustomMysqlMinutesConn.Close();
try
{
CustomMysqlMinutesConn.Close();
}
catch {}
customMySqlMinutesUpdateInProgress = false;
}
}
Expand Down Expand Up @@ -7576,7 +7585,11 @@ internal void CustomMysqlRolloverTimerTick()
}
finally
{
CustomMysqlRolloverConn.Close();
try
{
CustomMysqlRolloverConn.Close();
}
catch {}
customMySqlRolloverUpdateInProgress = false;
}
});
Expand Down Expand Up @@ -7681,32 +7694,46 @@ private void MySqlCatchup()
mySqlConn.Password = MySqlPass;
mySqlConn.Database = MySqlDatabase;

mySqlConn.Open();

for (int i = 0; i < MySqlList.Count; i++)
try
{
LogMessage("MySQL Archive: Uploading archive #" + (i + 1));
try
mySqlConn.Open();

for (int i = 0; i < MySqlList.Count; i++)
{
using (MySqlCommand cmd = new MySqlCommand())
LogMessage("MySQL Archive: Uploading archive #" + (i + 1));
try
{
cmd.CommandText = MySqlList[i];
cmd.Connection = mySqlConn;
LogDebugMessage(MySqlList[i]);
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.CommandText = MySqlList[i];
cmd.Connection = mySqlConn;
LogDebugMessage(MySqlList[i]);

int aff = cmd.ExecuteNonQuery();
LogMessage($"MySQL Archive: Table {MySqlMonthlyTable} - {aff} rows were affected.");
int aff = cmd.ExecuteNonQuery();
LogMessage($"MySQL Archive: Table {MySqlMonthlyTable} - {aff} rows were affected.");
}
}
catch (Exception ex)
{
LogMessage("MySQL Archive: Error encountered during catchup MySQL operation.");
LogMessage(ex.Message);
}
}
catch (Exception ex)
}
catch (Exception ex)
{
LogMessage("MySQL Archive: Error encountered during catchup MySQL operation.");
LogMessage(ex.Message);
}
finally
{
try
{
LogMessage("MySQL Archive: Error encountered during catchup MySQL operation.");
LogMessage(ex.Message);
mySqlConn.Close();
}
catch {}
}

mySqlConn.Close();

LogMessage("MySQL Archive: End of MySQL archive upload");
MySqlList.Clear();
}
Expand Down Expand Up @@ -8014,13 +8041,16 @@ public async void CustomHttpSecondsUpdate()
{
customHttpSecondsTokenParser.InputText = CustomHttpSecondsString;
var processedString = customHttpSecondsTokenParser.ToStringFromString();
await customHttpSecondsClient.GetAsync(processedString);
//var responseBodyAsText = await response.Content.ReadAsStringAsync();
//LogDebugMessage("Custom HTTP seconds response: " + response.StatusCode + ": " + responseBodyAsText);
LogDebugMessage("CustomHttpSeconds: Querying - " + processedString);
var response = await customHttpSecondsClient.GetAsync(processedString);
response.EnsureSuccessStatusCode();
var responseBodyAsText = await response.Content.ReadAsStringAsync();
LogDebugMessage("CustomHttpSeconds: Response - " + response.StatusCode);
LogDataMessage("CustomHttpSeconds: Response Text - " + responseBodyAsText);
}
catch (Exception ex)
{
LogDebugMessage("Custom HTTP seconds update: " + ex.Message);
LogDebugMessage("CustomHttpSeconds: " + ex.Message);
}
finally
{
Expand All @@ -8035,19 +8065,19 @@ public async void CustomHttpMinutesUpdate()
{
updatingCustomHttpMinutes = true;

LogDebugMessage("Custom HTTP Minutes update");

try
{
customHttpMinutesTokenParser.InputText = CustomHttpMinutesString;
var processedString = customHttpMinutesTokenParser.ToStringFromString();
LogDebugMessage("CustomHttpMinutes: Querying - " + processedString);
var response = await customHttpMinutesClient.GetAsync(processedString);
var responseBodyAsText = await response.Content.ReadAsStringAsync();
LogDebugMessage("Custom HTTP Minutes response: " + response.StatusCode + ": " + responseBodyAsText);
LogDebugMessage("CustomHttpMinutes: Response code - " + response.StatusCode);
LogDataMessage("CustomHttpMinutes: Response text - " + responseBodyAsText);
}
catch (Exception ex)
{
LogDebugMessage("Custom HTTP Minutes update: " + ex.Message);
LogDebugMessage("CustomHttpMinutes: " + ex.Message);
}
finally
{
Expand All @@ -8062,19 +8092,19 @@ public async void CustomHttpRolloverUpdate()
{
updatingCustomHttpRollover = true;

LogDebugMessage("Custom HTTP Rollover update");

try
{
customHttpRolloverTokenParser.InputText = CustomHttpRolloverString;
var processedString = customHttpRolloverTokenParser.ToStringFromString();
LogDebugMessage("CustomHttpRollover: Querying - " + processedString);
var response = await customHttpRolloverClient.GetAsync(processedString);
var responseBodyAsText = await response.Content.ReadAsStringAsync();
LogDebugMessage("Custom HTTP Rollover response: " + response.StatusCode + ": " + responseBodyAsText);
LogDebugMessage("CustomHttpRollover: Response code - " + response.StatusCode);
LogDataMessage("CustomHttpRollover: Response text - " + responseBodyAsText);
}
catch (Exception ex)
{
LogDebugMessage("Custom HTTP Rollover update: " + ex.Message);
LogDebugMessage("CustomHttpRollover: " + ex.Message);
}
finally
{
Expand Down
33 changes: 28 additions & 5 deletions CumulusMX/CumulusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,40 @@ protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
{
switch (powerStatus)
{
case PowerBroadcastStatus.BatteryLow:
Program.cumulus.LogMessage("POWER: Detected system BATTERY LOW");
break;
case PowerBroadcastStatus.OemEvent:
Program.cumulus.LogMessage("POWER: Detected system OEM EVENT");
break;
case PowerBroadcastStatus.PowerStatusChange:
Program.cumulus.LogMessage("POWER: Detected system POWER STATUS CHANGE");
break;
case PowerBroadcastStatus.QuerySuspend:
Program.cumulus.LogMessage("POWER: Detected system QUERY SUSPEND");
break;
case PowerBroadcastStatus.QuerySuspendFailed:
Program.cumulus.LogMessage("POWER: Detected system QUERY SUSPEND FAILED");
break;
case PowerBroadcastStatus.ResumeAutomatic:
Program.cumulus.LogMessage("POWER: Detected system RESUME AUTOMATIC");
break;
case PowerBroadcastStatus.ResumeCritical:
Program.cumulus.LogMessage("POWER: Detected system RESUME CRITICAL, stopping service");
Program.cumulus.LogConsoleMessage("Detected system RESUME CRITICAL, stopping service");
// A critical suspend will not have shutdown Cumulus, so do it now
Stop();
break;
case PowerBroadcastStatus.ResumeSuspend:
Program.cumulus.LogMessage("Detected system RESUMING FROM STANDBY");
Program.cumulus.LogConsoleMessage("Detected system RESUMING FROM STANDBY");
Program.cumulus.LogMessage("POWER: Detected system RESUMING FROM STANDBY");
break;
case PowerBroadcastStatus.Suspend:
Program.cumulus.LogMessage("Detected system GOING TO STANDBY");
Program.cumulus.LogConsoleMessage("Detected system GOING TO STANDBY");
Program.cumulus.LogMessage("POWER: Detected system GOING TO STANDBY, stopping service");
Program.cumulus.LogConsoleMessage("Detected system GOING TO STANDBY, stopping service");
Stop();
break;
}

Stop();
return true;
}
}
Expand Down
Loading

0 comments on commit 6318bcb

Please sign in to comment.