diff --git a/README.md b/README.md index e3823a5..49993b3 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,12 @@ You need just to run `make`. Additional dependencies: - [SWIG](http://www.swig.org/) - [WiringPi2 pythonic binding](https://github.com/WiringPi/WiringPi2-Python) (for switching lock on Raspberry) - [python-irc](https://pypi.python.org/pypi/irc) >= 16.0, use "pip install irc", the one in repos is old +- [pysftp](https://pypi.org/project/pysftp/) - for uploading SpaceAPI-formatted status to some host All dependencies can be installed on Ubuntu or Debian/Raspbian via: apt install libnfc-dev libfreefare-bin libfreefare-dev python-axolotl-curve25519 swig2.0 python-dev - pip install irc wiringpi2 + pip install irc wiringpi2 pysftp To build, just run make: diff --git a/brmdoor_nfc.config.sample b/brmdoor_nfc.config.sample index 6f3d25d..761de85 100644 --- a/brmdoor_nfc.config.sample +++ b/brmdoor_nfc.config.sample @@ -66,7 +66,28 @@ reconnect_delay = 300 # fi # # python -c "import wiringpi; wiringpi.wiringPiSetupGpio(); wiringpi.pinMode($PIN, wiringpi.INPUT); wiringpi.pullUpDnControl($PIN, wiringpi.PUD_UP)" +# +# SpaceAPI upload is to upload JSON-formatted status to a SFTP server where it can be hosted via web. +# +# spaceapi_status_upload = True/False whether to use SFTP upload +# spaceapi_sftp_host = hostname where to upload the key +# spaceapi_sftp_port = port of sftp server +# spaceapi_sftp_username = username for the sftp server +# spaceapi_sftp_key = full path to SFTP (SSH) key +# spaceapi_dest_file = path relative to SFTP root, including final the filename (it's recommended to use chroot with internal-sftp) +# spaceapi_template_file = full path to JSON template file, where status (open/closed) will be added +# +# Note: for sftp upload to work, you need to have the server in ~/.ssh/known_hosts, otherwise you'll get exception + enabled = False status_file = /sys/class/gpio/gpio22/value open_value = 0 +spaceapi_status_upload = False +spaceapi_sftp_host = some.fqdn.com +spaceapi_sftp_port = 22 +spaceapi_sftp_username = brmdoor-web +spaceapi_sftp_key = /path/to/key +spaceapi_dest_filen= /path/on/target/host/to/dest/file +spaceapi_template_file = /full/path/to/spaceapi_template.json + diff --git a/brmdoor_nfc_daemon.py b/brmdoor_nfc_daemon.py index e3e8eeb..57f2ba1 100755 --- a/brmdoor_nfc_daemon.py +++ b/brmdoor_nfc_daemon.py @@ -71,6 +71,14 @@ class BrmdoorConfig(object): if self.useOpenSwitch: self.switchStatusFile = self.config.get("open_switch", "status_file") self.switchOpenValue = self.config.get("open_switch", "open_value") + self.useStatusUpload = self.config.getboolean("open_switch", "spaceapi_status_upload ") + if self.useStatusUpload: + self.sftpHost = self.config.get("open_switch", "spaceapi_sftp_host") + self.sftpPort= self.config.getint("open_switch", "spaceapi_sftp_port") + self.sftpUsername = self.config.get("open_switch", "spaceapi_sftp_username") + self.sftpKey = self.config.get("open_switch", "spaceapi_sftp_key") + self.sftpDestFile = self.config.get("open_switch", "spaceapi_sftp_key") + self.sftpTemplateFile = self.config.get("open_switch", "spaceapi_template_file") def convertLoglevel(self, levelString): """Converts string 'debug', 'info', etc. into corresponding @@ -355,6 +363,14 @@ class IrcThread(threading.Thread): logging.exception("Exception in IRC thread") time.sleep(self.reconnectDelay) +class SpaceAPIUploader(object): + """ + Class for uploading JSON-formatted SpaceAPI status via SFTP + """ + + def __init__(self, config): + pass + class OpenSwitchThread(threading.Thread): """ Class for watching OPEN/CLOSED switch that diff --git a/spaceapi_template.json b/spaceapi_template.json new file mode 100644 index 0000000..d20b500 --- /dev/null +++ b/spaceapi_template.json @@ -0,0 +1,17 @@ +{ + "api": "0.13", + "space": "Brmlab", + "logo": "https://brmlab.cz/brmlab.png", + "url": "https://brmlab.cz/", + "location": { + "address": "Pod Kaplickou 3149/18, 13000 Praha 3", + "lon": 50.08346, + "lat": 14.48032 + }, + "contact": { + "irc": "irc://freenode.net/#brmlab", + "phone": "+420 608 801 582", + "facebook": "https://www.facebook.com/brmlab", + "ml": "brmlab@brmlab.cz" + } +}