Skip to content

Commit

Permalink
- Fix: Occasional GW1000 crash on GetSensorIdsNew response timeout
Browse files Browse the repository at this point in the history
- Fix: GW1000, WH40 rain gauge, removed battery status check as it does not send this information
- Fix: Adds missing WeatherCloud interval setting to Internet Settings
- New: Adds option to upload AQ data to WeatherCloud
  • Loading branch information
mcrossley committed Apr 1, 2021
1 parent aeeae3a commit e0a7d66
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CumulusMX/Cumulus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ public Cumulus(int HTTPport, bool DebugEnabled, string startParms)
//LogDB.CreateTable<StandardData>();

// Open diary database (create file if it doesn't exist)
//DiaryDB = new SQLiteConnection(diaryfile, flags, true); // We should be using this - storing datetime as ticks, but historically string storage has been used, so we are stuck with it?
DiaryDB = new SQLiteConnection(diaryfile, flags);
DiaryDB.CreateTable<DiaryData>();

Expand Down Expand Up @@ -3971,6 +3972,7 @@ private void ReadIniFile()
WCloud.Interval = ini.GetValue("WeatherCloud", "Interval", WCloud.DefaultInterval);
WCloud.SendUV = ini.GetValue("WeatherCloud", "SendUV", false);
WCloud.SendSolar = ini.GetValue("WeatherCloud", "SendSR", false);
WCloud.SendAQI = ini.GetValue("WeatherCloud", "SendAQI", false);

WCloud.SynchronisedUpdate = (60 % WCloud.Interval == 0);

Expand Down Expand Up @@ -4707,6 +4709,7 @@ internal void WriteIniFile()
ini.SetValue("WeatherCloud", "Interval", WCloud.Interval);
ini.SetValue("WeatherCloud", "SendUV", WCloud.SendUV);
ini.SetValue("WeatherCloud", "SendSR", WCloud.SendSolar);
ini.SetValue("WeatherCloud", "SendAQI", WCloud.SendAQI);

ini.SetValue("Twitter", "User", Twitter.ID);
ini.SetValue("Twitter", "Password", Twitter.PW);
Expand Down Expand Up @@ -9621,6 +9624,7 @@ public class WebUploadService
public bool SendUV;
public bool SendSolar;
public bool SendIndoor;
public bool SendAQI;
public bool CatchUp;
public bool CatchingUp;
public bool Updating;
Expand Down
20 changes: 3 additions & 17 deletions CumulusMX/FOStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,8 @@ public override void getAndProcessHistoryData()

cumulus.LogMessage(msg);

msg = "Data block: ";

for (int i = 0; i < numBytes; i++)
{
msg += data[i].ToString("X2");
msg += " ";
}

cumulus.LogDataMessage(msg);
cumulus.LogDataMessage("Data block: " + BitConverter.ToString(data, 0, numBytes));

histData.timestamp = timestamp;
histData.interval = interval;
Expand Down Expand Up @@ -601,11 +594,9 @@ private void ReadAddress(int address, byte[] buff)
cumulus.LogMessage("Error reading data from station - it may need resetting");
}

var recData = " Data" + i + ": ";
var recData = " Data" + i + ": " + BitConverter.ToString(response, startByte, responseLength - startByte);
for (int j = startByte; j < responseLength; j++)
{
recData += response[j].ToString("X2");
recData += " ";
buff[ptr++] = response[j];
}
cumulus.LogDataMessage(recData);
Expand Down Expand Up @@ -759,12 +750,7 @@ private void GetAndProcessData()

