Compare commits

...

109 Commits
0.0.26 ... main

Author SHA1 Message Date
61509c0000 queries
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-10 15:40:37 +01:00
3c09c04066 rename snmp handler to prepared handler, 4
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-10 14:07:25 +01:00
af739c7148 rename snmp handler to prepared handler, 3
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-10 14:03:22 +01:00
33ff176c79 rename snmp handler to prepared handler, 2
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-10 14:01:50 +01:00
134e3706cc rename snmp handler to prepared handler
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-10 13:58:01 +01:00
3a56309b9f tsm
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-10 13:11:31 +01:00
084645f002
update of go modules
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-04 16:34:49 +01:00
9815371199
filter for build step
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-04 16:25:03 +01:00
4debe45592
fix new ci, 7
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-04 16:04:59 +01:00
71773968c9
fix new ci, 6
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-04 16:02:52 +01:00
574e2886f5
fix new ci, 5
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-04 15:42:02 +01:00
e25693fb84
fix new ci, 4
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-04 15:11:49 +01:00
ff49d285dc
fix new ci, 3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-04 15:10:14 +01:00
8c3977162b
fix new ci, 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-04 15:07:31 +01:00
b99b47ca40
fix new ci, 1
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-04 15:05:53 +01:00
c40805b4cb
change Dockerfile, introduce separate build step
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-04 15:01:49 +01:00
a2eb38b414
sbon, 6
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-03 17:30:05 +01:00
64cf45e22f
sbon, 5
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-03 17:27:19 +01:00
9310a86687
sbon, 4
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-03 17:24:07 +01:00
f4b404e2b1
sbon, 3
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-03 17:20:18 +01:00
29148a13f4
sbon, 2
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-03 17:18:44 +01:00
0356e9dcee
sbon
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-03 17:14:11 +01:00
a5b981357d
enable license scanning, 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-03 16:51:16 +01:00
57bbc6135e
enable license scanning
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-03 16:43:46 +01:00
d704f7ba5e
python module updated too
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-03 14:38:14 +01:00
d0567a48f1
update modules
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-03 14:35:44 +01:00
ee22996433
sbom in ci, 3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-03 14:26:07 +01:00
4130befdbf
sbom in ci, 2
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-03 14:23:45 +01:00
77c5df0697
sbom in ci 2025-02-03 14:21:41 +01:00
d4ee4c49de
new database
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-01-09 16:18:53 +01:00
ae938d10b9 debug
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-01-09 14:53:12 +01:00
799ef9e00b Merge branch 'main' of gitea.hottis.de:wn/universal-data-ingest
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-01-09 14:49:24 +01:00
311e732841 debug 2025-01-09 14:49:15 +01:00
51e482e94e
fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-12-13 10:27:02 +01:00
a1b98d3438
more debugging
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-12-13 10:02:32 +01:00
166c414af1
more debugging for database issue
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-12-12 23:23:32 +01:00
cedb1dfa5a
more debugging for database issue
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-12-12 23:21:09 +01:00
a21fae4f8a
view
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-12-04 13:17:06 +01:00
1b6ac5d762
gy21, fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-12-04 12:52:03 +01:00
95831d5e47
gy21
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-12-04 12:49:49 +01:00
c3dce9faab
disable debugging code
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-11-15 11:26:26 +01:00
c332373691
disable debugging code
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/tag/woodpecker Pipeline failed
2024-11-15 11:24:26 +01:00
418b44289d
disable debugging code
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/tag/woodpecker Pipeline failed
2024-11-15 11:22:35 +01:00
23962cdebc
new model
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-11-15 11:11:35 +01:00
b9e639e0a2
additional model
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-11-15 10:52:29 +01:00
1870089942
queries
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-11-11 20:02:12 +01:00
f8bcfe4d25
fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-11-11 18:00:13 +01:00
aa3f784a41
mi sensor 2024-11-11 17:59:23 +01:00
57c635b1e0
drop scan
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-11-11 17:20:38 +01:00
c5150b1b4f
configuration 2024-11-11 17:20:13 +01:00
abc0ad0825
some more attributes
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-11-11 17:19:04 +01:00
b6a7447cb3
fix
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-11-11 16:13:04 +01:00
58d86101f3
Merge branch 'main' of gitea.hottis.de:wn/universal-data-ingest 2024-11-11 16:11:47 +01:00
81e067e672
seems to work now 2024-11-11 16:11:32 +01:00
45e4cd793b
static parse function 2024-11-11 15:00:04 +01:00
830596f211
saerbeck query 2024-11-11 12:45:47 +01:00
a55f80b7d9
saerbeck query
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-11-11 12:44:02 +01:00
3d68aa0e61
prepare changes
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-11-11 12:43:29 +01:00
f2f16c811a
still sensor labels
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 16:50:54 +02:00
6f9327fdd6
sensor labels
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 16:36:17 +02:00
1d1942a4d3
sensor labels 2024-07-31 16:26:51 +02:00
d6e7fa3949
sensor labels
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 16:22:39 +02:00
97c6a045d2
sensor labels
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 16:14:29 +02:00
f10f9afd8b
sensor labels
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-07-31 16:10:52 +02:00
64f74c60f3
battery
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 15:29:54 +02:00
79d6422379
new query and some updates
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-12 15:42:38 +02:00
532e12a9a6
increase some more module version according to trivy results
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-07-12 14:22:37 +02:00
a5856f08ab
increase some module version according to trivy results
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-07-12 12:52:57 +02:00
d970151aca
new builder image
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-07-12 12:03:35 +02:00
72757b5ae7
add hottis threeway thermometer
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-07-12 11:16:37 +02:00
7a350e0bc7
co2_v adjusted
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-16 17:19:46 +01:00
1dbe656681
brightness in hottisScd30
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-02-16 10:34:23 +01:00
b5f0c0d86f
fix lsn50 data format
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-02-09 14:13:27 +01:00
17b2b362a0
fix in error output
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-02-09 14:05:14 +01:00
c1a8a0b8f2
add decoder for lsn50 3-way, fix 1
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-02-09 13:40:21 +01:00
8dbef7c647
add decoder for lsn50 3-way
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-09 13:38:55 +01:00
42b307ff7b
fix image name in deploy script
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-02-07 22:46:35 +01:00
943516f1ac
upgrade some modules due to vulnerabilities
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-02-07 22:41:01 +01:00
1a8e76dc32
add trivy in pipeline
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-07 22:35:15 +01:00
3e4c621645
test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-30 16:54:50 +01:00
c8e60df30b
test 2024-01-30 16:33:09 +01:00
664a2831ab
test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-30 16:28:49 +01:00
00524c0a3f
label in snmp measurements
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-26 14:44:23 +01:00
3af9482880
fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-25 15:27:33 +01:00
df353d4f6c
skip diff value
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/tag/woodpecker Pipeline failed
2024-01-25 15:24:11 +01:00
d1bbbeaccf
snmp
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-25 15:13:36 +01:00
8cfc92c226
some more views
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-15 11:12:23 +01:00
08e81e309c
locative handler, config adjusted
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-15 10:16:58 +01:00
f44664eaad
locative handler
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-15 10:10:51 +01:00
15458b9955
hottisScd30
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-07 18:48:47 +01:00
f55990cc57
hottisScd30
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-07 18:23:22 +01:00
766355f85d
hottisScd30
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-07 18:14:59 +01:00
73aaa2225d
hottisScd30
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-07 17:28:32 +01:00
44b7461d19
fix migrate pv
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-04 22:22:19 +01:00
c54b335e5f
queries and migrations
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-03 20:57:26 +01:00
956d1bdcdb
fix status in migration
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-12-28 15:56:30 +01:00
b938d48c7f
add status in ttn handlers
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-12-28 15:48:51 +01:00
b374b7f49d
some queries
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-12-28 13:04:25 +01:00
879825a260
format paylaod
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-12-27 14:21:21 +01:00
b6132afb11
disable logging in ttn
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-12-27 12:14:05 +01:00
5e94782575
add RawPayloadPrinter
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-12-27 12:06:50 +01:00
57c63adeb2
handover FrmPayload to model parsers too 2023-12-27 12:00:02 +01:00
e209598f9e
secrets
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-12-24 15:57:53 +01:00
03f8f9fade
fix in deploy script
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-12-24 14:41:49 +01:00
fc91a0da2e
change db password approach
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-12-24 14:28:46 +01:00
7d8d8b1c6a
soil hottis
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-12-24 11:05:37 +01:00
ffbda52c36
migration stuff
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-12-23 22:57:27 +01:00
647a2d36e5
saerbeck
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-12-23 21:57:43 +01:00
a8db62ea52
LSE01
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-12-22 17:28:32 +01:00
51 changed files with 1252 additions and 275 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
src/udi/udi
src/udi/main
src/udi/migrate_schema
tmp/
ENVDB

View File

