Selaa lähdekoodia

latest domoticz dedusting

cc 3 vuotta sitten
vanhempi
commit
92ffc88d64

+ 4 - 18
domoticz/Dockerfile

@@ -1,27 +1,13 @@
-#
-# Dockerfile for Rpi-Domoticz
-#
-# Based on version by LBTM
-#
-# Base image.
-FROM resin/rpi-raspbian:jessie-20161026
+FROM domoticz/domoticz:stable
 
-MAINTAINER Florian Chauveau
-
-# Install Domoticz from sources.
+# Install more stuff
 RUN \
   apt-get update && \
-  apt-get install -y cmake apt-utils build-essential && \
-  apt-get install -y libboost-dev libboost-thread-dev libboost-system-dev libsqlite3-dev subversion curl libcurl4-openssl-dev libusb-dev zlib1g-dev && \
+  apt-get install -y sqlite3 python3 python3-dev && \
   apt-get clean && \
   apt-get autoclean && \
   rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
 
-# Expose port.
-EXPOSE 80
-
-CMD ["/root/domoticz/domoticz", "-www", "80"]
+COPY fix_meter_values.py /fix_meter_values.py
 
-# https://releases.domoticz.com/releases/release/domoticz_linux_armv7l.tgz
-ADD domoticz_linux_armv7l.tgz /root/domoticz
 HEALTHCHECK --interval=10s CMD curl -sS --fail http://localhost:80 || exit 1

BIN
domoticz/domoticz_linux_armv7l.tgz


+ 41 - 0
domoticz/fix_meter_values.py

@@ -0,0 +1,41 @@
+import os, sqlite3
+
+if os.name != 'nt':
+    fn = '/opt/domoticz/userdata/domoticz.db'
+else:
+    fn = 't:/domoticz.db'
+conn = sqlite3.connect(fn)
+cursor = conn.cursor()
+print("Successfully Connected to %s" % fn)
+
+sql = '''select DeviceRowId, Value, Counter, Date
+from Meter_Calendar order by DeviceRowId,  Date'''
+cursor.execute(sql)
+rs = list(cursor.fetchall())
+for i, (DeviceRowId, Value, Counter, Date) in enumerate(rs):
+
+    if i > 0 and i+2 < len(rs):
+        DeviceRowId1, Value1, Counter1, Date1 = rs[i+1]
+        DeviceRowId2, Value2, Counter2, Date2 = rs[i+2]
+        if Value == 0 or Value1 == 0 or Value2 == 0:
+            # these rows dont look sane, ignore
+            continue
+
+        bad_value = False
+        if (DeviceRowId, DeviceRowId) == (DeviceRowId1, DeviceRowId2):
+            # if the next two values are smaller but increasing
+            if Counter > Counter1 and Counter > Counter2 and Counter1 < Counter2:
+                bad_value = True
+        if bad_value:
+            DeviceRowId0, Value0, Counter0, Date0 = rs[i-1]
+            if DeviceRowId == DeviceRowId0:
+                new_counter = Counter1 - Value1
+                new_value = new_counter - Counter0
+                if new_value > 0:
+                    print('fix device %s at %s: from %s to %s (%s)' % (DeviceRowId, Date, Counter, new_counter, new_value))
+                    sql = '''update Meter_Calendar set value = %s, counter = %s
+                    where DeviceRowId = %s and Date = '%s' '''
+                    cursor.execute(sql % (new_value, new_counter, DeviceRowId, Date))
+
+conn.commit()
+cursor.close()

+ 25 - 0
graphite/Dockerfile