if ((!synchronising) || ((readCounter%20) == 0))
{
LatestFOReading = addr.ToString("X4") + ":";
for (int i = 0; i < 16; i++)
{
LatestFOReading = LatestFOReading + " " + data[i].ToString("X2");
}

LatestFOReading = addr.ToString("X4") + ": " + BitConverter.ToString(data, 0, 16);
cumulus.LogDataMessage(LatestFOReading);

// Indoor Humidity ====================================================
Expand Down
9 changes: 6 additions & 3 deletions CumulusMX/GW1000Station.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,12 +708,12 @@ private bool GetSensorIdsNew()
// ... etc
// (??) - 0x?? - checksum

var len = ConvertBigEndianUInt16(data, 3);

var batteryLow = false;

if (null != data && data.Length > 200)
{
var len = ConvertBigEndianUInt16(data, 3);

for (int i = 5; i < len; i += 7)
{
if (PrintSensorInfoNew(data, i))
Expand Down Expand Up @@ -778,9 +778,12 @@ private bool PrintSensorInfoNew(byte[] data, int idx)
string batt;
switch (type)
{
case "WH40": // WH40 does not send any battery info :(
batt = "n/a";
break;

case "WH65":
case "WH24":
case "WH40":
case "WH26":
batt = TestBattery1(data[battPos], 1); // 0 or 1
break;
Expand Down
6 changes: 6 additions & 0 deletions CumulusMX/InternetSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ public string UpdateInternetConfig(IHttpContext context)
{
cumulus.WCloud.ID = settings.weathercloud.wid ?? string.Empty;
cumulus.WCloud.PW = settings.weathercloud.key ?? string.Empty;
cumulus.WCloud.Interval = settings.weathercloud.interval;
cumulus.WCloud.SendSolar = settings.weathercloud.includesolar;
cumulus.WCloud.SendUV = settings.weathercloud.includeuv;
cumulus.WCloud.SendAQI = settings.weathercloud.includeaqi;
cumulus.WCloud.SynchronisedUpdate = (60 % cumulus.WCloud.Interval == 0);

cumulus.WCloudTimer.Interval = cumulus.WCloud.Interval * 60 * 1000;
Expand Down Expand Up @@ -727,8 +729,10 @@ public string GetInternetAlpacaFormData()
var wcloudsettings = new JsonInternetSettingsWCloud()
{
enabled = cumulus.WCloud.Enabled,
interval = cumulus.WCloud.Interval,
includesolar = cumulus.WCloud.SendSolar,
includeuv = cumulus.WCloud.SendUV,
includeaqi = cumulus.WCloud.SendAQI,
key = cumulus.WCloud.PW,
wid = cumulus.WCloud.ID
};
Expand Down Expand Up @@ -1134,8 +1138,10 @@ public class JsonInternetSettingsAwekas
public class JsonInternetSettingsWCloud
{
public bool enabled { get; set; }
public int interval { get; set; }
public bool includeuv { get; set; }
public bool includesolar { get; set; }
public bool includeaqi { get; set; }
public string wid { get; set; }
public string key { get; set; }
}
Expand Down
41 changes: 40 additions & 1 deletion CumulusMX/WeatherStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8441,7 +8441,7 @@ public void SetDefaultYearlyHighsAndLows()
public string GetWCloudURL(out string pwstring, DateTime timestamp)
{
pwstring = cumulus.WCloud.PW;
StringBuilder sb = new StringBuilder($"http://api.weathercloud.net/v01/set?wid={cumulus.WCloud.ID}&key={pwstring}");
StringBuilder sb = new StringBuilder($"https://api.weathercloud.net/v01/set?wid={cumulus.WCloud.ID}&key={pwstring}");

//Temperature
sb.Append("&tempin=" + (int)Math.Round(ConvertUserTempToC(IndoorTemperature) * 10));
Expand Down Expand Up @@ -8488,6 +8488,45 @@ public string GetWCloudURL(out string pwstring, DateTime timestamp)
sb.Append("&uvi=" + (int)Math.Round(UV * 10));
}

// aq
if (cumulus.WCloud.SendAQI)
{
sb.Append("&");

switch (cumulus.StationOptions.PrimaryAqSensor)
{
case (int)Cumulus.PrimaryAqSensor.AirLinkOutdoor:
if (cumulus.airLinkDataOut != null)
{
sb.Append($"pm25={cumulus.airLinkDataOut.pm2p5:F0}");
sb.Append($"&pm10={cumulus.airLinkDataOut.pm10:F0}");
sb.Append($"&aqi={AirQualityIndices.US_EPApm2p5(cumulus.airLinkDataOut.pm2p5_24hr)}");
}
break;
case (int)Cumulus.PrimaryAqSensor.Ecowitt1:
sb.Append($"pm25={AirQuality1:F0}");
sb.Append($"&aqi={AirQualityIndices.US_EPApm2p5(AirQualityAvg1)}");
break;
case (int)Cumulus.PrimaryAqSensor.Ecowitt2:
sb.Append($"pm25={AirQuality2:F0}");
sb.Append($"&aqi={AirQualityIndices.US_EPApm2p5(AirQualityAvg2)}");
break;
case (int)Cumulus.PrimaryAqSensor.Ecowitt3:
sb.Append($"pm25={AirQuality3:F0}");
sb.Append($"&aqi={AirQualityIndices.US_EPApm2p5(AirQualityAvg3)}");
break;
case (int)Cumulus.PrimaryAqSensor.Ecowitt4:
sb.Append($"pm25={AirQuality4:F0}");
sb.Append($"&aqi={AirQualityIndices.US_EPApm2p5(AirQualityAvg4)}");
break;
case (int)Cumulus.PrimaryAqSensor.EcowittCO2:
sb.Append($"pm25={CO2_pm2p5:F0}");
sb.Append($"&pm10={CO2_pm10:F0}");
sb.Append($"&aqi={AirQualityIndices.US_EPApm2p5(CO2_pm2p5_24h)}");
break;
}
}

// time
sb.Append("&time=" + timestamp.ToString("HHmm"));

Expand Down
5 changes: 5 additions & 0 deletions Updates.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
3.10.5 - b3122
——————————————
- Fix: Comma decimal issues with OpenWeatherMap and other third party uploads
- Fix: Occasional GW1000 crash on GetSensorIdsNew response timeout
- Fix: GW1000, WH40 rain gauge, removed battery status check as it does not send this information
- Fix: Adds missing WeatherCloud interval setting to Internet Settings

- New: Now determines the Ecowitt GW1000 device main sensor type (WH65/WH24) and prints system information to the log file
- New: Adds the free text station model to the Station settings page
- New: Adds a cache buster to default web site webpagedata.json downloads
- New: Adds optional UV index to Now, Today, Yesterday pages of the default web site
- New: All decimal web tag values now accept a dp=N and tc=y overrides for the number of decimal places
- New: Adds option to upload AQ data to WeatherCloud


3.10.4 - b3121
Expand Down

0 comments on commit e0a7d66

Please sign in to comment.