SparkplugNet is a library that implements the Sparkplug IIoT standard on top of
MQTTnet. It is published as the NuGet package
SparkplugNet, so the library project sets
GeneratePackageOnBuild and the repository ships BuildAndPushPackage.bat for the upload. Both
Sparkplug payload versions are supported, version A (the old Kura format, namespace spAv1.0) and
version B (spBv1.0), and for version B both specification versions 2.2 and 3.0.
One solution src/SparkplugNet.sln with exactly three projects:
src/SparkplugNet/SparkplugNet.csproj, the library, targetingnet10.0andnet11.0.src/SparkplugNet.Tests/SparkplugNet.Tests.csproj, MSTest, targetingnet10.0andnet11.0.dotnet testreports 72 results per framework because one of the 71 test methods carries twoDataRowattributes.src/SparkplugNet.Examples/SparkplugNet.Examples.csproj,Exe,net10.0, a console demo that runs an application and a node for both payload versions againstlocalhost:1883.
Layout inside src/SparkplugNet:
Core/SparkplugBase.csand its partial files (.Events.cs,.EventArgs.cs,.KnownMetricStorage.cs): the generic base of everything,SparkplugBase<T> where T : IMetric. It owns theIMqttClient, the sequence and session numbers and the nested classKnownMetricStorage.Core/Application/SparkplugApplicationBase.csplus its partial files: the SCADA host side. It subscribes to the whole namespace, tracksNodeStatesandDeviceStatesand publishes STATE.Core/Node/SparkplugNodeBase.csplus.Device.csand the partial files: the edge node side, including the devices hanging off a node.Core/Messages/SparkplugMessageGenerator.cs: the largest file of the repository. It builds every MQTT message (STATE, NBIRTH, DBIRTH, NDEATH, DDEATH, NDATA, DDATA, NCMD, DCMD), each of them once for version A and once for version B. New message types follow that same pairing.Core/Messages/SparkplugTopicGenerator.cs: builds andCore/Topics/parses the topic strings.Core/PayloadHelper.cs: protobuf-net serialization plus the byte conversion helpers. The file also carries the assembly levelInternalsVisibleTo("SparkplugNet.Tests"), which is what makes the internal message generator testable.VersionA/andVersionB/:Data/holds the public metric types,ProtoBuf/the generated wire format types,PayloadConverter.csconverts between the two, andSparkplugApplication.csandSparkplugNode.csare the concrete classes a consumer instantiates.GlobalUsings.cs: all usings of the project, including the aliasesVersionAData,VersionBData,VersionAProtoBuf,VersionBProtoBuf,VersionADataTypeEnum,VersionBDataTypeEnumandSystemCancellationToken.
Repository root: README.md (badges, supported frameworks, structure), HowToUse.md (the usage
samples for both versions), Changelog.md, Updating.md (the five step release recipe),
testing/sparkplug-tck/ (the official Sparkplug 3.0 TCK setup), License.txt (MIT), Icon.png and Icon.svg,
.all-contributorsrc, BuildAndPushPackage.bat, Delete-BIN-OBJ-Folders.bat, .editorconfig
(under src) and .gitattributes. doc/ holds the specification PDFs and the two .proto files
the ProtoBuf classes were generated from.
dotnet build src/SparkplugNet.sln -c Releasedotnet test src/SparkplugNet.sln -c Release- Building the solution requires the .NET 11 SDK. Running the full test suite requires the .NET 10 and .NET 11 runtimes.
src/Directory.Build.propscontains nothing butGenerateDocumentationFile. Every other build property lives in the three.csprojfiles and is duplicated there.TreatWarningsAsErrorsis enabled in all three projects, so every warning breaks the build, NuGet warnings (NU****) from restore included. A clean build reports zero warnings, keep it that way.- The
NoWarnlist isNU1803,CS0618,CS0809,NU1901,NU1902in all three projects.CS0618andCS0809are there because the library keeps obsolete members alive,NU1901andNU1902hide low and moderate vulnerability audit findings. Fix warnings instead of extending that list.NuGetAuditMode=allis on, so a vulnerable transitive package fails the build too. - Versions come from GitVersion.MsBuild out of the git tags, for example
1.4.2-5for the fifth commit after tag1.4.1. There is noGitVersion.yml, the defaults apply. Never edit a version property or an assembly version by hand. - Restore needs nuget.org. If a private feed is configured globally on the machine and answers 404
for public packages, restore fails with
NU1301. Then build with an explicit source:dotnet build src/SparkplugNet.sln --source https://api.nuget.org/v3/index.json. - Tests are MSTest and need no broker and no network. They cover the message generator for
specification versions 2.2 and 3.0, the payload converters for both versions, the known metric
storage including its filtering, and the metric timestamp handling.
EqualityHelper.csis not a test class, it is the deep comparison the payload tests run on. Never claim a test run happened without running it. testing/sparkplug-tck/runs the Eclipse Sparkplug 3.0.0 Host Application and Edge Node scenarios against HiveMQ with MQTT 3.1.1 and MQTT 5. See the README there for the runner and logs.SparkplugNet.Examplescan also connect to a broker onlocalhost:1883.
Follow the surrounding code, it is consistent throughout every file:
- File header comment block with
<copyright file="..." company="Hämmer Electronics">and a<summary>, then the file-scoped namespace. - XML doc comments on every type and every member, private members included, no exceptions.
Implementations of an interface member additionally carry
<inheritdoc cref="..."/>and<seealso cref="..."/>pointing at that interface.GenerateDocumentationFileis on, so a missing comment is a warning and therefore an error. Nullable,ImplicitUsingsandLangVersion latestare enabled.- New
usingdirectives go into theGlobalUsings.csof the respective project, inside the existing#pragma warning disable IDE0065block, never at the top of a file. The editorconfig requires usings inside the namespace (csharp_using_directive_placement=inside_namespace:warning), which global usings cannot satisfy, that is what the pragma is for. Do not add other pragmas. The comment text in that block is German because Visual Studio generated it, leave it alone. - Fields, properties, methods and events are always accessed with
this.qualification (dotnet_style_qualification_for_*at severitywarning). src/.editorconfigalso enforces braces everywhere, no multiple blank lines, four spaces, CRLF, UTF-8, file scoped namespaces,Systemusings sorted first andIDE0005as warning. Analyzer warnings are fixed, not silenced.- The
.csprojfiles use four spaces of indentation inside<Project>, unlike the Visual Studio default.
Do not silently "clean up" these, they are existing behaviour:
WithCookieContainer(ICredentials)really sets the credentials. BothConnectInternalmethods callWithCookieContainertwice on the web socket builder, once with the cookie container and once with the credentials. That reads like a copy and paste error but it is not, MQTTnet has an overload of that name takingICredentialswhich assignsCredentials. Verified against MQTTnet 5.2, do not "fix" it into aWithCredentialscall that does not exist.- UInt32 does not sit in the same protobuf field everywhere. The encoder writes UInt32 metrics
to
int_valueand writes UInt32DataSetValue,ParameterandPropertyValueentries tolong_value. The decoder accepts either field in all four cases for interoperability. - Version A is the Kura format, not "Sparkplug A".
VersionA/Data/KuraMetric.cscarries a flat set of typed value properties, version B usesMetricwith aDataTypeand a single boxed value. The two are not convertible into each other, which is why every message generator method and every event exists twice. - The ProtoBuf classes are generated, the data classes are not.
VersionA/ProtoBuf/andVersionB/ProtoBuf/mirrordoc/SparkplugA.protoanddoc/SparkplugB.proto. The classes underData/are handwritten and richer.PayloadConverteris the only bridge, and a change on one side without the other silently breaks the wire format. - STATE messages differ per specification version. Version 2.2 publishes the plain strings
ONLINEandOFFLINEonSTATE/<host>, version 3.0 publishes the JSON ofStateMessageonspBv1.0/STATE/<host>. Both are retained and sent with QoS 1, the rest of the library uses QoS 0. The application deliberately skips incoming STATE messages inOnApplicationMessageReceivedbecause they are UTF-8 and not protobuf. SparkplugMessageTopic.TryParsedecides what is handled. Anything it cannot parse is dropped without an error, the STATE branch is the only explicit exception. A topic typo therefore looks like silence, not like a failure.InternalsVisibleTosits inPayloadHelper.cs. Not in anAssemblyInfo.cs, not in the.csproj. The tests reachSparkplugMessageGeneratorandPayloadHelperthrough it.KnownMetricStoragekeys by name and by alias in two dictionaries.Metricsconcatenates both, so a metric that has a name and an alias would show up twice. Version A metrics only ever go into the name dictionary.- The session number starts at -1.
LastSessionNumberis incremented before the connect, so the first bdSeq that reaches the broker is 0, which is what the specification demands.LastSequenceNumberstarts at 0 and is incremented after publishing. eclipse_tahuis a submodule, not a folder. It points at https://github.com/eclipse/tahu, pinned to5736e40(tagv1.0.7), and it is the reference implementation the.protofiles underdoc/come from. Clone withgit clone --recursive, or rungit submodule update --initafterwards, otherwise the directory stays empty. Up to version 1.4.0 the gitlink was committed without a.gitmodulesentry, so it could not be checked out at all.- AppVeyor badge without CI in the repository.
README.mdlinks an AppVeyor build that is configured outside of this repository. There is no.githubfolder and no pipeline file here. src/SparkplugNet.sln.DotSettingsis tracked and holds nothing but a ReSharper user dictionary (the Sparkplug message type abbreviations,Kura,scada,H_00E4mmer). Leave it alone..gitattributessets* text=autoand every rule of the Visual Studio template below it is commented out. The.pdffiles underdoc/are only safe because git detects them as binary, any further binary file should get its own rule.Updating.mddescribes the old, manual release. The authoritative order is the one under "Releasing" below.Updating.mdsays "build with Visual Studio", which nobody does.
Every new version is released completely. Changelog, README, nuget.org, GitHub Packages and a GitHub release belong to every version, none of these steps is optional and none of them waits for a separate request.
- Make the change.
- Add an entry at the top of
Changelog.mdin the existing format:* **Version 1.4.2.0 (2026-08-18)**: Short description. - Update
<PackageReleaseNotes>insrc/SparkplugNet/SparkplugNet.csprojto the same text. It is the one version string that is maintained by hand, everything else comes from GitVersion. - Update
README.mdfor every version, the part above the contributors table. The "Available for" list has to match the target frameworks, breaking changes go into the "Special notes" section, and nothing there may describe a state the packages have left behind. If the change is user visible, updateHowToUse.mdas well. - Commit that.
- Tag the commit with the plain version number, no
vprefix (1.4.1,1.4.0,1.3.10, ...). The existing tags are lightweight tags, create new ones the same way. - Push the commits and the tag.
- Publish the packages with
BuildAndPushPackage.bat. It deletes everybinandobjbelowsrc, builds Release, builds the nanoFramework project and packs its.nuspecwith the GitVersion version ofSparkplugNet, then pushes theSparkplugNet,SparkplugNet.Extensions.JsonandSparkplugNet.nanoFrameworkpackages to nuget.org and to the GitHub package feed. It needsNUGET_API_KEYandGITHUB_API_KEYin the environment,nuget.exeon the PATH and the MSBuild of Visual Studio or the Build Tools with the nanoFramework extension (orNanoFrameworkProjectSystemPathpointing at the extracted extension files). It must run after the tag, otherwise GitVersion burns a prerelease version into the packages. Call it with its full path: the Claude Code shell setsNoDefaultCurrentDirectoryInExePath=1, so cmd does not find a bareBuildAndPushPackage.batin the current directory. A push to nuget.org cannot be taken back, the version is burned even after unlisting. nuget.org needs a few minutes to validate a new version before it is listed. Check afterwards that all three packages arrived on nuget.org and on GitHub Packages (gh api /users/SeppPenner/packages/nuget/<id>/versions). - Create the GitHub release:
gh release create 1.4.2 -R SeppPenner/SparkplugNet --verify-tag --latest --title "Version 1.4.2.0 (2026-08-18)" --notes-file <file>. The notes are the changelog sentence plus one line per package, for exampleNuGet: https://www.nuget.org/packages/SparkplugNet/1.4.2. Write credits as`@name`in backticks, a bare@namenotifies that person again.
On 2026-11-23 eleven of the tags had a GitHub release (the newest is 1.5.0), the older history there is incomplete.
The version in the Changelog.md has four parts (1.4.1.0), the tag has three (1.4.1). The
oldest tags (1.0, 0.7) have two, do not copy that.
GitVersion turns the tag into the assembly version, so an untagged commit produces something like
1.4.2-5+Branch.master.Sha....
- Include the full GitHub pull request or issue URL in the body of each related commit on a
Refs:line. Use the GitHub issue skill for issue work and closeout. - Never amend a commit. No
git commit --amend, not for a typo in the message, not to add a forgotten file, not even when the commit is still local. Write a follow-up commit instead. The release versions come from tags on exact commits, an amended commit leaves its tag pointing at a commit that no longer exists in the branch.
- Commit messages are written in English only: short, precise subject line, explanatory body when needed.
- Code comments and comments in project files such as
.csprojare always English, regardless of the language used in the conversation. - No em dashes or en dashes (
—,–), neither in prose, commit messages, code comments nor documentation. Use a regular hyphen, comma, colon, parentheses or a separate sentence. - German texts (documentation, chat replies) always use real umlauts and ß, never ASCII
transliterations such as
ae,oe,ueorss. Identifiers, file names and configuration keys stay unchanged where umlauts are technically undesirable.