@ -1,8 +1,55 @@
steps:
build:
image: golang:1.22.5-alpine3.20
commands:
- GOPATH=/woodpecker/go
- cd src/udi
- go mod tidy
- go build -a -installsuffix nocgo -o udi main.go
- cp udi ../..
when:
- event: [push, tag]
scan:
image: quay.io/wollud1969/woodpecker-helper:0.5.1
environment:
TRIVY_TOKEN:
from_secret: trivy_token
TRIVY_URL:
from_secret: trivy_url
DTRACK_API_KEY:
from_secret: dtrack_api_key
DTRACK_API_URL:
from_secret: dtrack_api_url
commands:
- export GOPATH=/woodpecker/go # the export is required, otherwise trivy will not consider the variable
- HOME=/home/`id -nu`
- TAG="${CI_COMMIT_TAG:-$CI_COMMIT_SHA}"
- |
trivy fs \
--server $TRIVY_URL \
--token $TRIVY_TOKEN \
--format cyclonedx \
--scanners license \
--output /tmp/sbom.xml \
.
- cat /tmp/sbom.xml
- |
curl -X "POST" \
-H "Content-Type: multipart/form-data" \
-H "X-Api-Key: $DTRACK_API_KEY" \
-F "autoCreate=true" \
-F "projectName=$CI_REPO" \
-F "projectVersion=$TAG" \
-F "bom=@/tmp/sbom.xml"\
"$DTRACK_API_URL/api/v1/bom"
when:
- event: [push, tag]
dockerize:
image: plugins/kaniko
settings:
repo: gitea.hottis.de/wn/udi
repo: ${FORGE_NAME}/${CI_REPO}
registry:
from_secret: container_registry
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
@ -15,14 +62,14 @@ steps:
- event: [push, tag]
deploy:
image: portainer/kubectl-shell:latest
secrets:
- source: kube_config
target: KUBE_CONFIG_CONTENT
- source: encryption_key
target: ENCRYPTION_KEY
- source: secrets_checksum
target: MD5_CHECKSUM
image: quay.io/wollud1969/woodpecker-helper:0.5.1
environment:
KUBE_CONFIG_CONTENT:
from_secret: kube_config
ENCRYPTION_KEY:
from_secret: encryption_key
MD5_CHECKSUM:
from_secret: secrets_checksum
commands:
- export IMAGE_TAG=$CI_COMMIT_TAG
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig

View File

@ -1,16 +1,8 @@
FROM golang:1.21-alpine as builder
RUN mkdir -p /go/src
COPY ./src/ /go/src
WORKDIR /go/src/udi
RUN go build -a -installsuffix nocgo -o udi main.go
FROM scratch
ENV UDI_CONF ""
COPY --from=builder /go/src/udi ./
COPY udi ./
ENTRYPOINT ["./udi"]

View File

@ -10,6 +10,7 @@ if [ "$MD5_CHECKSUM" = "" ]; then
exit 1
fi
SECRETS_CIPHERTEXT_FILE=secrets.enc
SECRETS_PLAINTEXT_FILE=/tmp/secrets
TMP_FILE=`mktemp`

View File

@ -6,7 +6,7 @@ if [ "$IMAGE_TAG" == "" ]; then
fi
IMAGE_NAME=gitea.hottis.de/wn/udi
IMAGE_NAME=$FORGE_NAME/$CI_REPO
CONFIG_FILE=config.json
@ -35,9 +35,12 @@ for NAMESPACE_DIR in `find $INSTANCES_DIR -type d -mindepth 1 -maxdepth 1`; do
INSTANCE=`basename $INSTANCE_DIR`
echo "Instance: $INSTANCE"
# set secret configuration from encrypted and decrypted file
VARIABLE_PREFIX=`echo "$NAMESPACE""_""$INSTANCE" | tr - _`
# set MQTT_PASSWORD as secret
MQTT_PASSWORD_VARIABLE="$NAMESPACE""_""$INSTANCE""_MQTT_PASSWORD"
MQTT_PASSWORD_VARIABLE=`echo $MQTT_PASSWORD_VARIABLE | tr - _`
MQTT_PASSWORD_VARIABLE=$VARIABLE_PREFIX"_MQTT_PASSWORD"
MQTT_PASSWORD="${!MQTT_PASSWORD_VARIABLE}"
# echo "MQTT_PASSWORD_VARIABLE: $MQTT_PASSWORD_VARIABLE"
# echo "MQTT_PASSWORD: $MQTT_PASSWORD"
@ -48,24 +51,14 @@ for NAMESPACE_DIR in `find $INSTANCES_DIR -type d -mindepth 1 -maxdepth 1`; do
--save-config | \
kubectl apply -f - -n $NAMESPACE
# set database configuration as secret
## prepare configuration to access database to set udi database password
PGUSER=`kubectl get secret -n database timescaledb -o jsonpath="{.data.superuser-username}" | base64 -d`
PGHOST=`kubectl get services traefik -n system -o jsonpath="{.status.loadBalancer.ingress[0].ip}"`
PGPASSWORD=`kubectl get secret -n database timescaledb -o jsonpath="{.data.superuser-password}" | base64 -d`
PGSSLMODE=require
NEW_UDI_DB_LOGIN="udi""-""$NAMESPACE""-""$INSTANCE"
NEW_UDI_DB_PASSWORD=`tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 32`
NEW_UDI_DB_DATABASE="udi""-""$NAMESPACE""-""$INSTANCE"
NEW_UDI_DB_HOST=timescaledb.database.svc.cluster.local
DATABASE_MASTER_POD=`kubectl get pods -n database -l app=StackGresCluster -l role=master -o jsonpath='{.items[0].metadata.name}'`
kubectl exec -i $DATABASE_MASTER_POD -c postgres-util -n database -- psql <<EOF
BEGIN;
ALTER USER "$NEW_UDI_DB_LOGIN" WITH PASSWORD '$NEW_UDI_DB_PASSWORD';
COMMIT;
EOF
LOGIN_VARIABLE=$VARIABLE_PREFIX"_PGUSER"
NEW_UDI_DB_LOGIN="${!LOGIN_VARIABLE}"
PASSWORD_VARIABLE=$VARIABLE_PREFIX"_PGPASSWORD"
NEW_UDI_DB_PASSWORD="${!PASSWORD_VARIABLE}"
DATABASE_VARIABLE=$VARIABLE_PREFIX"_PGDATABASE"
NEW_UDI_DB_DATABASE="${!DATABASE_VARIABLE}"
NEW_UDI_DB_HOST=database.database1.svc.cluster.local
kubectl create secret generic $INSTANCE-udi-db-cred \
--dry-run=client \

View File

@ -1,9 +1,7 @@
#!/bin/bash
if [ "$ENCRYPTION_KEY" = "" ]; then
echo "ENCRYPTION_KEY not set"
exit 1
fi
ENCRYPTION_KEY=`openssl rand -hex 32`
echo $ENCRYPTION_KEY
SECRETS_PLAINTEXT_FILE=secrets.txt
SECRETS_CIPHERTEXT_FILE=secrets.enc

View File

@ -1,17 +1,16 @@
{
"mqtt": {
"broker": "ssl://eu1.cloud.thethings.network:8883",
"username": "com-passavant-geiger-poc@ttn",
"username": "de-hottis-saerbeck-monitoring@ttn",
"password": "ENV",
"tlsEnable": "true"
},
"topicMappings": [
{
"topics": [ "v3/com-passavant-geiger-poc@ttn/devices/#" ],
"topics": [ "v3/#" ],
"handler": "TTN",
"id": "TTN0",
"config": {
"databaseConnStr": "",
"attributes": {
}
}

View File

@ -11,13 +11,12 @@
"handler": "TTN",
"id": "TTN0",
"config": {
"databaseConnStr": "",
"attributes": {
}
}
}
],
"archiver": {
"dir": "./tmp/udi"
"dir": "/archive"
}
}

View File

@ -1,23 +1,22 @@
{
"mqtt": {
"broker": "ssl://eu1.cloud.thethings.network:8883",
"username": "com-passavant-geiger-poc@ttn",
"username": "de-hottis-lora-test1@ttn",
"password": "ENV",
"tlsEnable": "true"
},
"topicMappings": [
{
"topics": [ "v3/com-passavant-geiger-poc@ttn/devices/#" ],
"topics": [ "v3/#" ],
"handler": "TTN",
"id": "TTN0",
"config": {
"databaseConnStr": "",
"attributes": {
}
}
}
],
"archiver": {
"dir": "./tmp/udi"
"dir": "/archive"
}
}

View File

