Skip to content

Commit

Permalink
Merge pull request #103 from mcrossley/master
Browse files Browse the repository at this point in the history
v3.10.2 build
  • Loading branch information
mcrossley authored Mar 2, 2021
2 parents a89549f + f317daa commit 3090ac2
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 337 deletions.
146 changes: 77 additions & 69 deletions CumulusMX/Cumulus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2085,79 +2085,92 @@ internal async void UpdateAwekas(DateTime timestamp)

try
{
HttpResponseMessage response = await AwekashttpClient.GetAsync(url);
var responseBodyAsText = await response.Content.ReadAsStringAsync();
LogDebugMessage("AWEKAS Response code = " + response.StatusCode);
LogDataMessage("AWEKAS: Response text = " + responseBodyAsText);
//var respJson = JsonConvert.DeserializeObject<AwekasResponse>(responseBodyAsText);
var respJson = JsonSerializer.DeserializeFromString<AwekasResponse>(responseBodyAsText);

// Check the status response
if (respJson.status == 2)
LogMessage("AWEKAS: Data stored OK");
else if (respJson.status == 1)
{
LogMessage("AWEKAS: Data PARIALLY stored");
// TODO: Check errors and disabled
}
else if (respJson.status == 0) // Authenication error or rate limited
using (HttpResponseMessage response = await AwekashttpClient.GetAsync(url))
{
if (respJson.minuploadtime > 0 && respJson.authentication == 0)
var responseBodyAsText = await response.Content.ReadAsStringAsync();
LogDebugMessage("AWEKAS Response code = " + response.StatusCode);
LogDataMessage("AWEKAS: Response text = " + responseBodyAsText);
//var respJson = JsonConvert.DeserializeObject<AwekasResponse>(responseBodyAsText);
var respJson = JsonSerializer.DeserializeFromString<AwekasResponse>(responseBodyAsText);

// Check the status response
if (respJson.status == 2)
LogMessage("AWEKAS: Data stored OK");
else if (respJson.status == 1)
{
LogMessage("AWEKAS: Authentication error");
if (AWEKAS.Interval < 60)
{
AWEKAS.RateLimited = true;
AWEKAS.OriginalInterval = AWEKAS.Interval;
AWEKAS.Interval = 60;
AwekasTimer.Enabled = false;
AWEKAS.SynchronisedUpdate = true;
LogMessage("AWEKAS: Temporarily increasing AWEKAS upload interval to 60 seconds due to authenication error");
}
LogMessage("AWEKAS: Data PARIALLY stored");
// TODO: Check errors and disabled
}
else if (respJson.minuploadtime == 0)
else if (respJson.status == 0) // Authenication error or rate limited
{
LogMessage("AWEKAS: Too many requests, rate limited");
if (AWEKAS.Interval < 60)
if (respJson.minuploadtime > 0 && respJson.authentication == 0)
{
LogMessage("AWEKAS: Authentication error");
if (AWEKAS.Interval < 300)
{
AWEKAS.RateLimited = true;
AWEKAS.OriginalInterval = AWEKAS.Interval;
AWEKAS.Interval = 300;
AwekasTimer.Enabled = false;
AWEKAS.SynchronisedUpdate = true;
LogMessage("AWEKAS: Temporarily increasing AWEKAS upload interval to 300 seconds due to authenication error");
}
}
else if (respJson.minuploadtime == 0)
{
AWEKAS.RateLimited = true;
AWEKAS.OriginalInterval = AWEKAS.Interval;
AWEKAS.Interval = 60;
AwekasTimer.Enabled = false;
AWEKAS.SynchronisedUpdate = true;
LogMessage("AWEKAS: Temporarily increasing AWEKAS upload interval to 60 seconds due to rate limit");
LogMessage("AWEKAS: Too many requests, rate limited");
// AWEKAS PLus allows minimum of 60 second updates, try that first
if (!AWEKAS.RateLimited && AWEKAS.Interval < 60)
{
AWEKAS.OriginalInterval = AWEKAS.Interval;
AWEKAS.RateLimited = true;
AWEKAS.Interval = 60;
AwekasTimer.Enabled = false;
AWEKAS.SynchronisedUpdate = true;
LogMessage("AWEKAS: Temporarily increasing AWEKAS upload interval to 60 seconds due to rate limit");
}
// AWEKAS normal allows minimum of 300 second updates, revert to that
else
{
AWEKAS.RateLimited = true;
AWEKAS.Interval = 300;
AwekasTimer.Interval = AWEKAS.Interval * 1000;
AwekasTimer.Enabled = !AWEKAS.SynchronisedUpdate;
AWEKAS.SynchronisedUpdate = AWEKAS.Interval % 60 == 0;
LogMessage("AWEKAS: Temporarily increasing AWEKAS upload interval to 300 seconds due to rate limit");
}
}
else
{
LogMessage("AWEKAS: Unknown error");
}
}
else

// check the min upload time is greater than our upload time
if (respJson.status > 0 && respJson.minuploadtime > AWEKAS.OriginalInterval)
{
LogMessage("AWEKAS: Unknown error");
LogMessage($"AWEKAS: The minimum upload time to AWEKAS for your station is {respJson.minuploadtime} sec, Cumulus is configured for {AWEKAS.OriginalInterval} sec, increasing Cumulus interval to match AWEKAS");
AWEKAS.Interval = respJson.minuploadtime;
WriteIniFile();
AwekasTimer.Interval = AWEKAS.Interval * 1000;
AWEKAS.SynchronisedUpdate = AWEKAS.Interval % 60 == 0;
AwekasTimer.Enabled = !AWEKAS.SynchronisedUpdate;
// we got a successful upload, and reset the interval, so clear the rate limited values
AWEKAS.OriginalInterval = AWEKAS.Interval;
AWEKAS.RateLimited = false;
}
else if (AWEKAS.RateLimited && respJson.status > 0)
{
// We are currently rate limited, it could have been a transient thing because
// we just got a valid response, and our interval is >= the minimum allowed.
// So we just undo the limit, and resume as before
LogMessage($"AWEKAS: Removing temporary increase in upload interval to 60 secs, resuming uploads every {AWEKAS.OriginalInterval} secs");
AWEKAS.Interval = AWEKAS.OriginalInterval;
AwekasTimer.Interval = AWEKAS.Interval * 1000;
AWEKAS.SynchronisedUpdate = AWEKAS.Interval % 60 == 0;
AwekasTimer.Enabled = !AWEKAS.SynchronisedUpdate;
AWEKAS.RateLimited = false;
}
}

// check the min upload time is greater than our upload time
if (respJson.status > 0 && respJson.minuploadtime > AWEKAS.OriginalInterval)
{
LogMessage($"AWEKAS: The minimum upload time to AWEKAS for your station is {respJson.minuploadtime} sec, Cumulus is configured for {AWEKAS.OriginalInterval} sec, increasing Cumulus interval to match AWEKAS");
AWEKAS.Interval = respJson.minuploadtime;
WriteIniFile();
AwekasTimer.Interval = AWEKAS.Interval * 1000;
AWEKAS.SynchronisedUpdate = AWEKAS.Interval % 60 == 0;
AwekasTimer.Enabled = !AWEKAS.SynchronisedUpdate;
// we got a successful upload, and reset the interval, so clear the rate limited values
AWEKAS.OriginalInterval = AWEKAS.Interval;
AWEKAS.RateLimited = false;
}
else if (AWEKAS.RateLimited && respJson.status > 0)
{
// We are currently rate limited, it could have been a transient thing because
// we just got a valid response, and our interval is >= the minimum allowed.
// So we just undo the limit, and resume as before
LogMessage($"AWEKAS: Removing temporary increase in upload interval to 60 secs, resuming uploads every {AWEKAS.OriginalInterval} secs");
AWEKAS.Interval = AWEKAS.OriginalInterval;
AwekasTimer.Interval = AWEKAS.Interval * 1000;
AWEKAS.SynchronisedUpdate = AWEKAS.Interval % 60 == 0;
AwekasTimer.Enabled = !AWEKAS.SynchronisedUpdate;
AWEKAS.RateLimited = false;
}
}
catch (Exception ex)
Expand Down Expand Up @@ -2561,11 +2574,6 @@ private void RealtimeFTPUpload(byte cycle)
var remoteFile = remotePath + RealtimeFiles[i].RemoteFileName;
var localFile = RealtimeFiles[i].LocalPath + RealtimeFiles[i].LocalFileName;

