Skip to content

NATS

Setup

Prepared values and manifests are in repo home.mixi.cz:/srv/git/repos/home/automation.git in folder kube/nats/.

  1. Install helm repo and get default NATS Helm values if needed.
    helm repo add nats https://nats-io.github.io/k8s/helm/charts/ helm inspect values nats/nats > values.yaml
    
  2. to enable authentication using memory resolver, create NKEYs accounts and users (here is also included user leaf-mqtt for leaf node):
    # set environment
    . env.sh
    
    # create operator OP and account ACC (use second key for signing when asked)
    nsc add operator -n OP --sys --generate-signing-key
    nsc add account -n APP -i
    nsc edit account APP --js-disk-storage -1 --js-mem-storage -1
    nsc edit account --sk generate
    
    # create user accounts (use second key for signing when asked)
    nsc add user --name mixi -a APP -i
    nsc add user --name app -a APP -i
    nsc add user --name nats-box -a APP -i
    nsc add user --name leaf-mqtt -a APP -i
    
    nsc generate config --mem-resolver --config-file ./resolver.conf && mv ./resolver.conf nats-accounts/
    
    cp nsc/keys/creds/OP/APP/nats-box.creds nsc/keys/creds/OP/APP/app.creds nats-user-creds/
    
    kubectl create configmap nats-accounts --from-file=nats-accounts/resolver.conf
    kubectl create secret generic nats-leaf-mqtt-creds --from-file=nsc/keys/creds/OP/APP/leaf-mqtt.creds
    kubectl create secret generic nats-user-creds --from-file=./nats-user-creds
    
  3. in case there is later change in account database, config map can be updated this way:
    # update of config map:
    kubectl get configmaps nats-accounts -o yaml > tmp-cm-nats-accounts.yaml
    
    # ... edit tmp-cm-nats-accounts.yaml (paste nats-accounts/resolver.conf) ...
    kubectl apply -f tmp-cm-nats-accounts.yaml
    
  4. run helm charts and kubernetes manifests
    # install/update main cluster
    helm upgrade nats-home nats/nats --values helm-values-home-cluster.yaml --install
    kubectl apply -f nats-home-service.yaml 
    
    # install/update MQTT leaf node
    helm upgrade nats-home-mqtt nats/nats --values helm-values-home-leaf-mqtt.yaml --install
    kubectl apply -f nats-mqtt-leaf-service.yaml
    

Subject catalog

All subjets are available both as native NATS subjects or MQTT topics. For translation rules see NATS documentation. In catalog, all subjects use NATS notation.

IoT

Generally uses JSON and plain text formats, with possible binary payload encoded as base64 strings (Google Protocol Buffers).

subjects

  • node.> -- Hardwario Tower communication
  • gateway.> -- Hardwario Tower gateway

streams

  • iot_node -- unlimited retention, captured subjects:
    • node.>

home

PV = PhotoVoltaics, FVE = FotoVoltaická Elektrárna.

subjects

  • home.pv.inverter.data -- raw data from Goodwe inverter in JSON format
  • home.pv.inverter.sensors -- sensor information from Goodwe inverter in JSON format
  • home.pv.data.> -- structured and categorized data regarding PhotoVoltaics

streams

  • home_pv_inverter -- short retention
  • home_pv_data -- TBD (more streams with various retention?)