Skip to content

Commit

Permalink
feat(version): Add version information to binary and apply GPLv3
Browse files Browse the repository at this point in the history
  • Loading branch information
heubeck committed Dec 5, 2022
1 parent 3ac117e commit fe865ea
Show file tree
Hide file tree
Showing 11 changed files with 888 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
FROM golang:1.19

# Injected from the build
ARG VERSION

RUN apt-get update && apt-get install uuid-dev uuid-runtime

# make it
WORKDIR /build
COPY . .
RUN make

# Try it
RUN ./samler
18 changes: 8 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ jobs:
with:
submodules: 'true'

# - name: Application Build and Test
# run: |
# sudo apt-get install -y uuid-dev uuid-runtime
# make
# ls -lah

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

Expand All @@ -40,18 +34,22 @@ jobs:
- name: Build AMD64 binary
uses: docker/build-push-action@v3
with:
file: .github/workflows/Dockerfile
tags: result:amd64
platforms: linux/amd64
file: .github/workflows/Dockerfile
build-args: |
VERSION=${{ steps.semantic.outputs.new_release_version }}
load: true
push: false

- name: Build ARM v7 binary
uses: docker/build-push-action@v3
with:
file: .github/workflows/Dockerfile
tags: result:arm-v7
platforms: linux/arm/v7
file: .github/workflows/Dockerfile
build-args: |
VERSION=${{ steps.semantic.outputs.new_release_version }}
load: true
push: false

Expand All @@ -72,7 +70,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Release
- name: Add artifacts to release
uses: softprops/action-gh-release@v1
if: github.ref == 'refs/heads/main' && steps.semantic.outputs.new_release_version != null
with:
Expand Down
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
# SaMLer - Smart Meter data colletor at the edge
# Copyright (C) 2022 Florian Heubeck
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

all: samler

libsml:
make -C libsml/sml
make -C libsml/examples

samler: libsml
go build
go build -ldflags "-X main.Version=$$VERSION"
go test

.PHONY: clean libsml
Expand Down
68 changes: 67 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,76 @@
# SaMLer

The SaMLer is reading SML messages from a serial device and publishes it to InfluxDB.
The SaMLer is reading SML messages produced by a smart meter from a serial device and publishes it to InfluxDB.

## Dependencies

It uses [libsml](https://github.com/volkszaehler/libsml) for the low level device and protocol handling, and has filesystem caching using [diskqueue](https://github.com/nsqio/go-diskqueue) to overcome (temporary) network issues.
Credits to these projects!

## Use

The dependency `libuuid` has to be installed on the target system, on Debian based systems availabe from package `uuid-runtime`.

There are pre-build binaries available with every [release](https://github.com/heubeck/samler/releases).

SaMLer is configured using environment variables, just run it, to let it print its options:

```shell
> ./samler.amd64
SaMLer; configure via ENV:
SAMLER_INFLUX_TOKEN (default: )
SAMLER_INFLUX_ORG (default: )
SAMLER_INFLUX_MEASUREMENT (default: power)
SAMLER_CACHE_PATH (default: /home/heubeck/.samler)
SAMLER_DEVICE_BAUD_RATE (default: 9600)
SAMLER_DEVICE_MODE (default: 8-N-1)
SAMLER_DEBUG (default: false)
SAMLER_INFLUX_URL (default: )
SAMLER_INFLUX_BUCKET (default: home)
SAMLER_DEVICE (default: /dev/ttyUSB0)
```

A minimalistic run script using [Influx Cloud](https://cloud2.influxdata.com/) may look like:

```shell
#!/bin/bash

export SAMLER_INFLUX_URL=https://region.provider.cloud2.influxdata.com
export SAMLER_INFLUX_TOKEN=thisIsVerySecret==
export [email protected]

/opt/samler.arm-v7
```

Using systemd a service description may look like:

```shell
> cat /etc/systemd/system/samler.service
[Unit]
Description=SaMLer SmartMeter Data collector
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=10
User=root
ExecStart=/opt/run_samler.sh

[Install]
WantedBy=multi-user.target
```

## Known restrictions & TODO

* By now, there's only a single serial mode supported what's reflected in the configuration defaults:
_Baud rate `9600` and mode `8-N-1` (8 data bits, 1 stop bit, none parity)_
That needs to be generalized.
* Smart Meter data is properitary to electric power meter, as that's the only one I have running SaMLer right now.
Please file [issues](https://github.com/heubeck/samler/issues) with devices you'd like to read.
* Timing values are hard coded and should made configurable on demand.
* My C and Go skills are only rudimentary, don't hesitate to point out improvements.
* The only supported backend is InfluxDB by now, but it's prepared to support more in the future, just file an [issues](https://github.com/heubeck/samler/issues).

## Contribution

Yes, please. Looking forward to your ideas.
26 changes: 25 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
SaMLer - Smart Meter data colletor at the edge
Copyright (C) 2022 Florian Heubeck
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package main

/*
Expand All @@ -22,6 +39,12 @@ import (
diskqueue "github.com/nsqio/go-diskqueue"
)

var Version string
var notice = fmt.Sprintf(`SaMLer v%s Copyright (C) 2022 Florian Heubeck
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions.
`, Version)

var debugFlag bool
var _messages = make(chan Measurement, 5000)

Expand Down Expand Up @@ -99,14 +122,15 @@ func readConfig() map[string]string {
}

func printHelpAndExit() {
fmt.Println("SaMLer; configure via ENV:")
fmt.Println("# Configuration options, set them as ENV:")
for key, dev := range configOptions {
fmt.Printf("%s (default: %s)\n", key, dev)
}
os.Exit(0)
}

func main() {
fmt.Println(notice)
config := readConfig()

if flag, err := strconv.ParseBool(config[Debug]); err == nil {
Expand Down
17 changes: 17 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
SaMLer - Smart Meter data colletor at the edge
Copyright (C) 2022 Florian Heubeck
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package main

import (
Expand Down
21 changes: 21 additions & 0 deletions samler.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
SaMLer - Smart Meter data colletor at the edge
Copyright (C) 2022 Florian Heubeck
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
Expand All @@ -18,6 +35,10 @@
#include "libsml/examples/unit.h"
#include "samler.h"

/*
* Most of the following is taken from the libsml examples, many thanks to the volkszaehler project.
*/

// Registered callback
SmlEvent event;

Expand Down
17 changes: 17 additions & 0 deletions samler.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
SaMLer - Smart Meter data colletor at the edge
Copyright (C) 2022 Florian Heubeck
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package main

import (
Expand Down
17 changes: 17 additions & 0 deletions samler.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
SaMLer - Smart Meter data colletor at the edge
Copyright (C) 2022 Florian Heubeck
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef SML_CGO_H_
#define SML_CGO_H_

Expand Down
17 changes: 17 additions & 0 deletions samler_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
SaMLer - Smart Meter data colletor at the edge
Copyright (C) 2022 Florian Heubeck
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package main

import (
Expand Down

0 comments on commit fe865ea

Please sign in to comment.