if (RealtimeFiles[i].Create && !string.IsNullOrWhiteSpace(RealtimeFiles[i].TemplateFileName))
{
ProcessTemplateFile(RealtimeFiles[i].TemplateFileName, localFile, tokenParser);
}

LogFtpMessage($"Realtime[{cycle}]: Uploading - {RealtimeFiles[i].LocalFileName}");
if (Sslftp == FtpProtocols.SFTP)
{
Expand Down
2 changes: 1 addition & 1 deletion CumulusMX/InternetSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ public string GetInternetAlpacaFormSchema()
public string GetExtraWebFilesData()
{
var json = new StringBuilder(10240);
json.Append("{\"metadata\":[{\"name\":\"local\",\"label\":\"Local Filename\",\"datatype\":\"string\",\"editable\":true},{\"name\":\"remote\",\"label\":\"Remote Filename\",\"datatype\":\"string\",\"editable\":true},{\"name\":\"process\",\"label\":\"Process\",\"datatype\":\"boolean\",\"editable\":true},{\"name\":\"realtime\",\"label\":\"Realtime\",\"datatype\":\"boolean\",\"editable\":true},{\"name\":\"ftp\",\"label\":\"FTP\",\"datatype\":\"boolean\",\"editable\":true},{\"name\":\"utf8\",\"label\":\"UTF-8\",\"datatype\":\"boolean\",\"editable\":true},{\"name\":\"binary\",\"label\":\"Binary\",\"datatype\":\"boolean\",\"editable\":true},{\"name\":\"endofday\",\"label\":\"End of day\",\"datatype\":\"boolean\",\"editable\":true}],\"data\":[");
json.Append("{\"metadata\":[{\"name\":\"local\",\"label\":\"Local Filename\",\"datatype\":\"string\",\"editable\":true},{\"name\":\"remote\",\"label\":\"Destination Filename\",\"datatype\":\"string\",\"editable\":true},{\"name\":\"process\",\"label\":\"Process\",\"datatype\":\"boolean\",\"editable\":true},{\"name\":\"realtime\",\"label\":\"Realtime\",\"datatype\":\"boolean\",\"editable\":true},{\"name\":\"ftp\",\"label\":\"FTP\",\"datatype\":\"boolean\",\"editable\":true},{\"name\":\"utf8\",\"label\":\"UTF-8\",\"datatype\":\"boolean\",\"editable\":true},{\"name\":\"binary\",\"label\":\"Binary\",\"datatype\":\"boolean\",\"editable\":true},{\"name\":\"endofday\",\"label\":\"End of day\",\"datatype\":\"boolean\",\"editable\":true}],\"data\":[");

for (int i = 0; i < Cumulus.numextrafiles; i++)
{
Expand Down
Loading

0 comments on commit 3090ac2

Please sign in to comment.