A .NET-based server application that reads energy data from smart meters via the Smart Message Language (SML) protocol and publishes the values over MQTT. It runs as a systemd daemon on Linux and connects to the meter through a serial optical coupler (e.g. /dev/ttyUSB0).
- SML Protocol Parser -- streaming detector and parser for the Smart Message Language protocol, available as a standalone NuGet package
- MQTT Publishing -- forwards meter readings (purchased/sold energy, current power, grid balance) to an MQTT broker with configurable topics
- Linux Daemon -- runs as a systemd service under a dedicated user with automatic service registration
- CLI Tool -- command-line interface (
smc) for diagnostics and manual data retrieval
| Project | Description |
|---|---|
CreativeCoders.SmartMessageLanguage |
SML framing, TLV parsing, CRC validation, OBIS value extraction |
CreativeCoders.SmartMeter.Core |
Serial port abstraction and configuration options |
CreativeCoders.SmartMeter.DataProcessing |
Value processing pipeline and MQTT publisher |
CreativeCoders.SmartMeter.Server.Core |
Server logic and daemon host builder |
CreativeCoders.SmartMeter.Server.Linux |
Linux systemd daemon entry point |
CreativeCoders.SmartMeter.Cli |
CLI tool for manual interaction |
- .NET 10 SDK (for building from source)
- .NET 10 Runtime (on the target Linux machine)
- A smart meter with an SML-compatible infrared interface
- An optical reading head (IR coupler) connected via USB serial (e.g.
/dev/ttyUSB0) - An MQTT broker (e.g. Mosquitto)
./build.shOr using the .NET CLI directly:
dotnet build
dotnet testThe recommended way to install or update the SmartMeter server on Linux is by using the provided install-smartmeter.sh script. It downloads the distribution package, extracts it, and runs the bundled installer.
Download and run the installer in one step:
curl -fsSL https://raw.githubusercontent.com/CreativeCodersTeam/SmartMeter/main/install-smartmeter.sh -o install-smartmeter.sh
chmod +x install-smartmeter.sh
./install-smartmeter.shThis will:
- Fetch the latest stable release from GitHub
- Download the
SmartMeter.Server.Linux.tar.gzasset - Extract and run the bundled
install.shwithsudo
To install from the latest successful CI build instead of a release (requires the GitHub CLI with authentication):
./install-smartmeter.sh --workflows main.ymlSkip the confirmation prompt with -y:
./install-smartmeter.sh -y| Tool | Required for |
|---|---|
curl |
Downloading the archive |
tar |
Extracting the package |
jq |
Parsing GitHub API responses |
sudo |
Running the privileged installer |
gh |
Only when using --workflows |
The bundled install.sh performs the following steps:
- Stops and disables the existing
smartmeter-serversystemd service (if running) - Backs up the current installation at
/opt/smartmetersrvto/opt/smartmetersrv.bak - Copies the new files to
/opt/smartmetersrv - Creates a dedicated
smartmeter-usersystem user (if it doesn't exist) and adds it to thedialoutgroup for serial port access - Sets file ownership to
smartmeter-user - Registers and starts the systemd service via
dotnet smartmetersrv.dll --install
To update an existing installation, simply run install-smartmeter.sh again. The installer automatically backs up the previous installation before deploying the new version.
./install-smartmeter.shTip
After an update, check that the service is running correctly:
sudo systemctl status smartmeter-server
sudo journalctl -u smartmeter-server -fOnce installed, the server runs as a systemd service:
# Check service status
sudo systemctl status smartmeter-server
# Stop the service
sudo systemctl stop smartmeter-server
# Start the service
sudo systemctl start smartmeter-server
# View logs
sudo journalctl -u smartmeter-server -f| Path | Description |
|---|---|
/opt/smartmetersrv |
Application directory |
/opt/smartmetersrv.bak |
Backup of the previous installation |
The server reads its configuration at startup. Key options include:
| Option | Default | Description |
|---|---|---|
PortName |
/dev/ttyUSB0 |
Serial port device path for the optical coupler |
MqttServer |
-- | URI of the MQTT broker |
MqttClientName |
SmartMeterClient |
MQTT client identifier |
MqttTopicTemplate |
smartmeter/values/{0} |
Topic template ({0} is replaced by the value type) |
The server publishes the following meter values:
| Value | Description |
|---|---|
TotalPurchasedEnergy |
Cumulative energy purchased from the grid |
TotalSoldEnergy |
Cumulative energy sold to the grid |
CurrentPurchasingPower |
Current power being drawn |
CurrentSellingPower |
Current power being fed in |
GridPowerBalance |
Net power balance |