@@ -0,0 +1,25 @@
+FROM resin/rpi-raspbian:jessie-20170531
+
+RUN apt-get -y update \
+  && apt-get -y upgrade \
+  && apt-get -y install vim \
+  nginx \
+  python-dev \
+  python-flup \
+  python-pip \
+  python-ldap \
+  expect \
+  git \
+  memcached \
+  sqlite3 \
+  libffi-dev \
+  libcairo2 \
+  libcairo2-dev \
+  python-cairo \
+  python-rrdtool \
+  pkg-config \
+  nodejs \
+  && rm -rf /var/lib/apt/lists/*
+
+ENV CONTAINER_TIMEZONE=Europe/Berlin
+ENV DEBIAN_FRONTEND noninteractive

+ 6 - 2
hosts.yml

@@ -27,6 +27,10 @@ all:
     erdbeere:
       ansible_ssh_host: 192.168.178.29
     waldbeere:
-      ansible_ssh_host: 192.168.178.24
+      ansible_ssh_host: waldbeere.fritz.box
     stachelbeere:
-      ansible_ssh_host: 192.168.178.111
+      ansible_ssh_host: stachelbeere.fritz.box
+    #~ brombeere:
+      #~ ansible_ssh_host: brombeere.fritz.box
+
+

+ 9 - 0
install.txt

@@ -3,6 +3,7 @@ raspi-config
 
 * german-locale + german-keymap
 * activate sshd and i2c
+ * i2c for pi-usv?
 * apt install vim curl htop mc
 
 manual stuff
@@ -18,3 +19,11 @@ manual stuff
         * printf "username=ftpuser\npassword=#*ftpuser.00\n" > /home/pi/.smbcredentials
         * //192.168.178.1/FRITZ.NAS/TOSHIBA-MK5065GSXF-01 /mnt/hddext  cifs credentials=/home/pi/.smbcredentials,uid=1000,gid=1000,sec=ntlm 0 0
 
+
+Docker
+======
+- https://phoenixnap.com/kb/docker-on-raspberry-pi
+- nano /etc/systemd/system/docker.service.d/override.conf
+    [Service]
+    ExecStart=
+    ExecStart=/usr/bin/dockerd -s overlay2 -H fd:// -H tcp://0.0.0.0:4243

+ 7 - 3
jlab/Dockerfile

@@ -1,11 +1,12 @@
 # This file creates a container that runs a jupyter lab server on Raspberry Pi
 # Originally from: https://github.com/mkjiang/rpi-jupyter/blob/master/Dockerfile and https://github.com/kidig/rpi-jupyter-lab/blob/master/Dockerfile
 
-FROM balenalib/raspberry-pi-python:3.8-build
+FROM balenalib/raspberry-pi-python:3.9-stretch-build
 
 WORKDIR /root
 
 # Update pip and install jupyter
+# RUN /bin/bash -c 'wget https://archive.raspbian.org/raspbian.public.key -O - | sudo apt-key add -'
 RUN apt-get update
 RUN apt-get install -y libncurses5-dev
 RUN apt-get install -y libzmq-dev
@@ -36,6 +37,9 @@ RUN sed -i "/c.NotebookApp.open_browser/c c.NotebookApp.open_browser = False" /r
         && sed -i "/c.NotebookApp.notebook_dir/c c.NotebookApp.notebook_dir = '/root'" /root/.jupyter/jupyter_notebook_config.py \
         && sed -i "/c.NotebookApp.password/c c.NotebookApp.password = 'sha1:5815fb7ca805:f09ed218dfcc908acb3e29c3b697079fea37486a'" /root/.jupyter/jupyter_notebook_config.py
 
+# enables sublime mode on all cells (fixes ctrl+d multi select)
+RUN pip3 install jupyterlab_sublime
+
 VOLUME /root/notebooks
 
 # Add Tini. Tini operates as a process subreaper for jupyter. This prevents kernel crashes.
@@ -58,7 +62,7 @@ ENTRYPOINT ["/usr/bin/tini", "--"]
 EXPOSE 8888
 
 # passwd is "code"
-CMD ["jupyter", "lab", "--allow-root", "--NotebookApp.token=''", "--NotebookApp.password='argon2:$argon2id$v=19$m=10240,t=10,p=8$GXZHXm2yFviNanoy9hyULw$1YLbN5ymQxuwvwPVN5e0hA'"]
+CMD ["jupyter", "lab", "--collaborative", "--allow-root", "--NotebookApp.token=''", "--NotebookApp.password='argon2:$argon2id$v=19$m=10240,t=10,p=8$GXZHXm2yFviNanoy9hyULw$1YLbN5ymQxuwvwPVN5e0hA'"]
 
 # local flaschen-taschen terminal
 RUN mkdir /opt/ft \
@@ -74,4 +78,4 @@ RUN chmod 777 /bin/ft
 
 
 # some custom libs for jlab
-COPY ./matrix_ft.py /usr/local/lib/python3.8/site-packages/matrix_ft.py
+COPY ./matrix_ft.py /usr/local/lib/python3.9/site-packages/matrix_ft.py

+ 21 - 1
jlab/matrix_ft.py

@@ -57,6 +57,24 @@ class Matrix(object):
         self._data[offset + 1] = color[1]
         self._data[offset + 2] = color[2]
 
+    def draw_img(self, x, y, img, ignore_black=True):
+        '''draw a PIL image at (x, y)
+        '''
+        #~ for img_x in range(img.width):
+            #~ for img_y in range(img.height):
+                #~ color = img.getpixel((img_x, img_y))[:3]
+                #~ if not ignore_black or sum(color) > 0:
+                    #~ self.set(x + img_x , y + img_y, color)
+
+        width = img.width
+        imgdata = img.getdata()
+        for img_x in range(img.width):
+            for img_y in range(img.height):
+                color = imgdata[img_y * width + img_x]
+                if not ignore_black or (color[0] or color[1] or color[2]):
+                    self.set(x + img_x , y + img_y, color)
+
+
     def set_offset(self, x, y):
         self.x_offset = x
         self.y_offset = y
@@ -66,10 +84,12 @@ class Matrix(object):
         '''Send the updated pixels to the display.'''
         self._sock.send(self._data)
 
-    def clear(self):
+    def clear(self, send=True):
         '''clear pane with black (reinit self._data)
         '''
         self._init_data()
+        if send:
+            self.send()
 
 if __name__ == '__main__':
     f = Matrix('192.168.178.144', 50, 50)

+ 7 - 6
matrix/light/Dockerfile

@@ -1,4 +1,5 @@
-FROM resin/rpi-raspbian:jessie-20170531
+#~ FROM resin/rpi-raspbian:jessie-20170531
+FROM arm32v7/debian:buster-slim
 
 # Set the variables
 ENV DEBIAN_FRONTEND noninteractive
@@ -28,12 +29,12 @@ RUN apt-get update && apt-get install -y \
         python-pillow
 
 
-RUN sudo echo "Europe/Berlin" > /etc/timezone
-RUN sudo dpkg-reconfigure -f noninteractive tzdata
+#~ RUN echo "Europe/Berlin" > /etc/timezone
+#~ RUN dpkg-reconfigure -f noninteractive tzdata
 
 # Update pip and install jupyter
-RUN pip install --upgrade pip
-RUN pip install path.py requests
+#~ RUN pip install --upgrade pip
+#~ RUN pip install path.py requests
 
 # this version will be used by matrix python bindings
 RUN pyversions -d
@@ -48,6 +49,6 @@ RUN make -C examples-api-use
 # for python interface
 RUN cd bindings/python && make build-python install-python
 
-COPY _ctx/pixel /app
+#~ COPY _ctx/pixel /app
 # CMD python -u /app/pixelreceiver.py > /pixel/receive.log
 CMD /bin/bash -c "sleep 100000"

+ 4 - 4
matrix/pixel/sender.py

@@ -73,12 +73,12 @@ def destroy():
     return None
 
 if __name__ == '__main__':
-    #~ print(repr(print_text(u'Christine ♥')))
-    print(decode(print_text(u'Christine ♥')).text.encode('utf-8'))
+    print(repr(print_text(u'Christine ♥')))
+    #~ print(decode(print_text(u'Christine ♥')).text.encode('utf-8'))
     #~ print(decode(print_text('Christine ♥'))._asdict())
     #~ print(type(decode(print_text('Christine ♥'))).__name__)
 
 
-    sender = Sender('blaubeere.fritz.box', 10000)
-    #~ sender.print_text(u'Christine ♥')
+    sender = Sender('waldbeere.fritz.box', 10000)
+    sender.print_text(u'Christine ♥')
     sender.destroy()

+ 116 - 18
services.yml

@@ -39,11 +39,80 @@ domoticz:
   docker:
     build: domoticz
     image: domoticz
+    #~ image: domoticz/domoticz:stable
     volumes:
-      - /etc/localtime:/etc/localtime
-      - /mnt/ssdext/data/domoticz/domoticz.db:/root/domoticz/domoticz.db
-    # ports: 8080:8080
+      # - /etc/localtime:/etc/localtime
+      # - /mnt/ssdext/data/domoticz/domoticz.db:/root/domoticz/domoticz.db
+      - /mnt/ssdext/data/domoticz:/opt/domoticz/userdata
+    ports: 8080:80
     devices: /dev/ttyUSB0
+    env:
+      TZ: Europe/Amsterdam
+      WWW_PORT: 80
+    commands:
+      backup_db: /bin/bash -c "cp -p /opt/domoticz/userdata/domoticz.db /opt/domoticz/userdata/domoticz.db.`date +%Y.%m.%d.%H.%M.%S`"
+      cleanup_meter_values: python3 /fix_meter_values.py
+
+
+#~ influxdb: # receive data from domoticz
+  #~ host: himbeere
+  #~ fqdn: influx.cere.duckdns.org
+  #~ docker:
+    #~ image: arm32v7/influxdb:latest
+    #~ volumes:
+      #~ - /mnt/ssdext/data/influxdb/data:/var/lib/influxdb2
+      #~ # - /mnt/ssdext/data/influxdb/config:/etc/influxdb2
+    #~ env:
+      #~ VIRTUAL_PORT: 8086
+      #~ # DOCKER_INFLUXDB_INIT_MODE: setup
+      #~ # DOCKER_INFLUXDB_INIT_USERNAME: dirk
+      #~ # DOCKER_INFLUXDB_INIT_PASSWORD: "#*influx.00"
+      #~ # DOCKER_INFLUXDB_INIT_ORG: rothe
+      #~ # DOCKER_INFLUXDB_INIT_BUCKET: home_bucket
+      #~ # DOCKER_INFLUXDB_INIT_RETENTION: 1w
+      #~ # DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: "123XY.00"
+      #~ INFLUXDB_REPORTING_DISABLED: true
+      #~ INFLUXDB_ADMIN_USER: influx_admin
+      #~ INFLUXDB_ADMIN_PASSWORD: pass
+      #~ INFLUXDB_HTTP_AUTH_ENABLED: "true"
+
+#~ chronograf:
+  #~ host: himbeere
+  #~ fqdn: chronograf.cere.duckdns.org
+  #~ docker:
+    #~ image: arm32v7/chronograf:latest
+    #~ volumes:
+      #~ - /mnt/ssdext/data/chronograf/data:/var/lib/chronograf
+    #~ env:
+      #~ VIRTUAL_PORT: 8888
+
+grafana:
+  host: himbeere
+  fqdn: grafana.cere.duckdns.org
+  docker:
+    image: grafana/grafana-oss
+    env:
+      VIRTUAL_PORT: 3000
+    volumes:
+      # see https://grafana.com/docs/grafana/v9.0/setup-grafana/configure-docker/#default-paths
+      - /mnt/ssdext/data/grafana/data:/var/lib/grafana
+      - /mnt/ssdext/data/grafana/log:/var/log/grafana
+      - /mnt/ssdext/data/grafana/plugins:/var/lib/grafana/plugins
+
+graphite: # https://hub.docker.com/r/graphiteapp/graphite-statsd/
+  host: himbeere
+  docker:
+    #~ build: graphite
+    image: graphiteapp/graphite-statsd
+    volumes:
+      - /mnt/ssdext/data/graphite/storage:/opt/graphite/storage
+      - /mnt/ssdext/data/graphite/log:/var/log
+      - /mnt/ssdext/data/graphite/redis:/var/lib/redis
+      #~ - /mnt/ssdext/data/graphite/logs:/var/log/supervisor
+    #~ ports:
+      #~ - 13080:8000
+      #~ - 8125:8125/udp
+      #~ - 8126:8126
 
 netdata:
   host: himbeere
@@ -157,19 +226,6 @@ gogs: # git server with wiki
       test: curl -I --silent http://localhost:3000 | grep "404 Not Found"
       interval: 10 # seconds
 
-graphite:
-  host: himbeere
-  docker:
-    build: graphite
-    #~ image: abarbanell/docker-grafana-graphite
-    volumes:
-      - /mnt/ssdext/data/graphite/whisper:/opt/graphite/storage/whisper
-      - /mnt/ssdext/data/graphite/logs:/var/log/supervisor
-    ports:
-      - 13080:8000
-      - 8125:8125/udp
-      - 8126:8126
-
 alexa: # https://alexa.amazon.de
   fqdn: alexa.cere.duckdns.org
   host: himbeere
@@ -198,8 +254,8 @@ matrix-ft:
     # matrix driver needs access to /dev/mem
     privileged: true
     ports: 1337:1337/udp
-    # --led-slowdown-gpio=2 --led-pwm-lsb-nanoseconds=50
-    command: '/server --led-pixel-mapper=Rotate:180 --led-rows=64 --led-cols=192'
+    # --led-pwm-dither-bits=1
+    command: '/server --layer-timeout 3600 --led-pixel-mapper=Rotate:180 --led-rows=64 --led-cols=192 --led-brightness=60 --led-slowdown-gpio=3 --led-show-refresh --led-pwm-lsb-nanoseconds=150'
     commands:
       d_life: /root/ft-demos/life -g 192x64 -d 50
       d_matrix: /root/ft-demos/matrix -g 192x64
@@ -214,7 +270,49 @@ matrix-ft:
       d_bolt: /root/ft-demos/blur -g 192x64 bolt
       d_sierpinski: /root/ft-demos/sierpinski -g 192x64
 
+matrix-ft-brom:
+  host: brombeere
+  docker:
+    init: true
+    build: flaschentaschen
+    # matrix driver needs access to /dev/mem
+    privileged: true
+    ports: 1337:1337/udp
+    # --led-pwm-dither-bits=1
+    command: '/server --layer-timeout 36000 --led-rgb-sequence=BRG --led-rows=64 --led-cols=128 --led-parallel=2 --led-brightness=60 --led-slowdown-gpio=1 --led-show-refresh --led-pwm-lsb-nanoseconds=180'
+    commands:
+      d_life: /root/ft-demos/life -g 128x128 -d 50
+      d_matrix: /root/ft-demos/matrix -g 128x128
+      d_quilt: /root/ft-demos/quilt -g 128x128
+      d_fractal: /root/ft-demos/fractal -g 128x128
+      d_hack: /root/ft-demos/hack -g 128x128
+      d_midi: /root/ft-demos/midi -g 128x128
+      d_maze: /root/ft-demos/maze -g 128x128
+      d_plasma: /root/ft-demos/plasma -g 128x128
+      d_lines: /root/ft-demos/lines -g 128x128 -a one
+      d_boxes: /root/ft-demos/blur -g 128x128 boxes
+      d_bolt: /root/ft-demos/blur -g 128x128 bolt
+      d_sierpinski: /root/ft-demos/sierpinski -g 128x128
 
+matrix-brom:
+  host: blaubeere
+  docker:
+    init: true
+    build: matrix/light
+    import: pixel
+
+    # matrix driver needs access to /dev/mem
+    privileged: true
+    # ports: 10000:10000/udp, 10001:10001/udp
+    volumes:
+      - /opt/pixel:/pixel
+    env:
+      LED_ROWS: 64
+      LED_COLS: 64
+
+  commands:
+    # some rotating square
+    demo00: examples-api-use/demo --led-rows=64 --led-cols=64 --led-show-refresh -D 0
 
 matrix: # interface with RGB LED-Matrix
   host: waldbeere