Skip to content

Commit

Permalink
Merge pull request #109 from mcrossley/master
Browse files Browse the repository at this point in the history
v3.10.5
  • Loading branch information
mcrossley authored Apr 6, 2021
2 parents b9da880 + 6d01266 commit e24ae3d
Show file tree
Hide file tree
Showing 9 changed files with 688 additions and 609 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
184 changes: 122 additions & 62 deletions CumulusMX/GW1000Station.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ internal class GW1000Station : WeatherStation

private Version fwVersion;

private string mainSensor;

private enum Commands : byte {
// General order
CMD_WRITE_SSID = 0x11,// send router SSID and Password to wifi module
Expand Down Expand Up @@ -277,6 +279,8 @@ public GW1000Station(Cumulus cumulus) : base(cumulus)
var fwString = GW1000FirmwareVersion.Split(new string[] { "_V" }, StringSplitOptions.None);
fwVersion = new Version(fwString[1]);

GetSystemInfo();

GetSensorIdsNew();
}

Expand Down Expand Up @@ -614,6 +618,7 @@ private string GetFirmwareVersion()
return response;
}

/*
private bool GetSensorIds()
{
cumulus.LogMessage("Reading sensor ids");
Expand Down Expand Up @@ -647,6 +652,43 @@ private bool GetSensorIds()
}
}
private void PrintSensorInfo(byte[] data, int idx)
{
// expected response
// 0 - 0xff - header
// 1 - 0xff - header
// 2 - 0x3A - sensor id command
// 3 - 0x?? - size of response
// 4 - wh65
// 5-8 - wh65 id
// 9 - wh65 signal
// 10 - wh65 battery
// 11 - wh68
// ... etc
// (??) - 0x?? - checksum
var id = ConvertBigEndianUInt32(data, idx + 1);
var type = Enum.GetName(typeof(SensorIds), data[idx]).ToUpper();
if (string.IsNullOrEmpty(type))
{
type = $"unknown type = {id}";
}
switch (id)
{
case 0xFFFFFFFE:
cumulus.LogDebugMessage($" - {type} sensor = disabled");
break;
case 0xFFFFFFFF:
cumulus.LogDebugMessage($" - {type} sensor = registering");
break;
default:
cumulus.LogDebugMessage($" - {type} sensor id = {id} signal = {data[idx+5]} battery = {data[idx+6]}");
break;
}
}
*/

private bool GetSensorIdsNew()
{
cumulus.LogMessage("Reading sensor ids");
Expand All @@ -666,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 All @@ -689,41 +731,6 @@ private bool GetSensorIdsNew()
return false;
}
}
private void PrintSensorInfo(byte[] data, int idx)
{
// expected response
// 0 - 0xff - header
// 1 - 0xff - header
// 2 - 0x3A - sensor id command
// 3 - 0x?? - size of response
// 4 - wh65
// 5-8 - wh65 id
// 9 - wh65 signal
// 10 - wh65 battery
// 11 - wh68
// ... etc
// (??) - 0x?? - checksum

var id = ConvertBigEndianUInt32(data, idx + 1);
var type = Enum.GetName(typeof(SensorIds), data[idx]);

if (string.IsNullOrEmpty(type))
{
type = $"unknown type = {id}";
}
switch (id)
{
case 0xFFFFFFFE:
cumulus.LogDebugMessage($" - {type} sensor = disabled");
break;
case 0xFFFFFFFF:
cumulus.LogDebugMessage($" - {type} sensor = registering");
break;
default:
cumulus.LogDebugMessage($" - {type} sensor id = {id} signal = {data[idx+5]} battery = {data[idx+6]}");
break;
}
}

