Skip to content

Commit

Permalink
Merge pull request #110 from mcrossley/master
Browse files Browse the repository at this point in the history
v3.11.0 - b3129 final
  • Loading branch information
mcrossley authored May 7, 2021
2 parents e24ae3d + c6d70eb commit 1baabb6
Show file tree
Hide file tree
Showing 27 changed files with 4,236 additions and 2,199 deletions.
166 changes: 161 additions & 5 deletions CumulusMX/AlarmSettings.cs

Large diffs are not rendered by default.

73 changes: 45 additions & 28 deletions CumulusMX/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static class Api
public static ProgramSettings programSettings;
internal static StationSettings stationSettings;
public static InternetSettings internetSettings;
public static ThirdPartySettings thirdpartySettings;
public static ExtraSensorSettings extraSensorSettings;
public static CalibrationSettings calibrationSettings;
public static NOAASettings noaaSettings;
Expand Down Expand Up @@ -449,6 +450,10 @@ public async Task<bool> GetDailyGraphData()
return await this.JsonResponseAsync(Station.GetAllDailyHumGraphData());
case "solardata.json":
return await this.JsonResponseAsync(Station.GetAllDailySolarGraphData());
case "degdaydata.json":
return await this.JsonResponseAsync(Station.GetAllDegreeDaysGraphData());
case "tempsumdata.json":
return await this.JsonResponseAsync(Station.GetAllTempSumGraphData());
case "units.json":
return await this.JsonResponseAsync(Station.GetUnits());
case "graphconfig.json":
Expand Down Expand Up @@ -821,60 +826,68 @@ public async Task<bool> SettingsGet()
switch (lastSegment)
{
case "programdata.json":
return await this.JsonResponseAsync(programSettings.GetProgramAlpacaFormData());
return await this.JsonResponseAsync(programSettings.GetAlpacaFormData());
case "programoptions.json":
return await this.JsonResponseAsync(programSettings.GetProgramAlpacaFormOptions());
return await this.JsonResponseAsync(programSettings.GetAlpacaFormOptions());
case "programschema.json":
return await this.JsonResponseAsync(programSettings.GetProgramAlpacaFormSchema());
return await this.JsonResponseAsync(programSettings.GetAlpacaFormSchema());

case "stationdata.json":
return await this.JsonResponseAsync(stationSettings.GetStationAlpacaFormData());
return await this.JsonResponseAsync(stationSettings.GetAlpacaFormData());
case "stationoptions.json":
return await this.JsonResponseAsync(stationSettings.GetStationAlpacaFormOptions());
return await this.JsonResponseAsync(stationSettings.GetAlpacaFormOptions());
case "stationschema.json":
return await this.JsonResponseAsync(stationSettings.GetStationAlpacaFormSchema());
return await this.JsonResponseAsync(stationSettings.GetAlpacaFormSchema());

case "internetdata.json":
return await this.JsonResponseAsync(internetSettings.GetInternetAlpacaFormData());
return await this.JsonResponseAsync(internetSettings.GetAlpacaFormData());
case "internetoptions.json":
return await this.JsonResponseAsync(internetSettings.GetInternetAlpacaFormOptions());
return await this.JsonResponseAsync(internetSettings.GetAlpacaFormOptions());
case "internetschema.json":
return await this.JsonResponseAsync(internetSettings.GetInternetAlpacaFormSchema());
return await this.JsonResponseAsync(internetSettings.GetAlpacaFormSchema());

case "thirdpartydata.json":
return await this.JsonResponseAsync(thirdpartySettings.GetAlpacaFormData());
case "thirdpartyoptions.json":
return await this.JsonResponseAsync(thirdpartySettings.GetAlpacaFormOptions());
case "thirdpartyschema.json":
return await this.JsonResponseAsync(thirdpartySettings.GetAlpacaFormSchema());

case "extrasensordata.json":
return await this.JsonResponseAsync(extraSensorSettings.GetExtraSensorAlpacaFormData());
return await this.JsonResponseAsync(extraSensorSettings.GetAlpacaFormData());
case "extrasensoroptions.json":
return await this.JsonResponseAsync(extraSensorSettings.GetExtraSensorAlpacaFormOptions());
return await this.JsonResponseAsync(extraSensorSettings.GetAlpacaFormOptions());
case "extrasensorschema.json":
return await this.JsonResponseAsync(extraSensorSettings.GetExtraSensorAlpacaFormSchema());
return await this.JsonResponseAsync(extraSensorSettings.GetAlpacaFormSchema());

case "extrawebfiles.json":
return await this.JsonResponseAsync(internetSettings.GetExtraWebFilesData());

case "calibrationdata.json":
return await this.JsonResponseAsync(calibrationSettings.GetCalibrationAlpacaFormData());
return await this.JsonResponseAsync(calibrationSettings.GetAlpacaFormData());
case "calibrationoptions.json":
return await this.JsonResponseAsync(calibrationSettings.GetCalibrationAlpacaFormOptions());
return await this.JsonResponseAsync(calibrationSettings.GetAlpacaFormOptions());
case "calibrationschema.json":
return await this.JsonResponseAsync(calibrationSettings.GetCalibrationAlpacaFormSchema());
return await this.JsonResponseAsync(calibrationSettings.GetAlpacaFormSchema());

case "noaadata.json":
return await this.JsonResponseAsync(noaaSettings.GetNoaaAlpacaFormData());
return await this.JsonResponseAsync(noaaSettings.GetAlpacaFormData());
case "noaaoptions.json":
return await this.JsonResponseAsync(noaaSettings.GetNoaaAlpacaFormOptions());
return await this.JsonResponseAsync(noaaSettings.GetAlpacaFormOptions());
case "noaaschema.json":
return await this.JsonResponseAsync(noaaSettings.GetNoaaAlpacaFormSchema());
return await this.JsonResponseAsync(noaaSettings.GetAlpacaFormSchema());

case "wsport.json":
return await this.JsonResponseAsync(stationSettings.GetWSport());
case "version.json":
return await this.JsonResponseAsync(stationSettings.GetVersion());

case "mysqldata.json":
return await this.JsonResponseAsync(mySqlSettings.GetMySqlAlpacaFormData());
return await this.JsonResponseAsync(mySqlSettings.GetAlpacaFormData());
case "mysqloptions.json":
return await this.JsonResponseAsync(mySqlSettings.GetMySqAlpacaFormOptions());
return await this.JsonResponseAsync(mySqlSettings.GetAlpacaFormOptions());
case "mysqlschema.json":
return await this.JsonResponseAsync(mySqlSettings.GetMySqAlpacaFormSchema());
return await this.JsonResponseAsync(mySqlSettings.GetAlpacaFormSchema());

case "alarms.json":
return await this.JsonResponseAsync(alarmSettings.GetAlarmSettings());
Expand All @@ -899,22 +912,24 @@ public async Task<bool> SettingsSet()
switch (lastSegment)
{
case "updateprogramconfig.json":
return await this.JsonResponseAsync(programSettings.UpdateProgramConfig(this));
return await this.JsonResponseAsync(programSettings.UpdateConfig(this));

case "updatestationconfig.json":
return await this.JsonResponseAsync(stationSettings.UpdateStationConfig(this));
return await this.JsonResponseAsync(stationSettings.UpdateConfig(this));
case "updateinternetconfig.json":
return await this.JsonResponseAsync(internetSettings.UpdateInternetConfig(this));
return await this.JsonResponseAsync(internetSettings.UpdateConfig(this));
case "updatethirdpartyconfig.json":
return await this.JsonResponseAsync(thirdpartySettings.UpdateConfig(this));
case "updateextrasensorconfig.json":
return await this.JsonResponseAsync(extraSensorSettings.UpdateExtraSensorConfig(this));
return await this.JsonResponseAsync(extraSensorSettings.UpdateConfig(this));
case "updatecalibrationconfig.json":
return await this.JsonResponseAsync(calibrationSettings.UpdateCalibrationConfig(this));
return await this.JsonResponseAsync(calibrationSettings.UpdateConfig(this));
case "updatenoaaconfig.json":
return await this.JsonResponseAsync(noaaSettings.UpdateNoaaConfig(this));
return await this.JsonResponseAsync(noaaSettings.UpdateConfig(this));
case "updateextrawebfiles.html":
return await this.JsonResponseAsync(internetSettings.UpdateExtraWebFiles(this));
case "updatemysqlconfig.json":
return await this.JsonResponseAsync(mySqlSettings.UpdateMysqlConfig(this));
return await this.JsonResponseAsync(mySqlSettings.UpdateConfig(this));
case "createmonthlysql.json":
return await this.JsonResponseAsync(mySqlSettings.CreateMonthlySQL(this));
case "createdayfilesql.json":
Expand All @@ -925,6 +940,8 @@ public async Task<bool> SettingsSet()
return await this.JsonResponseAsync(alarmSettings.UpdateAlarmSettings(this));
case "ftpnow.json":
return await this.JsonResponseAsync(stationSettings.FtpNow(this));
case "testemail.json":
return await this.JsonResponseAsync(alarmSettings.TestEmail(this));
}

throw new KeyNotFoundException("Key Not Found: " + lastSegment);
Expand Down
77 changes: 47 additions & 30 deletions CumulusMX/ApiTagProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Unosquare.Labs.EmbedIO;
Expand Down Expand Up @@ -32,38 +33,47 @@ public string ProcessJson(string query)
cumulus.LogDebugMessage("API tag: Processing API JSON tag request");
cumulus.LogDataMessage("API tag: Input string = " + query);

// remove leading "?" and split on "&"
var input = new List<string>(query.Substring(1).Split('&'));
var parms = new Dictionary<string, string>();
if (input[0] == "rc")
{
input.RemoveAt(0);
rc = true;
}
var output = new StringBuilder("{", query.Length * 2);

foreach(var tag in input)
try
{
if (rc)
// remove leading "?" and split on "&"
var input = new List<string>(query.Substring(1).Split('&'));
var parms = new Dictionary<string, string>();
if (input[0] == "rc")
{
input.RemoveAt(0);
rc = true;
}

foreach (var tag in input)
{
parms.Add("webtag", tag);
parms.Add("rc", "y");
if (rc)
{
parms.Add("webtag", tag);
parms.Add("rc", "y");
}
var val = webtags.GetWebTagText(tag, parms);
output.Append($"\"{tag}\":\"{val}\",");
if (rc)
{
parms.Clear();
}
}
var val = webtags.GetWebTagText(tag, parms);
output.Append($"\"{tag}\":\"{val}\",");
if (rc)
if (output.Length > 1)
{
parms.Clear();
// remove trailing ","
output.Remove(output.Length - 1, 1);
}
output.Append("}");

cumulus.LogDataMessage("API tag: Output string = " + output);
}
if (output.Length > 1)
catch (Exception ex)
{
// remove trailing ","
output.Remove(output.Length - 1, 1);
cumulus.LogMessage($"API tag: Error - {ex.Message}");
output.Append($"\"ERROR\":\"{ex.Message}\"}}");
}
output.Append("}");

cumulus.LogDataMessage("API tag: Output string = " + output);

return output.ToString();
}
Expand All @@ -73,17 +83,24 @@ public string ProcessText(IHttpContext context)
{
cumulus.LogDebugMessage("API tag: Processing API Text tag request");

var data = new StreamReader(context.Request.InputStream).ReadToEnd();
try
{
var data = new StreamReader(context.Request.InputStream).ReadToEnd();

cumulus.LogDataMessage("API tag: Input string = " + data);
cumulus.LogDataMessage("API tag: Input string = " + data);

tokenParser.InputText = data;
var output = tokenParser.ToStringFromString();
tokenParser.InputText = data;
var output = tokenParser.ToStringFromString();

cumulus.LogDataMessage("API tag: Output string = " + output);
cumulus.LogDataMessage("API tag: Output string = " + output);

return output;
return output;
}
catch (Exception ex)
{
cumulus.LogMessage($"API tag: Error - {ex.Message}");
return $"{{\"ERROR\":\"{ex.Message}\"}}";
}
}

}
}
8 changes: 6 additions & 2 deletions CumulusMX/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.1.1" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reactive.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
Expand Down Expand Up @@ -89,6 +89,10 @@
<assemblyIdentity name="Tmds.MDns" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.7.0.0" newVersion="0.7.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
44 changes: 30 additions & 14 deletions CumulusMX/CalibrationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,43 @@ namespace CumulusMX
public class CalibrationSettings
{
private readonly Cumulus cumulus;
private readonly string calibrationOptionsFile;
private readonly string calibrationSchemaFile;
private readonly string optionsFile;
private readonly string schemaFile;

public CalibrationSettings(Cumulus cumulus)
{
this.cumulus = cumulus;
calibrationOptionsFile = cumulus.AppDir + "interface"+Path.DirectorySeparatorChar+"json" + Path.DirectorySeparatorChar + "CalibrationOptions.json";
calibrationSchemaFile = cumulus.AppDir + "interface"+Path.DirectorySeparatorChar+"json" + Path.DirectorySeparatorChar + "CalibrationSchema.json";
optionsFile = cumulus.AppDir + "interface"+Path.DirectorySeparatorChar+"json" + Path.DirectorySeparatorChar + "CalibrationOptions.json";
schemaFile = cumulus.AppDir + "interface"+Path.DirectorySeparatorChar+"json" + Path.DirectorySeparatorChar + "CalibrationSchema.json";
}

//public string UpdateCalibrationConfig(HttpListenerContext context)
public string UpdateCalibrationConfig(IHttpContext context)
public string UpdateConfig(IHttpContext context)
{
var json = "";
JsonCalibrationSettingsData settings;
var invC = new CultureInfo("");

try
{
var invC = new CultureInfo("");
var data = new StreamReader(context.Request.InputStream).ReadToEnd();

var json = WebUtility.UrlDecode(data.Substring(5));
json = WebUtility.UrlDecode(data.Substring(5));

// de-serialize it to the settings structure
var settings = json.FromJson<JsonCalibrationSettingsData>();
settings = json.FromJson<JsonCalibrationSettingsData>();
}
catch (Exception ex)
{
var msg = "Error deserializing Calibration Settings JSON: " + ex.Message;
cumulus.LogMessage(msg);
cumulus.LogDebugMessage("Calibration Data: " + json);
context.Response.StatusCode = 500;
return msg;
}

try
{
// process the settings
cumulus.LogMessage("Updating calibration settings");

Expand Down Expand Up @@ -91,14 +106,15 @@ public string UpdateCalibrationConfig(IHttpContext context)
}
catch (Exception ex)
{
cumulus.LogMessage(ex.Message);
cumulus.LogMessage("Error setting Calibration settings: " + ex.Message);
cumulus.LogDebugMessage("Calibration Data: " + json);
context.Response.StatusCode = 500;
return ex.Message;
}
return "success";
}

public string GetCalibrationAlpacaFormData()
public string GetAlpacaFormData()
{
//var InvC = new CultureInfo("");
var offsets = new JsonCalibrationSettingsOffsets()
Expand Down Expand Up @@ -161,18 +177,18 @@ public string GetCalibrationAlpacaFormData()
return data.ToJson();
}

public string GetCalibrationAlpacaFormOptions()
public string GetAlpacaFormOptions()
{
using (StreamReader sr = new StreamReader(calibrationOptionsFile))
using (StreamReader sr = new StreamReader(optionsFile))
{
string json = sr.ReadToEnd();
return json;
}
}

public string GetCalibrationAlpacaFormSchema()
public string GetAlpacaFormSchema()
{
using (StreamReader sr = new StreamReader(calibrationSchemaFile))
using (StreamReader sr = new StreamReader(schemaFile))
{
string json = sr.ReadToEnd();
return json;
Expand Down
Loading

0 comments on commit 1baabb6

Please sign in to comment.