DoorPa: Unterschied zwischen den Versionen

Aus FHEMWiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 20: Zeile 20:


[[File:Doorpi_block.png]][[File:doorpi_completes.png]][[File:doorpi_completeb.png]]
[[File:Doorpi_block.png]][[File:doorpi_completes.png]][[File:doorpi_completeb.png]]
=Hardware=
Randbedingung des Projektes DoorPa ist, dass es auf derselben Hardware wie DoorPi laufen soll.
==Arbeitsaufwand und Kosten==
==Raspberry Pi==
Verwendet wird
* ein [http://www.pollin.de/shop/dt/OTQxNzkyOTk-/Bauelemente_Bauteile/Entwicklerboards/Raspberry_Pi/Raspberry_Pi_3_Modell_B.html Raspberry Pi 3], der ein integriertes WLAN-Modul besitzt. Falls man seiner eigenen WLAN-Bandbreite nicht traut: Für ca. 25 € bekommt man einen Satz Powerline-Adapter, mit denen man eine sehr stabile Verbindung zwischen dem Raspberry Pi (Innenwand neben der Tür) und dem Rest des Hauses aufbauen kann.
* eine Zusatzkarte mit jeweils mindestens 8 digitalen Ein- und Ausgängen. Ursprünglich wurde hier das Raspberry Pi-Erweiterungsmodul [http://www.pollin.de/shop/dt/NTc1NzkyOTk-/Bauelemente_Bauteile/Entwicklerboards/Raspberry_Pi/Raspberry_Pi_B_Zusatzplatine_PIFACE_DIGITAL_2.html PiFace 2] verwendet, das neue System lässt sich aber mit ganz unterschiedlicher Hardware aufbauen. Einzige Anforderung an diese Hardware ist, dass beim Betätigen eines der Eingänge (= Verbindung mit GND) in FHEM ein Befehl
set <DoorPa-Device> call call key<Pin-Nummer>
ausgeführt wird
===PiFace 2===
Auf dem Raspberry Pi läuft ein Mini-Programm als Schleife und löst einen FHEM-Befehl aus, sobald einer der digitalen Eingänge des PiFace 2 betätigt wird. Dieses Mini-Programm ist in Python geschrieben und wird aufgerufen als
  python3 /opt/fhem/pifint.py -d <DoorPa-Device>
Der Quellcode ist dem nachstehenden Listing zu entnehmen.
<pre>
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
########################################################################################
#
# PIFACE event handler pifint.py
#
# Prof. Dr. Peter A. Henning, 2019
#
# $Id: pifint.py 2019-06 - pahenning $
#
########################################################################################
#
#  This programm is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  The GNU General Public License can be found at
#  http://www.gnu.org/copyleft/gpl.html.
#  A copy is found in the textfile GPL.txt and important notices to the license
#  from the author is found in LICENSE.txt distributed with these scripts.
#
#  This script is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
########################################################################################
# Attention: ALPHA Software, not to be used for production systems
# place in /etc/rc.local
# as python3 /directory/pifint.py -[i <ip-address>] -d <device> [-k <key>]&
#########################################################################################


import sys, getopt
import pifacedigitalio
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
ip = '127.0.0.1:8083'
device = ''
key = 'key'
def call_fhem(event):
    url = "http://" + ip + "/fhem?XHR=1&cmd=set%20" + device + "%20call%20" + key + str(event.pin_num)
#if "@" in url:
    #    nurl = urlparse.urlsplit(url)
    #    username = nurl.username
    #    password = nurl.password
    #    url = url.replace(username + ':' + password + '@', '')
    url = url.replace(" ", "%20")
    try:
      response = urlopen(url)
    except HTTPError as e:
      # do something
      print('Error code: ', e.code)
    except URLError as e:
      # do something
      print('Reason: ', e.reason)
    else:
      # do something
      html = response.read()
    return False
    return False
def main(argv):
  global device
  try:
      opts, args = getopt.getopt(argv,"hi:d:k:",["ip=","device=","key="])
  except getopt.GetoptError:
      print('pifint.py -i <ip-address> -d <device> -k <key>')
      sys.exit(2)
  for opt, arg in opts:
      if opt == '-h':
        print('pifint.py -i <ip-address> -d <device> -k <key>')
        sys.exit()
      elif opt in ("-i", "--ip"):
        ip = arg
      elif opt in ("-d", "--device"):
        device = arg
      elif opt in ("-k", "--key"):
        key = arg
   
  pifacedigital = pifacedigitalio.PiFaceDigital()
  listener = pifacedigitalio.InputEventListener(chip=pifacedigital)
  listener.register(0, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
  listener.register(1, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
  listener.register(2, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
  listener.register(3, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
  listener.register(4, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
  listener.register(5, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
  listener.register(6, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
  listener.register(7, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
  listener.activate()
 
if __name__ == "__main__":
  main(sys.argv[1:])
</pre>
===GPIO-Pins des Raspberry Pi===
Von der Verwendung der GPIO-Pins des Raspberry Pi rate ich eher ab, da diese über keinen integrierten Schutz verfügen. Fehlerströme und Spannungsspitzen können deshalb gleich die gesamte Hardware lahmlegen.
=Software=


[[Kategorie:1-Wire]]
[[Kategorie:1-Wire]]
[[Kategorie:Code_Snippets]]
[[Kategorie:Code_Snippets]]

Version vom 11. November 2019, 16:35 Uhr

WORK IN PROGRESS


DoorPa
Zweck / Funktion
Das Modul erlaubt die Verwendung eines Raspberry Pi als IP-Türsprechstelle
Allgemein
Typ Hilfsmodul
Details
Dokumentation EN / DE
Support (Forum) Automatisierung
Modulname 70_DoorPa.pm
Ersteller Prof. Dr. Peter A. Henning
Wichtig: sofern vorhanden, gilt im Zweifel immer die (englische) Beschreibung in der commandref!

Auf dieser Seite wird beschrieben, wie man man auf Basis eines Raspberry Pi eine IP-Türsprechstelle baut und in FHEM integriert. Diese ist ein vollwertiger Ersatz für das ältere Projekt DoorPi und FHEM, da dessen Kernsoftware DoorPi nicht mehr weiterentwickelt wird. Das neue Projekt läuft auf derselben Hardware wie das ältere Projekt, ebenso auf der als DoorPiBoard bezeichneten kompakten Platine.

Weitere Bestandteile des Gesamtsystems sind ein Garagentoröffner und eine Hoftür mit selbstverriegelndem Panikschloss. Zur Beschreibung der beiden letztgenannten Teilprojekte verweise ich auf das Buch Smart Home Hacks.

Doorpi all s.png

Funktion

Doorpi block.pngDoorpi completes.pngDoorpi completeb.png

Hardware

Randbedingung des Projektes DoorPa ist, dass es auf derselben Hardware wie DoorPi laufen soll.

Arbeitsaufwand und Kosten

Raspberry Pi

Verwendet wird

  • ein Raspberry Pi 3, der ein integriertes WLAN-Modul besitzt. Falls man seiner eigenen WLAN-Bandbreite nicht traut: Für ca. 25 € bekommt man einen Satz Powerline-Adapter, mit denen man eine sehr stabile Verbindung zwischen dem Raspberry Pi (Innenwand neben der Tür) und dem Rest des Hauses aufbauen kann.
  • eine Zusatzkarte mit jeweils mindestens 8 digitalen Ein- und Ausgängen. Ursprünglich wurde hier das Raspberry Pi-Erweiterungsmodul PiFace 2 verwendet, das neue System lässt sich aber mit ganz unterschiedlicher Hardware aufbauen. Einzige Anforderung an diese Hardware ist, dass beim Betätigen eines der Eingänge (= Verbindung mit GND) in FHEM ein Befehl
set <DoorPa-Device> call call key<Pin-Nummer>

ausgeführt wird

PiFace 2

Auf dem Raspberry Pi läuft ein Mini-Programm als Schleife und löst einen FHEM-Befehl aus, sobald einer der digitalen Eingänge des PiFace 2 betätigt wird. Dieses Mini-Programm ist in Python geschrieben und wird aufgerufen als

 python3 /opt/fhem/pifint.py -d <DoorPa-Device>

Der Quellcode ist dem nachstehenden Listing zu entnehmen.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
########################################################################################
#
# PIFACE event handler pifint.py 
#
# Prof. Dr. Peter A. Henning, 2019
# 
# $Id: pifint.py 2019-06 - pahenning $
#
########################################################################################
#
#  This programm is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  The GNU General Public License can be found at
#  http://www.gnu.org/copyleft/gpl.html.
#  A copy is found in the textfile GPL.txt and important notices to the license
#  from the author is found in LICENSE.txt distributed with these scripts.
#
#  This script is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
########################################################################################
# Attention: ALPHA Software, not to be used for production systems
# place in /etc/rc.local
# as python3 /directory/pifint.py -[i <ip-address>] -d <device> [-k <key>]&
#########################################################################################

import sys, getopt
import pifacedigitalio
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError

ip = '127.0.0.1:8083'
device = ''
key = 'key'

def call_fhem(event):
    url = "http://" + ip + "/fhem?XHR=1&cmd=set%20" + device + "%20call%20" + key + str(event.pin_num)
	#if "@" in url:
    #    nurl = urlparse.urlsplit(url)
    #    username = nurl.username
    #    password = nurl.password
    #    url = url.replace(username + ':' + password + '@', '')
    url = url.replace(" ", "%20")
    try:
       response = urlopen(url)
    except HTTPError as e:
       # do something
       print('Error code: ', e.code)
    except URLError as e:
       # do something
       print('Reason: ', e.reason)
    else:
       # do something
       html = response.read()
    return False
    return False

def main(argv):
   global device
   try:
      opts, args = getopt.getopt(argv,"hi:d:k:",["ip=","device=","key="])
   except getopt.GetoptError:
      print('pifint.py -i <ip-address> -d <device> -k <key>')
      sys.exit(2)
   for opt, arg in opts:
      if opt == '-h':
         print('pifint.py -i <ip-address> -d <device> -k <key>')
         sys.exit()
      elif opt in ("-i", "--ip"):
         ip = arg
      elif opt in ("-d", "--device"):
         device = arg
      elif opt in ("-k", "--key"):
         key = arg
    
   pifacedigital = pifacedigitalio.PiFaceDigital()
   listener = pifacedigitalio.InputEventListener(chip=pifacedigital)
   listener.register(0, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
   listener.register(1, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
   listener.register(2, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
   listener.register(3, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
   listener.register(4, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
   listener.register(5, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
   listener.register(6, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
   listener.register(7, pifacedigitalio.IODIR_FALLING_EDGE, call_fhem)
   listener.activate()
   
if __name__ == "__main__":
   main(sys.argv[1:])

GPIO-Pins des Raspberry Pi

Von der Verwendung der GPIO-Pins des Raspberry Pi rate ich eher ab, da diese über keinen integrierten Schutz verfügen. Fehlerströme und Spannungsspitzen können deshalb gleich die gesamte Hardware lahmlegen.


Software