private bool PrintSensorInfoNew(byte[] data, int idx)
{
Expand All @@ -741,14 +748,20 @@ private bool PrintSensorInfoNew(byte[] data, int idx)
// (??) - 0x?? - checksum

var id = ConvertBigEndianUInt32(data, idx + 1);
var type = Enum.GetName(typeof(SensorIds), data[idx]);
var type = Enum.GetName(typeof(SensorIds), data[idx]).ToUpper();
var battPos = idx + 5;
var sigPos = idx + 6;
var batteryLow = false;
if (string.IsNullOrEmpty(type))
{
type = $"unknown type = {id}";
}
// Wh65 could be a Wh65 or a Wh24, we found out using the System Info command
if (type == "WH65")
{
type = mainSensor;
}

switch (id)
{
case 0xFFFFFFFE:
Expand All @@ -765,30 +778,34 @@ private bool PrintSensorInfoNew(byte[] data, int idx)
string batt;
switch (type)
{
case "Wh65":
case "Wh40":
case "Wh26":
case "WH40": // WH40 does not send any battery info :(
batt = "n/a";
break;

case "WH65":
case "WH24":
case "WH26":
batt = TestBattery1(data[battPos], 1); // 0 or 1
break;

case "Wh68":
case "Wh80":
case string wh34 when wh34.StartsWith("Wh34"): // ch 1-8
case string wh35 when wh35.StartsWith("Wh35"): // ch 1-8
case "WH68":
case "WH80":
case string wh34 when wh34.StartsWith("WH34"): // ch 1-8
case string wh35 when wh35.StartsWith("WH35"): // ch 1-8
double battV = data[battPos] * 0.02;
batt = $"{battV:f1}V ({TestBattery4S(data[battPos])})"; // volts, low = 1.2V
break;

case string wh31 when wh31.StartsWith("Wh31"): // ch 1-8
case string wh51 when wh51.StartsWith("Wh51"): // ch 1-8
case string wh31 when wh31.StartsWith("WH31"): // ch 1-8
case string wh51 when wh51.StartsWith("WH51"): // ch 1-8
batt = $"{data[battPos]} ({TestBattery1(data[battPos], 1)})";
break;

case "Wh25":
case "Wh45":
case "Wh57":
case string wh41 when wh41.StartsWith("Wh41"): // ch 1-4
case string wh55 when wh55.StartsWith("Wh55"): // ch 1-4
case "WH25":
case "WH45":
case "WH57":
case string wh41 when wh41.StartsWith("WH41"): // ch 1-4
case string wh55 when wh55.StartsWith("WH55"): // ch 1-4
batt = $"{data[battPos]} ({TestBattery3(data[battPos])})"; // 0-5, low = 1
break;

Expand Down Expand Up @@ -1110,20 +1127,29 @@ private void GetLiveData()
chan /= 2; // -> 1,2,3,4...
tempInt16 = ConvertBigEndianInt16(data, idx);
DoUserTemp(ConvertTempCToUser(tempInt16 / 10.0), chan);
if (tenMinuteChanged)

// Firmware version 1.5.9 uses 2 data bytes, 1.6.0+ uses 3 data bytes
if (fwVersion.CompareTo(new Version("1.6.0")) >= 0)
{
var volts = TestBattery4V(data[idx + 2]);
if (volts <= 1.2)
{
batteryLow = true;
cumulus.LogMessage($"WH34 channel #{chan} battery LOW = {volts}V");
}
else
if (tenMinuteChanged)
{
cumulus.LogDebugMessage($"WH34 channel #{chan} battery OK = {volts}V");
var volts = TestBattery4V(data[idx + 2]);
if (volts <= 1.2)
{
batteryLow = true;
cumulus.LogMessage($"WH34 channel #{chan} battery LOW = {volts}V");
}
else
{
cumulus.LogDebugMessage($"WH34 channel #{chan} battery OK = {volts}V");
}
}
idx += 3;
}
else
{
idx += 2;
}
idx += 3; // Firmware version 1.5.9 uses 2 data bytes, 1.6.0+ uses 3 data bytes
break;
case 0x6B: //WH34 User temperature battery (8 channels) - No longer used in firmware 1.6.0+
if (tenMinuteChanged)
Expand Down Expand Up @@ -1256,6 +1282,40 @@ private void GetLiveData()
}
}

private void GetSystemInfo()
{
cumulus.LogMessage("Reading GW1000 system info");

var data = DoCommand((byte)Commands.CMD_READ_SSSS);

// expected response
// 0 - 0xff - header
// 1 - 0xff - header
// 2 - 0x30 - system info
// 3 - 0x?? - size of response
// 4 - frequency - 0=433, 1=868MHz
// 5 - sensor type - 0=WH24, 1=WH65
// 6-9 - UTC time
// 10 - timezone index (?)
// 11 - DST 0-1 - false/true
// 12 - 0x?? - checksum

if (data.Length != 13)
{
cumulus.LogMessage("Unexpected response to Sysetm Info!");
return;
}

var freq = data[4] == 0 ? "433MHz" : "868MHz";
mainSensor = data[5] == 0 ? "WH24" : "WH65";

var unix = ConvertBigEndianUInt32(data, 6);
var date = Utils.FromUnixTime(unix);
var dst = data[11] != 0;

cumulus.LogMessage($"GW1000 Info: freqency: {freq}, main sensor: {mainSensor}, date/time: {date:F}, Automatic DST adjustment: {dst}");
}

private byte[] DoCommand(byte command)
{
var buffer = new byte[2028];
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
Loading

0 comments on commit e24ae3d

Please sign in to comment.