@ -4,6 +4,24 @@
"tlsEnable": "false"
},
"topicMappings": [
{
"topics": [ "snmp" ],
"handler": "PREP",
"id": "SNMP",
"config": {
"attributes": {
}
}
},
{
"topics": [ "tsm" ],
"handler": "PREP",
"id": "TSM",
"config": {
"attributes": {
}
}
},
{
"topics": [ "dt1/ai/periodic/1" ],
"handler": "DT1T",
@ -44,6 +62,16 @@
}
}
},
{
"topics": [ "locative/event/#" ],
"handler": "Locative",
"id": "Locative",
"config": {
"databaseConnStr": "",
"attributes": {
}
}
},
{
"topics": [ "IoT/MBGW3/Measurement" ],
"handler": "MBGW3",
@ -100,6 +128,16 @@
}
}
},
{
"topics": [ "zigbee2mqtt/+" ],
"handler": "Z2M",
"id": "Z2M",
"config": {
"databaseConnStr": "",
"attributes": {
}
}
},
{
"topics": [ "shellyplusht/+/status/temperature:0" ],
"handler": "SVEJ",

View File

@ -0,0 +1,22 @@
{
"mqtt": {
"broker": "ssl://eu1.cloud.thethings.network:8883",
"username": "de-hottis-app01@ttn",
"password": "ENV",
"tlsEnable": "true"
},
"topicMappings": [
{
"topics": [ "v3/#" ],
"handler": "TTN",
"id": "TTN0",
"config": {
"attributes": {
}
}
}
],
"archiver": {
"dir": "/archive"
}
}

View File

@ -1,7 +1,38 @@
U2FsdGVkX1+jsPd67Sl8bXkH/OVKx3clFUnpJBzwRXA9qEhyDrwMJWg3UH6eiCZd
PIwApBbDKxR0W/NotaE9100gQo+L3tHL0elMo/YOFkiwkM3tJ1v3zngY1BUoEAGJ
4aZNVC7Eb9HDG0RKqh7fSPuazeKxd1fih9nQuxy//XgRivqjbgqfD/xLi5NZ/n0F
nJT1MsBKGmYF4ezC7thSYIN/+GDL6gpty/FYxAi56oFy6q2YGuADXPgRs1v22vz3
KP+9mIeg6VZn6IRv00w0HSJ3UghMMx/b3pDjIVrq9I3x9sXDD1YqYbjjcnopqKsl
+gVrX/jCsDBmArRXFu1innOJ+pOsHJ3sSR5fRugnn0Fgje63n4mN46eJYdwhHgEr
yIuyMipc0Uc1ZOsEpkrmYnEofgGaWC3IrdsVEwybbGQ=
U2FsdGVkX1+v6L4gc+CbYCZyo/UVN7QfmEntIBpk+GAHGf3d7m/4hfcYd39Eh2td
lXSmNdt1cdFw/UfZ1x1OlGm/fqLh/j/rWPgEc6BwEcDFDEXpTucTjUHNDonYNH8j
eDWeAGokfguqgQG16CBLHdeyocP0kTPJSrIKQgG1Mzzck/kfB1Z6Ggv4z5KEx2dy
2rrnm+BeFT1yITwoxa3iJeudcSQznNIqQa+Mx4fUsPV+yorahp4gs0PVVj9POnAT
yRhpQgkaq5oZNVcYrWS5+6mmhbzL5jIAa4wfzVep/69RcfBkV5Oj5JJGaQzH0T74
wg8dWz/scdi2kkCn0KroJPrsG/lAsFYhbX4kUJQeRUX1pWr/iwD0i8LRx+f2C82Y
HgpsnG6c5nPRy68TltgRgCRAIJj87rR/fATVowcpChfe9sXCwfLEZ5Q2hDK8eAPW
VS87axMkProyHJZe1GK0v9CAVWpXlxv6eAr8u2SftGA87Xu3ebQ4SjReXIcAb7M6
08UnxW4YcfH+usgU2GUuNlzRctAq334AfBWYQO51l/ELJAzaDi6Ht4Czr6R7Bsfh
M3ZcjcgqY7j7ywDFmKq/a8Q0Dsjm2sezNtrrRWusomgSKFEf8WncOdkcWOAiza4T
+Qubfr1SuZuWFF+migGtYM3X8YS+VpmMRIpJ1otibMELgjvldWGqHIK1uIThLq7F
MvQ0Nog6UNg79/8vrUoEUPPB5fQsXcNC5zcpVMrpJcGogBHhsXk1EPFcB75sx/65
bl2BZlCBacH9MNIBPh17dMC46EV1FNaLiO1N3/qJkxrkiG5wBDjDlnyMn/mYc/o1
olNuIO0nnn2x8ZU02lRo8RqcqOywseZeBhAzOj+899n5Qa/0YQAnb0Y9WAxqLft/
0C45HcK5Kgd3C6wqvVUqcQ/UMxQzv0y1cM8gbfpGjUvJ6gUj7vkW08D55A6gV8Lf
SrneWAP/1B1mmV16vHaXwoYpTpQwM7i7fHWBOpH7nq6E+0P3LHyon43dYo4P6KM7
He3R6phTFp36WI4ZCUQafTDZS196Ol2ZyEAonVwSOIEIyptXeoAmleolXC/eL84Z
bEbhld8g+ulrVSrBXFpCY3jBsqPVBYEpZaGYgevsrHPSbwWa/qQkTKnOO4+oz6Pe
9iJ1yJbSWfg6Gkr6iqE41Dp4VGXtwTDHHb9YMd56iWHAkxZLFIWdYUr8XfQS6j70
j5kV3jV/w5EHGYruBdtxAWc7YKq3pfqvh9R7dD/8JOFZhA140+zmOCWG4qdDhv+5
F9vlawudssa9ZHGi1jBFPCNW13LBhUdyCY3apKF4HHeeuA465uzxIqwtkJSigdun
vC9ooYZrJjYOnJSTJnKH0WSD0pPC6CIkge+Fxuksq6cst5Zcysw1xz5zs7UNeAP+
kLs1+8Kn2d1hJuzSWdWlj7xGratLEdA6pqcfBKvMYtY0kpPPDrxm+F1FZ7LyV+dc
G1vfI6aS2azrFrBNXSeOArJ/erGHIGhWxFY0c3bcGOjXwsLWRjQ03Kdj9ffj6UFL
4JJaI0I01RilAo+woaZhNmOHl1VxSsU1lDGF7IvW3t0qKLaSg/Rv3pQqdKyjq8I5
IxPlUEMdo1EDZZx4qLmYBM1tWhgMbn4nx6P2BS7obnPdaf3B0RPxI68Z49RYZKvR
/wTyr7oWCCRQDwCuVH8t/jUrSWspzEK7ApXHdh7T9JlNurFW7oxc8ylooQrAn3Gn
mru7X3cUeVtiosAklZ7w+JNxm44IRmDKNVDeAaat+q35EA8MRFGiuXEOeNw54tWH
zNkUyUJ79Ie7BkGrZFUFqkvfY3Q/xLaBGYDQe65S8/rerybL0YI7RmMiz4x7yq8L
GoIDwPsn0z/AFefoGTi0tAXZeC+EA62okK1kKR9qrh9gmD59uiMbFX1BHe3rWhgP
cCPScYeameXV3K6wwQpX8JTdptqMAH5cpEVoUZ/PZZpkaiCuWcMODVbqTpm4SRPt
Q9s5+6/g0TUUqz7Fwi0dlfnMZVuK0a1Uf/SBYR7f/UYVLfF5juTZ+IRJwQWwp6QX
CzfYms0W34/srtM72mQOpKTd0o3xuFyVbQtZPOpNghIjArQqwt34nEzXPYHqasDx
c/yIPdW+B/YVcFPdRV16Izqmjdlupv6pPjY/T6GdHczQsH9gD28HN9+Ka2Cvficf
evO7IXe0RuvodQ3tB4LmeWoJB10G7Sko2EEfpFTDXke9Ak/5cGrpdPMtbXCAIm1o
B5UhrqNuUYSWdo0mGttbSjFR7pyLujsxLNnp8teBi33QOUhrSId5+mOvtFDGiZKa
QCC+W+BIh6IFIwnxH4dDxjz3M65NXzqNV+6mXEFU77cX+oTF4BRe0R/L4nPoaBAN
smRxtqBItpVFUdsOVb6bXg==

8
queries/berresheim.sql Normal file
View File

@ -0,0 +1,8 @@
create or replace view level_v as
select time,
cast(values->'CorrectedDistance'->>'value' as float) as level,
cast(values->'Battery'->>'value' as float) as battery,
attributes->>'Status' as status,
device
from measurements
where application = 'de-hottis-level-monitoring';

View File

@ -43,5 +43,106 @@ create or replace view temperature_v as
cast(values->'Value'->>'value' as float) as temperature,
device
from measurements
where application in ('Temperature Multisensor', 'Temperature Shelly Plus HT');
where application in ('Temperature Multisensor', 'Temperature Shelly Plus HT')
union
select time,
cast(values->'Temperature'->>'value' as float) as temperature,
device
from measurements
where application = 'Zigbee2MQTT Hottis Eupenstr.' and
attributes->>'DeviceModel' in ('WSDCGQ11LM', 'WSDCGQ01LM');
create or replace view voltage_v as
select time,
cast(values->'Voltage'->>'value' as float) / 1000 as voltage,
device
from measurements
where application = 'Zigbee2MQTT Hottis Eupenstr.' and
attributes->>'DeviceModel' in ('WSDCGQ11LM', 'WSDCGQ01LM');
create or replace view temperature2_v as
select time,
cast(values->'Value'->>'value' as float) as temperature,
device
from measurements
where application = 'Temperature Wago';
create or replace view humidity_v as
select time,
cast(values->'Value'->>'value' as float) as humidity,
device
from measurements
where application in ('Humidity Multisensor')
union
select time,
cast(values->'Humidity'->>'value' as float) as temperature,
device
from measurements
where application = 'Zigbee2MQTT Hottis Eupenstr.' and
attributes->>'DeviceModel' in ('WSDCGQ11LM', 'WSDCGQ01LM');
create or replace view soil_v as
select time,
cast(values->'Water'->>'value' as float) as water,
cast(values->'Conductance'->>'value' as float) as conductance,
cast(values->'Temperature'->>'value' as float) as temperature,
device
from measurements
where application = 'de-hottis-app01' and attributes->>'DeviceType' = 'dragino-lse01';
create or replace view co2_v as
select time,
cast(m.values->'CO2concentration'->>'value' as float) as co2concentration,
cast(m.values->'Humidity'->>'value' as float) as humidity,
cast(m.values->'Temperature'->>'value' as float) as temperature,
cast(m.values->'Brightness'->>'value' as int) as brightness,
m.device as device,
d.attributes->>'Label' as label
from measurements m, devices d
where m.application = 'de-hottis-app01' and
m.attributes->>'DeviceType' = 'hottis-scd30' and
m.device = d.label;
create or replace view locative_v as
select time,
device as person,
values->'Location'->>'value' as location,
values->'Trigger'->>'value' as direction
from measurements
where application = 'Locative';
create or replace view router_v as
select time,
device,
cast(values->'wan-in'->>'value' as int) as wanInOctetsPerSeconds,
cast(values->'wan-out'->>'value' as int) as wanOutOctetsPerSeconds
from measurements
where application = 'SNMP' and device = '172.16.3.1';
create or replace view lora_sht21_v as
select time,
cast(values->'Humidity'->>'value' as float) as humidity,
cast(values->'Temperature'->>'value' as float) as temperature,
m.device as device,
d.attributes->>'Label' as label
from measurements m, devices d
where m.application = 'de-hottis-app01' and
m.attributes->>'DeviceType' = 'hottis-gy21' and
m.device = d.label;
create or replace view ntp_server_snmp_v as
select time,
device,
cast(values->'load1'->>'value' as float) as laLoad1,
cast(values->'lan-in'->>'value' as int) as lanInOctetsPerSeconds,
cast(values->'lan-out'->>'value' as int) as lanOutOctetsPerSeconds
from measurements
where application = 'SNMP' and device = '172.16.13.10';
create or replace view ntp_server_variables_v as
select time,
device,
cast(values->'rootdisp'->>'value' as float) as rootdisp
from measurements
where application = 'TSM' and device = '172.16.13.10';

View File

@ -0,0 +1,11 @@
select
extract('day' from time)::varchar || '.' || extract('month' from time)::varchar || '.' || extract('year' from time)::varchar as day,
avg(temperature)::numeric(10,0) as temperature
from room_climate_measurement_t
where
category = 'Outdoor' and
location = 'Outdoor' and
extract('hour' from time) = 12 and
time::date = now()::date
group by day

View File

@ -0,0 +1,73 @@
-- query
with
first_day_in_year as (
select
date_trunc('day', min(time)) as day
from pv_power_measurement_t
where
time between date_trunc('year', time) and now()
),
first_value_in_year as (
select
time_bucket('1 day', time) as interval,
first(exportenergyactive, time) as energy
from pv_power_measurement_t
where
time between (select day from first_day_in_year) and (select day from first_day_in_year) + interval '1 day' and
status = 'Ok'
group by interval
),
first_day_in_month as (
select
date_trunc('day', min(time)) as day
from pv_power_measurement_t
where
time between date_trunc('month', now()) and now()
),
first_value_in_month as (
select
time_bucket('1 day', time) as interval,
first(exportenergyactive, time) as energy
from pv_power_measurement_t
where
time between (select day from first_day_in_month) and (select day from first_day_in_month) + interval '1 day' and
status = 'Ok'
group by interval
),
first_value_in_day as (
select
time_bucket('1 day', time) as interval,
first(exportenergyactive, time) as energy
from pv_power_measurement_t
where time >= date_trunc('day', now())
group by interval
),
last_value as (
select
time_bucket('1 day', time) as interval,
last(exportenergyactive, time) as energy
from pv_power_measurement_t
where
time between date_trunc('day', now()) and date_trunc('day', now()) + interval '1 day' and
status = 'Ok'
group by interval
)
select
extract(year from (select day from first_day_in_year))::text as period_value,
'Year' as period_name,
round(((select energy from last_value) - (select energy from first_value_in_year))::numeric, 2) as yield
union
select
to_char((select day from first_day_in_month), 'Month') as period_value,
'Month' as period_name,
round(((select energy from last_value) - (select energy from first_value_in_month))::numeric, 2) as yield
union
select
now()::date::text as period_value,
'Day' as period_name,
round(((select energy from last_value) - (select energy from first_value_in_day))::numeric, 2) as yield;
-- output format
-- wn@atuin:~/Workspace/go-workspace/src/universal-data-ingest [main ≡ +0 ~1 -0 !]$ mosquitto_sub -h 172.23.1.102 -v -t IoT/PV/Yields
-- IoT/PV/Yields {"Month":"1.43","Year":"285.39","Day":"0.00"}

View File

@ -3,13 +3,7 @@ create or replace view power_v as
cast(values->'ActivePowerL1'->>'value' as float) as power_l1,
cast(values->'ActivePowerL2'->>'value' as float) as power_l2,
cast(values->'ActivePowerL3'->>'value' as float) as power_l3,
device
from measurements
where application = 'com-passavant-geiger-poc' and
attributes->>'FPort' = '1';
create or replace view power_factor_v as
select time,
cast(values->'ActivePowerL123'->>'value' as float) as power_total,
cast(values->'PowerfactorL1'->>'value' as float) as factor_l1,
cast(values->'PowerfactorL2'->>'value' as float) as factor_l2,
cast(values->'PowerfactorL3'->>'value' as float) as factor_l3,

44
queries/saerbeck.sql Normal file
View File

@ -0,0 +1,44 @@
create or replace view badesee_temperature_v as
select time,
cast(values->'Temp_Red'->>'value' as float) as Temp1,
cast(values->'Temp_White'->>'value' as float) as Temp2,
cast(values->'Temp_Black'->>'value' as float) as Temp3,
cast(values->'Battery'->>'value' as float) as battery,
attributes->>'Status' as status,
device
from measurements
where application = 'de-hottis-saerbeck-monitoring' and
device = 'eui-a84041318187ec13';
create or replace view cubecell_threeway_temperature2_v as
select time,
cast(values->'Temperature2'->>'value' as float) as value,
values->'Temperature2'->>'label' as label
from measurements
where application = 'de-hottis-saerbeck-monitoring' and
device = 'eui-70b3d57ed0068fa4';
create or replace view cubecell_threeway_temperature1_v as
select time,
cast(values->'Temperature1'->>'value' as float) as value,
values->'Temperature1'->>'label' as label
from measurements
where application = 'de-hottis-saerbeck-monitoring' and
device = 'eui-70b3d57ed0068fa4';
create or replace view cubecell_threeway_temperature3_v as
select time,
cast(values->'Temperature3'->>'value' as float) as value,
values->'Temperature3'->>'label' as label
from measurements
where application = 'de-hottis-saerbeck-monitoring' and
device = 'eui-70b3d57ed0068fa4';
create or replace view cubecell_threeway_battery_v as
select time,
cast(values->'Battery'->>'value' as float) as value,
values->'Battery'->>'label' as label
from measurements
where application = 'de-hottis-saerbeck-monitoring' and
device = 'eui-70b3d57ed0068fa4';

View File

@ -2,9 +2,13 @@ if [ "$1" = "" ]; then
echo "set namespace as argument"
fi
N=$1
if [ "$2" = "" ]; then
echo "set instance as argument"
fi
I=$2
PGHOST=`kubectl get services traefik -n system -o jsonpath="{.status.loadBalancer.ingress[0].ip}"`
PGPASSWORD=`kubectl get secrets udi-db-cred -n $N -o jsonpath="{.data.PGPASSWORD}" | base64 --decode`
PGUSER=`kubectl get secrets udi-db-cred -n $N -o jsonpath="{.data.PGUSER}" | base64 --decode`
PGSSLMODE=`kubectl get secrets udi-db-cred -n $N -o jsonpath="{.data.PGSSLMODE}" | base64 --decode`
PGDATABASE=`kubectl get secrets udi-db-cred -n $N -o jsonpath="{.data.PGDATABASE}" | base64 --decode`
PGPASSWORD=`kubectl get secrets $I-udi-db-cred -n $N -o jsonpath="{.data.PGPASSWORD}" | base64 --decode`
PGUSER=`kubectl get secrets $I-udi-db-cred -n $N -o jsonpath="{.data.PGUSER}" | base64 --decode`
PGSSLMODE=`kubectl get secrets $I-udi-db-cred -n $N -o jsonpath="{.data.PGSSLMODE}" | base64 --decode`
PGDATABASE=`kubectl get secrets $I-udi-db-cred -n $N -o jsonpath="{.data.PGDATABASE}" | base64 --decode`
export PGUSER PGHOST PGPASSWORD PGSSLMODE PGDATABASE

View File

@ -1,6 +1,6 @@
PGUSER="uditest"
PGUSER="udi-hottis"
PGHOST=`kubectl get services traefik -n system -o jsonpath="{.status.loadBalancer.ingress[0].ip}"`
PGPASSWORD=`kubectl get secrets uditest-db-cred -n udi-test -o jsonpath="{.data.PGPASSWORD}" | base64 --decode`
PGPASSWORD=`kubectl get secrets default-udi-db-cred -n udi -o jsonpath="{.data.PGPASSWORD}" | base64 --decode`
PGSSLMODE=require
PGDATABASE="uditest"
export PGUSER PGHOST PGPASSWORD PGSSLMODE PGDATABASE

View File

@ -1,21 +0,0 @@
{
"mqtt": {
"broker": "mqtt://172.23.1.102:1883",
"tlsEnable": "false"
},
"topicMappings": [
{
"topics": [ "ttn/#" ],
"handler": "TTN",
"id": "TTN0",
"config": {
"databaseConnStr": "",
"attributes": {
}
}
}
],
"archiver": {
"dir": "./tmp/udi"
}
}

View File

@ -1,8 +1,7 @@
{
"mqtt": {
"broker": "ssl://eu1.cloud.thethings.network:8883",
"username": "de-hottis-level-monitoring@ttn",
"passwordEnvVar": "MQTT_PASSWORD",
"username": "de-hottis-saerbeck-monitoring@ttn",
"tlsEnable": "true"
},
"topicMappings": [
@ -11,7 +10,6 @@
"handler": "TTN",
"id": "TTN0",
"config": {
"databaseConnStr": "",
"attributes": {
}
}

View File

@ -4,72 +4,6 @@
"tlsEnable": "false"
},
"topicMappings": [
{
"topics": [ "IoT/PV/Values" ],
"handler": "PV",
"id": "PV",
"config": {
"attributes": {
}
}
},
{
"topics": [ "IoT/MBGW3/Measurement" ],
"handler": "MBGW3",
"id": "MBGW3",
"config": {
"attributes": {
}
}
},
{
"topics": [ "dt1/ai/periodic/1" ],
"handler": "DT1T",
"id": "DT1T.0",
"config": {
"attributes": {
"Application": "Temperature Wago",
"Device": "Freezer",
"HardLow": "-273",
"SoftLow": "-50",
"SoftHigh": "20",
"HardHigh": "100"
}
}
},
{
"topics": [ "dt1/ai/periodic/3" ],
"handler": "DT1T",
"id": "DT1T.1",
"config": {
"attributes": {
"Application": "Temperature Wago",
"Device": "Outdoor",
"HardLow": "-273",
"SoftLow": "-60",
"SoftHigh": "60",
"HardHigh": "100"
}
}
},
{
"topics": [ "IoT/OneWireGW/Bus 1/#" ],
"handler": "SVER",
"id": "SVER0",
"config": {
"databaseConnStr": "",
"attributes": {
"application": "Temperature Heating",
"payloadRegex": "(\\d+(\\.\\d+)?)\\s*([^0-9\\s]\\S*)",
"deviceFrom": "topic",
"devicePart": "3",
"valueFrom": "payload",
"valuePart": "1",
"unitFrom": "payload",
"unitPart": "3"
}
}
},
{
"topics": [ "NR/Multisensor/+/Temperatur" ],
"handler": "SVEJ",
@ -85,44 +19,12 @@
}
},
{
"topics": [ "NR/Multisensor/+/Feuchte" ],
"handler": "SVEJ",
"id": "SVEJ1",
"topics": [ "zigbee2mqtt/+" ],
"handler": "Z2M",
"id": "Z2M",
"config": {
"databaseConnStr": "",
"attributes": {
"application": "Humidity Multisensor",
"deviceSelector": "T:2",
"valueSelector": "J:$.CurrentRelativeHumidity",
"unitSelector": "C:%"
}
}
},
{
"topics": [ "shellyplusht/+/status/temperature:0" ],
"handler": "SVEJ",
"id": "SVEJ2",
"config": {
"databaseConnStr": "",
"attributes": {
"application": "Temperature Shelly Plus HT",
"deviceSelector": "T:1",
"valueSelector": "J:$.tC",
"unitSelector": "C:°C"
}
}
},
{
"topics": [ "shellyplusht/+/status/humidity:0" ],
"handler": "SVEJ",
"id": "SVE4",
"config": {
"databaseConnStr": "",
"attributes": {
"application": "Humidity Shelly Plus HT",
"deviceSelector": "T:1",
"valueSelector": "J:$.rh",
"unitSelector": "C:%"
}
}
}

View File

@ -1,29 +0,0 @@
{
"mqtt": {
"broker": "mqtt://172.23.1.102:1883",
"tlsEnable": "false"
},
"topicMappings": [
{
"topics": [ "v3/de-hottis-level-monitoring@ttn/devices/+/up" ],
"handler": "TTN"
}
],
"handlers": [
{
"name": "TTN",
"databaseConnStr": "",
"attributes": {
}
},
{
"name": "IoT",
"databaseConnStr": "",
"attributes": {
}
}
],
"archiver": {
"dir": "./tmp/udi"
}
}

View File

@ -9,6 +9,7 @@ type VariableType struct {
Variable string `json:"variable"`
Unit string `json:"unit"`
Value interface{} `json:"value,omitempty"`
Status string `json:"status,omitempty"`
}
type Measurement struct {

View File

@ -25,7 +25,7 @@ func NewDatabaseHandle() *DatabaseHandle {
} else {
db.dbh = conn
db.initialized = true
//log.Println("Database connection opened")
log.Println("Database connection opened")
}
return &db
}
@ -44,7 +44,7 @@ func (self *DatabaseHandle) StoreMeasurement(measurement *Measurement) {
return
}
//log.Println("Successfully stored measurement")
log.Println("Successfully stored measurement")
counter.S("Stored")
}
@ -70,5 +70,27 @@ func (self *DatabaseHandle) GetDeviceByLabelAndApplication(applicationLabel stri
return &device, nil
}
func (self *DatabaseHandle) GetDeviceByLabel(deviceLabel string) (*Device, error) {
if ! self.initialized {
err := fmt.Errorf("Database connection not initialized")
return nil, err
}
var device Device
result := self.dbh.
Preload("Application").
Preload("DeviceType").
Where("devices.label = ?", deviceLabel).
First(&device)
if result.Error != nil {
err := fmt.Errorf("Query failed: %s", result.Error)
return nil, err
}
return &device, nil
}

View File

@ -16,6 +16,9 @@ import "udi/handlers/mbgw3"
import "udi/handlers/sver"
import "udi/handlers/svej"
import "udi/handlers/dt1t"
import "udi/handlers/locative"
import "udi/handlers/prepared"
import "udi/handlers/z2m"
var handlerMap map[string]handler.Handler = make(map[string]handler.Handler)
@ -44,6 +47,12 @@ func InitDispatcher() {
factory = svej.New
case "DT1T":
factory = dt1t.New
case "Locative":
factory = locative.New
case "PREP":
factory = prepared.New
case "Z2M":
factory = z2m.New
default:
factory = nil
log.Printf("No handler %s found, ignore mapping", mapping.Handler)

View File

@ -1,24 +1,25 @@
module udi
go 1.21.3
go 1.22.3
require (
github.com/eclipse/paho.mqtt.golang v1.4.3
github.com/google/uuid v1.4.0
github.com/eclipse/paho.mqtt.golang v1.5.0
github.com/google/uuid v1.6.0
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.5
gorm.io/driver/postgres v1.5.11
gorm.io/gorm v1.25.12
)
require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.2 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/text v0.21.0 // indirect
)

View File

@ -11,8 +11,10 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@ -26,19 +28,19 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo=
gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0=
gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg=
gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=

View File

@ -38,6 +38,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
t.Id = id
t.dbh = database.NewDatabaseHandle()
log.Printf("Handler DT1T %d initialized", id)
t.ready = true
return t
}

