Nov 27, 2020

Kubernetes with microK8s: First steps to expose a service to external

At home i wanted to have my own kubernetes cluster. I own 2 raspberry pi based on ubuntu, so i decided to install microK8s:

--> https://ubuntu.com/blog/what-can-you-do-with-microk8s

The installation is very well explained here:

https://ubuntu.com/tutorials/install-a-local-kubernetes-with-microk8s#1-overview

 

BUT: i found nowhere a tutorial how to run an container and expose the port in a way that i is reachable from other pc like localhost.

So here we go:

kubectl create deployment web --image=nginx
kubectl expose deployment web --type=NodePort --port=80

After that just do:

# kubectl get all
NAME                      READY   STATUS    RESTARTS   AGE
pod/web-96d5df5c8-5xvfc   1/1     Running   0          112s

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
service/kubernetes   ClusterIP   10.152.183.1    <none>        443/TCP        2d5h
service/web          NodePort    10.152.183.66   <none>        80:32665/TCP   105s

NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/web   1/1     1            1           112s

NAME                            DESIRED   CURRENT   READY   AGE
replicaset.apps/web-96d5df5c8   1         1         1       112s

On you kubernetes node you can reach the service with 10.152.183.66:80.

For getting the nginx from another pc just use:

<yourkuberneteshost>:32665

For me:



 


Nov 20, 2020

ZigBee@Linux: Getting Data from ZigBee Devices via MQTT to InfluxDB and Grafana

Getting sensors with zigbee integrated with my linux raspberry pi, i did some monitoring tasks on my raspberry pi.

  1. Monitoring my raspberry pi:
    There is a very nice tutorial:
    https://medium.com/@andreea.sonda31/monitor-raspberry-pi-resources-and-parameters-with-grafana-board-part-1-ab0567303e8
    Or even better: Just use this from grafana:
    https://grafana.com/grafana/dashboards/10578
    1. add deb https://packages.grafana.com/oss/deb stable main to a file in /etc/apt/sources.list.d/
    2. apt install grafana telegraf influxdb
    3. configure telegraf for your influxdb
    4. import the json from the grafana.com-link above



  2. Monitoring my Fritz.Box with Grafana:
    https://grafana.com/grafana/dashboards/713 
    and follow the given tutorial https://fetzerch.github.io/2014/08/23/fritzcollectd/
After these steps i have the following infrastructures running:
  1. zigbee2mqtt --> MQTT -->FHEM


  2. Fritz.box --> collectd --> InfluxDB --> Grafana

  3. raspberry --> telegraf --> InfluxDB --> Grafana


For  2 and 3 it is very easy to create graphics and the presentation looks little bit prettier than 1 (imho). 

AND there is only one frontend to configure. So what about the following chain for my zigbee sensors:

  1. zigbee2mqtt --> MQTT -->telegraf --> InfluxDB --> Grafana 

Looks like some more steps, but the telegraf --> InfluxDB --> Grafana chain is already there for monitoring my raspberry pi.

So i only had to add the following on /etc/telegraf/telegraf.conf:

