Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/SparkplugNet/Core/Node/SparkplugNodeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ public async Task Start(SparkplugNodeOptions nodeOptions, KnownMetricStorage? kn
// Connect, subscribe to incoming messages and send a state message.
await this.ConnectInternal();
await this.SubscribeInternal();
await this.PublishNodeAndDeviceBirthsInternal();

// When a primary host is defined, wait before sending NBIRTH and DBIRTH
if (string.IsNullOrEmpty(this.Options.ScadaHostIdentifier))
{
await this.PublishNodeAndDeviceBirthsInternal();
}
}

/// <summary>
Expand Down Expand Up @@ -124,21 +129,30 @@ public async Task<MqttClientPublishResult> PublishMetrics(IEnumerable<T> metrics
}

/// <summary>
/// Does a node rebirth.
/// Does a node birth.
/// </summary>
/// <param name="metrics">The new metrics.</param>
public async Task Rebirth(IEnumerable<T> metrics)
public async Task Birth(IEnumerable<T> metrics)
{
// Send node death first.
await this.SendNodeDeathMessage();

// Reset the known metrics.
this.knownMetrics = new KnownMetricStorage(metrics);

// Send node birth and device births.
await this.PublishNodeAndDeviceBirthsInternal();
}

/// <summary>
/// Does a node rebirth.
/// </summary>
/// <param name="metrics">The new metrics.</param>
public async Task Rebirth(IEnumerable<T> metrics)
{
// Send node death first.
await this.SendNodeDeathMessage();

await this.Birth(metrics);
}

/// <summary>
/// Publishes metrics for a node.
/// </summary>
Expand Down