View File

@ -36,7 +36,7 @@ func (self *CommonHandler) GetId() string {
}
func (self *CommonHandler) Lost(msg string, err error, message MessageT) {
if err != nil {
if err == nil {
log.Printf("Error: %s, message %s is lost", msg, message)
} else {
log.Printf("Error: %s (%s), message %s is lost", msg, err, message)

View File

@ -0,0 +1,74 @@
package locative
import (
"reflect"
"time"
"log"
"encoding/json"
"udi/config"
"udi/handlers/handler"
"udi/database"
)
type LocativeHandler struct {
handler.CommonHandler
dbh *database.DatabaseHandle
}
type locativeEvent struct {
Trigger string `json:"trigger"`
Device string `json:"device"`
Location string `json:"location"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
Person string `json:"person"`
Timestamp string `json:"timestamp"`
}
func New(id string, config config.HandlerConfigT) handler.Handler {
t := &LocativeHandler {
}
t.Id = id
t.dbh = database.NewDatabaseHandle()
log.Printf("Handler Locative %d initialized", id)
return t
}
func (self *LocativeHandler) Handle(message handler.MessageT) {
log.Printf("Handler Locative %d processing %s -> %s", self.Id, message.Topic, message.Payload)
var locativeEvent locativeEvent
err := json.Unmarshal([]byte(message.Payload), &locativeEvent)
if err != nil {
self.Lost("Unable to parse payload into locativeEvent struct", err, message)
return
}
variables := make(map[string]database.VariableType)
locativeEventStructValue := reflect.ValueOf(locativeEvent)
for i := 0; i < locativeEventStructValue.NumField(); i++ {
field := locativeEventStructValue.Type().Field(i)
fieldValue := locativeEventStructValue.Field(i)
v := database.VariableType {
Label: "",
Variable: field.Name,
Unit: "",
Value: fieldValue.Interface(),
}
variables[field.Name] = v
}
measurement := database.Measurement {
Time: time.Now(),
Application: "Locative",
Device: locativeEvent.Person,
Values: variables,
}
self.dbh.StoreMeasurement(&measurement)
self.S()
}

View File

@ -2,6 +2,7 @@ package mbgw3
import (
"time"
"log"
"strconv"
"encoding/json"
"udi/config"
@ -31,6 +32,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
}
t.Id = id
t.dbh = database.NewDatabaseHandle()
log.Printf("Handler MBGW3 %d initialized", id)
return t
}

View File

@ -0,0 +1,79 @@
package prepared
import (
"time"
"log"
"encoding/json"
"udi/config"
"udi/handlers/handler"
"udi/database"
)
type PreparedHandler struct {
handler.CommonHandler
dbh *database.DatabaseHandle
}
type endpoint_t struct {
Label string `json:"label"`
Variable string `json:"variable"`
Value string `json:"value"`
Unit string `json:"unit"`
Status string `json:"status"`
}
type observation_t struct {
Device string `json:"device"`
Label string `json:"label"`
Variables map[string]endpoint_t `json:"variables"`
}
func New(id string, config config.HandlerConfigT) handler.Handler {
t := &PreparedHandler {
}
t.Id = id
t.dbh = database.NewDatabaseHandle()
log.Printf("Handler Prepared %d initialized", id)
return t
}
func (self *PreparedHandler) Handle(message handler.MessageT) {
log.Printf("Handler Prepared %d processing %s -> %s", self.Id, message.Topic, message.Payload)
var observation observation_t
err := json.Unmarshal([]byte(message.Payload), &observation)
if err != nil {
self.Lost("Unable to parse payload into Observation struct", err, message)
return
}
var measurement database.Measurement
measurement.Time = time.Now()
measurement.Application = self.Id
measurement.Device = observation.Device
measurement.Attributes = map[string]interface{} {
"Label": observation.Label,
}
measurement.Values = make(map[string]database.VariableType)
for k, v := range observation.Variables {
measurement.Values[k] = database.VariableType {
Label: v.Label,
Variable: v.Variable,
Unit: v.Unit,
Value: v.Value,
Status: v.Status,
}
}
log.Printf("Prepared measurement item: %s", measurement)
self.dbh.StoreMeasurement(&measurement)
self.S()
}

View File

@ -3,6 +3,7 @@ package pv
import (
"reflect"
"time"
"log"
"encoding/json"
"udi/config"
"udi/handlers/handler"
@ -41,6 +42,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
}
t.Id = id
t.dbh = database.NewDatabaseHandle()
log.Printf("Handler PV %d initialized", id)
return t
}

View File

@ -76,19 +76,22 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
t.Id = id
t.ready = true
t.dbh = database.NewDatabaseHandle()
log.Printf("Handler SVEJ %d initialized", id)
return t
}
func extractionHelper(subTopics []string, jPayload interface{}, selector string, jp *jsonpath.Compiled) (string, error) {
func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []string, jPayload interface{}, selector string, jp *jsonpath.Compiled) (string, error) {
var res string
switch selector[:2] {
case "J:":
// extract using jsonpath from payload
r, e := jp.Lookup(jPayload)
if e != nil {
return "", fmt.Errorf("jp.Lookup failed with %s", e)
}
res = fmt.Sprint(r)
case "T:":
// T: extract from topic
i, e := strconv.Atoi(selector[2:])
if e != nil {
return "", fmt.Errorf("Atoi failed with %s", e)
@ -98,6 +101,7 @@ func extractionHelper(subTopics []string, jPayload interface{}, selector string,
}
res = subTopics[i]
case "C:":
// use constant value
res = selector[2:]
default:
return "", fmt.Errorf("Invalid selector: %s", selector[:2])
@ -111,14 +115,14 @@ func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT
self.Lost("Handler is not marked as ready", nil, message)
return
}
//log.Printf("Handler SingleValueExtractorJsonpath %d processing %s -> %s", self.Id, message.Topic, message.Payload)
log.Printf("Handler SingleValueExtractorJsonpath %d processing %s -> %s", self.Id, message.Topic, message.Payload)
var measurement database.Measurement
measurement.Time = time.Now()
measurement.Application = self.application
subTopics := strings.Split(message.Topic, "/")
//log.Printf("Subtopics: %s", strings.Join(subTopics, ", "))
log.Printf("Subtopics: %s", strings.Join(subTopics, ", "))
var jPayload interface{}
err := json.Unmarshal([]byte(message.Payload), &jPayload)
if err != nil {
@ -126,17 +130,20 @@ func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT
return
}
device, err1 := extractionHelper(subTopics, jPayload, self.deviceSelector, self.deviceJsonpath)
device, err1 := self.ExtractionHelper(subTopics, jPayload, self.deviceSelector, self.deviceJsonpath)
if err1 != nil {
self.Lost("Device extraction failed", err1, message)
return
}
value, err2 := extractionHelper(subTopics, jPayload, self.valueSelector, self.valueJsonpath)
log.Printf("device: %s", device)
value, err2 := self.ExtractionHelper(subTopics, jPayload, self.valueSelector, self.valueJsonpath)
if err2 != nil {
self.Lost("Value extraction failed", err2, message)
return
}
unit, err3 := extractionHelper(subTopics, jPayload, self.unitSelector, self.unitJsonpath)
unit, err3 := self.ExtractionHelper(subTopics, jPayload, self.unitSelector, self.unitJsonpath)
if err3 != nil {
self.Lost("Unit extraction failed", err3, message)
return
@ -152,7 +159,7 @@ func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT
measurement.Values = make(map[string]database.VariableType)
measurement.Values["Value"] = variable
//log.Printf("Prepared measurement item: %s", measurement)
log.Printf("Prepared measurement item: %s", measurement)
self.dbh.StoreMeasurement(&measurement)
self.S()
}

View File

@ -111,6 +111,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
t.Id = id
t.ready = true
t.dbh = database.NewDatabaseHandle()
log.Printf("Handler SVER %d initialized", id)
return t
}

View File

@ -2,7 +2,7 @@ package draginoLdds75
import (
"fmt"
"log"
// "log"
"strings"
"strconv"
"encoding/json"
@ -26,7 +26,7 @@ type message struct {
TempC_DS18B20 string `json:"TempC_DS18B20"`
}
func Parse(fPort int, decodedPayload []byte, variables *map[string]database.VariableType, device *database.Device) error {
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
@ -55,11 +55,20 @@ func Parse(fPort int, decodedPayload []byte, variables *map[string]database.Vari
Unit: "mm",
Value: distance,
}
if distance == 20 {
(*attributes)["Status"] = "invalid value"
} else if distance == 0 {
(*attributes)["Status"] = "no sensor detected"
} else {
(*attributes)["Status"] = "Ok"
}
groundLevelI, exists := device.Attributes["GroundLevel"]
groundLevelS, ok := groundLevelI.(string)
groundLevel, err3 := strconv.Atoi(groundLevelS)
if exists && err3 == nil && ok {
log.Println("add corrected distance")
//log.Println("add corrected distance")
correctedDistance := groundLevel - distance
(*variables)["CorrectedDistance"] = database.VariableType {
Label: "CorrectedDistance",
@ -67,11 +76,11 @@ func Parse(fPort int, decodedPayload []byte, variables *map[string]database.Vari
Unit: "mm",
Value: correctedDistance,
}
} else {
} /* else {
log.Printf("no ground level: %s %s %s", exists, err3, ok)
log.Printf("Device: %s", device)
log.Printf("Attributes: %s", device.Attributes)
}
} */
return nil
}

View File

@ -26,7 +26,7 @@ type message struct {
Dis2 int `json:"dis2"`
}
func Parse(fPort int, decodedPayload []byte, variables *map[string]database.VariableType, device *database.Device) error {
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
@ -55,6 +55,15 @@ func Parse(fPort int, decodedPayload []byte, variables *map[string]database.Vari
Unit: "mm",
Value: distance2,
}
if distance1 == 2 {
(*attributes)["Status"] = "invalid value"
} else if distance1 == 1 {
(*attributes)["Status"] = "no sensor detected"
} else {
(*attributes)["Status"] = "Ok"
}
groundLevelI, exists := device.Attributes["GroundLevel"]
groundLevelS, ok := groundLevelI.(string)
groundLevel, err3 := strconv.Atoi(groundLevelS)

View File

@ -0,0 +1,63 @@
package draginoLse01
import (
"fmt"
"encoding/json"
"udi/database"
)
/*
{
"Bat":3.211,
"TempC_DS18B20":"0.0",
"conduct_SOIL":32,
"temp_SOIL":"7.56",
"water_SOIL":"25.92"
}
*/
type message struct {
Bat float32 `json:"Bat"`
TempC_DS18B20 string `json:"TempC_DS18B20"`
Conduct_SOIL int `json:"conduct_SOIL"`
Temp_SOIL string `json:"temp_SOIL"`
Water_SOIL string `json:"water_SOIL"`
}
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, _ *map[string]interface{}, _ *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
var message message
err := json.Unmarshal(decodedPayload, &message)
if err != nil {
return fmt.Errorf("Unable to parse payload, fPort %d, error %s", fPort, err)
}
(*variables)["Battery"] = database.VariableType {
Label: "Battery",
Variable: "Voltage",
Unit: "V",
Value: message.Bat,
}
(*variables)["Conductance"] = database.VariableType {
Label: "Conductance",
Variable: "Conductance",
Unit: "uS/cm",
Value: message.Conduct_SOIL,
}
(*variables)["Temperature"] = database.VariableType {
Label: "Temperature",
Variable: "Temperature",
Unit: "°C",
Value: message.Temp_SOIL,
}
(*variables)["Water"] = database.VariableType {
Label: "Water",
Variable: "Water",
Unit: "%",
Value: message.Water_SOIL,
}
return nil
}

View File

@ -0,0 +1,74 @@
package draginoLsn50
import (
"fmt"
"encoding/json"
"udi/database"
)
/*
"decoded_payload": {
"ALARM_status": "FALSE",
"BatV": 3.659,
"Temp_Black": 3276.7,
"Temp_Red": 22.6,
"Temp_White": 3276.7,
"Work_mode": "DS18B20"
},
*/
type message struct {
ALARM_status string `json:"ALARM_status"`
Bat float32 `json:"BatV"`
Work_mode string `json:"Work_mode"`
Temp_Black float32 `json:"Temp_Black"`
Temp_Red float32 `json:"Temp_Red"`
Temp_White float32 `json:"Temp_White"`
}
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
var message message
err := json.Unmarshal(decodedPayload, &message)
if err != nil {
return fmt.Errorf("Unable to parse payload, fPort %d, error %s", fPort, err)
}
(*variables)["Battery"] = database.VariableType {
Label: "Battery",
Variable: "Voltage",
Unit: "V",
Value: message.Bat,
}
(*variables)["Alarm"] = database.VariableType {
Label: "Alarm",
Variable: "Alarm",
Unit: "",
Value: message.ALARM_status,
}
(*variables)["Temp_Red"] = database.VariableType {
Label: "Temp_Red",
Variable: "Temperature",
Unit: "°C",
Value: message.Temp_Red,
}
(*variables)["Temp_Black"] = database.VariableType {
Label: "Temp_Black",
Variable: "Temperature",
Unit: "°C",
Value: message.Temp_Black,
}
(*variables)["Temp_White"] = database.VariableType {
Label: "Temp_White",
Variable: "Temperature",
Unit: "°C",
Value: message.Temp_White,
}
(*attributes)["Status"] = "Ok"
return nil
}

View File

@ -177,7 +177,7 @@ type emuMessage1 struct {
func Parse(fPort int, decodedPayload []byte, variables *map[string]database.VariableType, _ *database.Device) error {
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, _ *map[string]interface{}, _ *database.Device) error {
//log.Printf("Parse input: %d, %s", fPort, decodedPayload)
switch fPort {
case 1:

View File

@ -0,0 +1,55 @@
package hottisGy21
import (
//"log"
"fmt"
"bytes"
"encoding/base64"
"encoding/binary"
"udi/database"
)
type hottisGy21Values struct {
Connected uint8
Status uint8
RawHumidity uint16
RawTemperature uint16
}
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, _ *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
b, err := base64.StdEncoding.DecodeString(frmPayload)
if err != nil {
return fmt.Errorf("Unable to base64-decode payload: %v", err)
}
var values hottisGy21Values
err = binary.Read(bytes.NewReader(b), binary.LittleEndian, &values)
if err != nil {
return fmt.Errorf("Unable to cast into struct: %v", err)
}
var temperature float32 = -46.85 + 175.72 * (float32(values.RawTemperature) / 65536.0)
var humidity float32 = -6 + 125 * (float32(values.RawHumidity) / 65536.0);
// log.Printf("CO2: %f, Temp: %f, Hum: %f, Status: %d", co2concentration, temperature, humidity, values.Status)
(*variables)["Humidity"] = database.VariableType {
Label: "Humidity",
Variable: "Humidity",
Unit: "%",
Value: humidity,
}
(*variables)["Temperature"] = database.VariableType {
Label: "Temperature",
Variable: "Temperature",
Unit: "°C",
Value: temperature,
}
(*attributes)["Status"] = values.Status
return nil
}

View File

@ -0,0 +1,69 @@
package hottisScd30
import (
//"log"
"fmt"
"bytes"
"encoding/base64"
"encoding/binary"
"udi/database"
)
type hottisScd30Values struct {
Status uint8
CO2Conc int32
Temp int32
Hum int32
Bri int32
}
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, _ *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
b, err := base64.StdEncoding.DecodeString(frmPayload)
if err != nil {
return fmt.Errorf("Unable to base64-decode payload: %v", err)
}
var values hottisScd30Values
err = binary.Read(bytes.NewReader(b), binary.LittleEndian, &values)
if err != nil {
return fmt.Errorf("Unable to cast into struct: %v", err)
}
var co2concentration float32 = float32(values.CO2Conc) / 100;
var temperature float32 = float32(values.Temp) / 100;
var humidity float32 = float32(values.Hum) / 100;
// log.Printf("CO2: %f, Temp: %f, Hum: %f, Status: %d", co2concentration, temperature, humidity, values.Status)
(*variables)["CO2concentration"] = database.VariableType {
Label: "CO2concentration",
Variable: "Concentration",
Unit: "ppm",
Value: co2concentration,
}
(*variables)["Temperature"] = database.VariableType {
Label: "Temperature",
Variable: "Temperature",
Unit: "°C",
Value: temperature,
}
(*variables)["Humidity"] = database.VariableType {
Label: "Humidity",
Variable: "Humidity",
Unit: "%",
Value: humidity,
}
(*variables)["Brightness"] = database.VariableType {
Label: "Brightness",
Variable: "Brightness",
Unit: "",
Value: values.Bri,
}
(*attributes)["Status"] = values.Status
return nil
}

View File

@ -0,0 +1,93 @@
package hottisThreeWayThermometer
import (
"log"
"fmt"
"bytes"
"strconv"
"encoding/base64"
"encoding/binary"
"udi/database"
)
type hottisThreeWayThermometerValues struct {
Status uint8
Battery uint16
SensorAddress1 uint64
Value1 int32
SensorAddress2 uint64
Value2 int32
SensorAddress3 uint64
Value3 int32
}
func getSensorName(sensorsMap *map[string]interface{}, sensorAddress uint64) string {
key := strconv.FormatUint(sensorAddress, 10)
if sensorName, exists := (*sensorsMap)[key].(string); exists {
return sensorName
}
return "Sensor" + key
}
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
deviceAttrs := (*device).Attributes
sensorsMap := deviceAttrs["Sensors"].(map[string]interface{})
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
b, err := base64.StdEncoding.DecodeString(frmPayload)
if err != nil {
return fmt.Errorf("Unable to base64-decode payload: %v", err)
}
var values hottisThreeWayThermometerValues
err = binary.Read(bytes.NewReader(b), binary.LittleEndian, &values)
if err != nil {
return fmt.Errorf("Unable to cast into struct: %v", err)
}
var battery float32 = float32(values.Battery) / 1000.0
var value1 float32 = float32(values.Value1) / 128.0
var value2 float32 = float32(values.Value2) / 128.0
var value3 float32 = float32(values.Value3) / 128.0
//log.Printf("Status: %d, Battery: %d", values.Status, values.Battery);
log.Printf("Status: %d", values.Status);
log.Printf("Battery: %d, %f", values.Battery, battery);
log.Printf("Sensor1: Addr: %d, Value: %f", values.SensorAddress1, value1);
log.Printf("Sensor2: Addr: %d, Value: %f", values.SensorAddress2, value2);
log.Printf("Sensor3: Addr: %d, Value: %f", values.SensorAddress3, value3);
(*variables)["Battery"] = database.VariableType {
Label: "Battery",
Variable: "Voltage",
Unit: "V",
Value: battery,
}
(*variables)["Temperature1"] = database.VariableType {
Label: getSensorName(&sensorsMap, values.SensorAddress1),
Variable: "Temperature",
Unit: "°C",
Value: value1,
}
(*variables)["Temperature2"] = database.VariableType {
Label: getSensorName(&sensorsMap, values.SensorAddress2),
Variable: "Temperature",
Unit: "°C",
Value: value2,
}
(*variables)["Temperature3"] = database.VariableType {
Label: getSensorName(&sensorsMap, values.SensorAddress3),
Variable: "Temperature",
Unit: "°C",
Value: value3,
}
(*attributes)["Status"] = values.Status
(*attributes)["SensorAddress1"] = values.SensorAddress1
(*attributes)["SensorAddress2"] = values.SensorAddress2
(*attributes)["SensorAddress3"] = values.SensorAddress3
return nil
}

View File

@ -0,0 +1,25 @@
package rawPayloadPrinter
import (
"log"
"fmt"
"encoding/base64"
"encoding/hex"
"udi/database"
)
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, _ *map[string]interface{}, _ *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
bytes, err := base64.StdEncoding.DecodeString(frmPayload)
if err != nil {
return fmt.Errorf("Unable to base64-decode payload: %v", err)
}
hexString := hex.EncodeToString(bytes)
log.Printf("Payload: %s", hexString)
return nil
}

View File

@ -2,6 +2,7 @@ package ttn
import (
"fmt"
"log"
"time"
"encoding/json"
"udi/config"
@ -9,6 +10,12 @@ import (
"udi/handlers/ttn/models/emuProfIILoRaCfg1"
"udi/handlers/ttn/models/draginoLdds75"
"udi/handlers/ttn/models/draginoLmds200"
"udi/handlers/ttn/models/draginoLse01"
"udi/handlers/ttn/models/draginoLsn50"
"udi/handlers/ttn/models/rawPayloadPrinter"
"udi/handlers/ttn/models/hottisScd30"
"udi/handlers/ttn/models/hottisGy21"
"udi/handlers/ttn/models/hottisThreeWayThermometer"
"udi/database"
)
@ -79,11 +86,12 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
}
t.Id = id
t.dbh = database.NewDatabaseHandle()
log.Printf("Handler TTN %d initialized", id)
return t
}
func (self *TTNHandler) Handle(message handler.MessageT) {
// log.Printf("Handler TTN %d processing %s -> %s", self.id, message.Topic, message.Payload)
//log.Printf("Handler TTN %d processing %s -> %s", self.Id, message.Topic, message.Payload)
var measurement database.Measurement
measurement.Time = time.Now()
@ -131,7 +139,7 @@ func (self *TTNHandler) Handle(message handler.MessageT) {
//log.Printf("DeviceLabel: %s, DeviceType: %s", device.Label, device.DeviceType.ModelIdentifier)
var parser func(int, []byte, *map[string]database.VariableType, *database.Device) error
var parser func(int, []byte, string, *map[string]database.VariableType, *map[string]interface{}, *database.Device) error
switch device.DeviceType.ModelIdentifier {
case "emu-prof-ii-lora-cfg1":
parser = emuProfIILoRaCfg1.Parse
@ -139,13 +147,30 @@ func (self *TTNHandler) Handle(message handler.MessageT) {
parser = draginoLdds75.Parse
case "dragino-lmds200":
parser = draginoLmds200.Parse
case "dragino-lse01":
parser = draginoLse01.Parse
case "dragino-lsn50":
parser = draginoLsn50.Parse
case "raw-payload-printer":
parser = rawPayloadPrinter.Parse
case "hottis-scd30":
parser = hottisScd30.Parse
case "hottis-gy21":
parser = hottisGy21.Parse
case "hottis-threeway-thermometer":
parser = hottisThreeWayThermometer.Parse
default:
self.Lost(fmt.Sprintf("No parser found for %s", device.DeviceType.ModelIdentifier), nil, message)
return
}
measurement.Values = make(map[string]database.VariableType)
err3 := parser(uplinkMessage.UplinkMessage.FPort, uplinkMessage.UplinkMessage.DecodedPayload.Payload, &(measurement.Values), device)
err3 := parser(uplinkMessage.UplinkMessage.FPort,
uplinkMessage.UplinkMessage.DecodedPayload.Payload,
uplinkMessage.UplinkMessage.FrmPayload,
&(measurement.Values),
&(measurement.Attributes),
device)
if err3 != nil {
self.Lost("Model parser failed", err3, message)
return

View File

@ -0,0 +1,15 @@
package gs361ah04
type Observation struct {
LinkQuality uint8 `unit:"" json:"linkquality"`
Battery uint8 `unit:"%" json:"battery"`
AwayMode string `unit:"" json:"away_mode"`
ChildLock string `unit:"" json:"child_lock"`
CurrentHeatingSetpoint float32 `unit:"°C" json:"current_heating_setpoint"`
LocalTemperature float32 `unit:"°C" json:"local_temperature"`
Preset string `unit:"" json:"preset"`
SystemMode string `unit:"" json:"system_mode"`
ValveDetection string `unit:"" json:"valve_detection"`
WindowDetection string `unit:"" json:"window_detection"`
}

View File

@ -0,0 +1,11 @@
package wsdcgq01lm
type Observation struct {
LinkQuality uint8 `unit:"" json:"linkquality"`
Battery uint8 `unit:"%" json:"battery"`
Humidity float32 `unit:"%H" json:"humidity"`
Pressure float32 `unit:"mbar" json:"pressure"`
Temperature float32 `unit:"°C" json:"temperature"`
Voltage uint16 `unit:"mV" json:"voltage"`
}

View File

@ -0,0 +1,10 @@
package wsdcgq11lm
type Observation struct {
LinkQuality uint8 `unit:"" json:"linkquality"`
Battery uint8 `unit:"%" json:"battery"`
Humidity float32 `unit:"%H" json:"humidity"`
Temperature float32 `unit:"°C" json:"temperature"`
Voltage uint16 `unit:"mV" json:"voltage"`
}

113
src/udi/handlers/z2m/z2m.go Normal file
View File

@ -0,0 +1,113 @@
package z2m
import (
"fmt"
"log"
"time"
"strings"
"reflect"
"encoding/json"
"udi/config"
"udi/handlers/handler"
"udi/database"
"udi/handlers/z2m/models/wsdcgq11lm"
"udi/handlers/z2m/models/wsdcgq01lm"
"udi/handlers/z2m/models/gs361ah04"
)
type Z2MHandler struct {
handler.CommonHandler
dbh *database.DatabaseHandle
}
func parse(T any, payload string, variables *map[string]database.VariableType) error {
observationType := reflect.TypeOf(T)
observation := reflect.New(observationType).Interface()
err := json.Unmarshal([]byte(payload), observation)
if err != nil {
return fmt.Errorf("Unable to parse payload into Observation struct: %v, %s", err, payload)
}
observationValue := reflect.ValueOf(observation).Elem()
for i := 0; i < observationType.NumField(); i++ {
field := observationType.Field(i)
name := field.Name
unit := field.Tag.Get("unit")
value := observationValue.Field(i).Interface()
(*variables)[name] = database.VariableType {
Label: name,
Variable: "y",
Unit: unit,
Value: value,
}
}
return nil
}
func New(id string, config config.HandlerConfigT) handler.Handler {
t := &Z2MHandler {
}
t.Id = id
t.dbh = database.NewDatabaseHandle()
log.Printf("Handler Z2M %d initialized", id)
return t
}
func (self *Z2MHandler) Handle(message handler.MessageT) {
log.Printf("Handler Z2M %d processing %s -> %s", self.Id, message.Topic, message.Payload)
var measurement database.Measurement
measurement.Time = time.Now()
subTopics := strings.Split(message.Topic, "/")
deviceId := subTopics[1]
log.Printf("DeviceId: %s", deviceId)
device, err1 := self.dbh.GetDeviceByLabel(deviceId)
if err1 != nil {
self.Lost("Error when loading device", err1, message)
return
}
log.Printf("Device: %s", device)
measurement.Application = device.Application.Label
measurement.Device = device.Attributes["Label"].(string)
var T any
switch device.DeviceType.ModelIdentifier {
case "WSDCGQ11LM":
T = wsdcgq11lm.Observation{}
case "WSDCGQ01LM":
T = wsdcgq01lm.Observation{}
case "GS361A-H04":
T = gs361ah04.Observation{}
default:
self.Lost(fmt.Sprintf("No parser found for %s", device.DeviceType.ModelIdentifier), nil, message)
return
}
measurement.Values = make(map[string]database.VariableType)
measurement.Attributes = make(map[string]interface{})
err3 := parse(T,
message.Payload,
&(measurement.Values))
if err3 != nil {
self.Lost("Model parser failed", err3, message)
return
}
measurement.Attributes["Status"] = "ok"
measurement.Attributes["DeviceId"] = deviceId
measurement.Attributes["DeviceModel"] = device.DeviceType.ModelIdentifier
log.Printf("Prepared measurement item: %s", measurement)
self.dbh.StoreMeasurement(&measurement)
self.S()
}