Skip to content

Commit

Permalink
Add Davis WLL collision avoidance to Realtime requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Crossley committed Dec 29, 2022
1 parent 779a454 commit 3d22b98
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CumulusMX/DavisWllStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,17 @@ private async void GetWllRealtime(object source, ElapsedEventArgs e)

if (CheckIpValid(ip))
{
var timeSinceLastMessage = (int) (DateTime.Now.Subtract(LastDataReadTimestamp).TotalMilliseconds % 2500);
if (timeSinceLastMessage > 1500)
{
// Another broadcast is due in the next second or less
var delay = Math.Max(200, 2600 - timeSinceLastMessage);
cumulus.LogDebugMessage($"GetWllRealtime: Delaying {delay} ms");
tmrRealtime.Stop();
await Task.Delay(delay);
tmrRealtime.Start();
}

var urlRealtime = "http://" + ip + "/v1/real_time?duration=" + cumulus.WllBroadcastDuration;

cumulus.LogDebugMessage($"GetWllRealtime: Sending GET real time request to WLL: {urlRealtime} ...");
Expand Down

0 comments on commit 3d22b98

Please sign in to comment.