[[inputs.mqtt_consumer]]
   servers = ["tcp://127.0.0.1:1883"]
   topics = [
     "zigbee2mqtt/0x00158d000542239e",
     "zigbee2mqtt/0x00158d00044a6378",
     "zigbee2mqtt/0x00158d0003f0faad",
     "zigbee2mqtt/0x00158d00044a72a2",
   data_format = "json"

And after that i was able to use the data in Grafana:


 


Nov 15, 2020

ZigBee@Linux: Securing zigbee2mqtt & MQTT@FHEM & FHEM


After my setup is running, just some words about securing the whole setup.

The web gui of FHEM was already setup with SSL/HTTPS but the MQTT server is listening for all ips.

The easiest way to get this secure is change the listener to localhost, so that no connections from outside can be made. Just change in /opt/fhem/fhem.cfg:

define MQTT2_FHEM_Server MQTT2_SERVER 1883 127.0.0.1

Just a checklist, if we secured everything:
  • FHEM
  • zigbee2mqtt
    • add permit_join: false to configuration.yaml




Nov 14, 2020

ZigBee@Linux: Integration of zigbee2mqtt with FHEM (mqtt server) on ubuntu server

After the setup of FHEM and zigbee2mqtt the integration of both components has to be done.

What has to be done?

After reading the excellent documentation of FHEM it is very easy - FHEM can be configured, so that it is providing a mqtt server. 

First you have to add the following line in /opt/zigbee2mqtt/data/configuration.yaml inside the "mqtt:" section:

  client_id: 'zigbee_pi'

Then go to the command prompt of the FHEM webgui and enter the following:

define MQTT2_FHEM_Server MQTT2_SERVER 1883 global
defmod MQTT2_zigbee_pi MQTT2_DEVICE zigbee_pi
attr MQTT2_zigbee_pi IODev MQTT2_FHEM_Server
attr MQTT2_zigbee_pi bridgeRegexp zigbee2mqtt/([A-Za-z0-9]*)[/]?.*:.* "zigbee_$1"
After that you should see something like this:

(you can change the style of the page via "select style" on the left column)

Then you should save:


To create a graph just click on the file which is created for your zigbee device:


and then there should be something like:

Here you can click on "Create SVG plot" and on:

click on "write .gplot file" and your first graph is there... Repeat this and you can get:







 


Zigbee@Linux: Infrastructure - Setup

On my way to home automation with zigbee@linux my decision (as i wrote in this posting) was

  • Hardware
  • OS
    • Ubuntu server
  • Software
    • FHEM (which is the acronym for Freundliche Hausautomation und Energie-Messung = Friendly home automation and energy metering)
      This includes the server with MQTT infrastructure & webserver & gui based on perl
    • zigbee2mqtt
      The server which does the communication with the usb zigbee stick and talking to the MQTT infrastructure based on nodejs

 



The installation of FHEM was quite easy (see here) and the installation of zigbee2mqtt just worked like described here.

  1. Problem:
    FHEM is per default installed without SSL/HTTPS and without user authentication
  2. Problem:
    The communication between both components has to be setup

Here the solution for problem 1:

Login to your raspberry and type the following commands:

cd /opt/fhem
chown fhem:dialout certs
cd certs/
openssl req -new -x509 -nodes -out server-cert.pem -days 3650 -keyout server-key.pem
chown fhem:dialout *
apt  install libio-socket-ssl-perl
After that move the webgui (something like http://yourraspberry:8083) and submit the following commands on the prompt:

attr WEB sslVersion TLSv12:!SSLv3
attr WEB HTTPS 1

And then open your webfrontend with https://yourraspberry:8083.

To add a user:

@bash

echo -n fhem:MYPASSWD| base64

@Webfrontend:

attr WEB basicAuth BASE64String

 The second problem will be solved on a future posting. Just wait...



Nov 8, 2020

Home automation with linux: How to use zigbee sensors on an ubuntu raspberry pi...

To the end of the year i wanted to start a new project: Home automation...

I decided to use a linux system (of course) on a raspberry pi (see the OS installation here) and the zigbee protocol.

The main problem: What packages are needed 

  • to get a communication with zigbee components?
  • to get a website or app to get the data / visualize the data?
  • to set up a daemon/server which controls the devices?

Let's start with the third point: I will try FHEM.

The installation is described here:

https://debian.fhem.de/

wget -qO - http://debian.fhem.de/archive.key | apt-key add -
echo "deb http://debian.fhem.de/nightly/ /" >> /etc/apt/sources.list
apt update
apt upgrade
apt install fhem

After you follow the steps you can check, if FHEM is running with

root@zigbee:/home/ubuntu# netstat -ltnup | grep 8083
tcp 0 0 0.0.0.0:8083 0.0.0.0:* LISTEN 19446/perl

 or just connect to your raspberry via browser: http://zigbee:8083

 
 
and here a screenshot of the goal i want to achieve (maybe with some graphs added):


Here a list of the supported hardware:

https://wiki.fhem.de/wiki/Kategorie:Hardware

and a list of all supported protocols:

https://wiki.fhem.de/wiki/System%C3%BCbersicht#Protokolle


 

 

 

 

Nov 6, 2020

Raspberry PI: Installing OS with a linux pc/laptop (ubuntu)

 If you want to run a raspberry pi and you are wondering how to install the os onto the sd card please try this:

https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#1-overview

What is the benefit of this way?

Ubuntu provides on page 2 a package for the rpi-imager:

and with this tool (will be started with rpi-imager on the cli), you will get this:



 As you can see: you can choose of many different OS and the imager will do the download and the installation for you including resizing the partition to the complete sd card...

And of course you can select your own image (e.g. in *xz format) from your disk...

After the installation it will be verified and you can start your raspberry pi...