From a436ff0ad7d17728e6998c14bd35a74b95f0ab95 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 7 Mar 2021 17:07:16 -0700 Subject: [PATCH 1/9] Install requests --- server/requirements.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 server/requirements.txt diff --git a/server/requirements.txt b/server/requirements.txt new file mode 100644 index 0000000..167fbfb --- /dev/null +++ b/server/requirements.txt @@ -0,0 +1,5 @@ +certifi==2020.12.5 +chardet==4.0.0 +idna==2.10 +requests==2.25.1 +urllib3==1.26.3 From bb9e9e6a1185e2655e77496ccd76a25e04096a58 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 7 Mar 2021 17:07:47 -0700 Subject: [PATCH 2/9] Move main.py --- server/{src => }/main.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename server/{src => }/main.py (100%) diff --git a/server/src/main.py b/server/main.py similarity index 100% rename from server/src/main.py rename to server/main.py From 7cc29f6b9fa53fe25a959accb1b4ec1b9df9344d Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 7 Mar 2021 17:22:06 -0700 Subject: [PATCH 3/9] Add gitignore --- server/.gitignore | 103 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 server/.gitignore diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 0000000..4a8da09 --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,103 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# Editor +*.swp +*.swo From c3d83be3c4f33ace8671c3e178a6356ddebabab4 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 7 Mar 2021 17:22:24 -0700 Subject: [PATCH 4/9] Add driver for lights --- server/power.py | 34 ++++++++++++++++++++++++++++++++++ server/settings.py | 7 +++++++ 2 files changed, 41 insertions(+) create mode 100644 server/power.py create mode 100644 server/settings.py diff --git a/server/power.py b/server/power.py new file mode 100644 index 0000000..8ed7a69 --- /dev/null +++ b/server/power.py @@ -0,0 +1,34 @@ +import requests +import settings +import logging +import time + +def np_02B_api(ip, username, password, is_on): + if is_on: + endpoint = '/cmd.cgi?grp=0' + else: + endpoint = '/cmd.cgi?grp=30' + + url = 'http://' + ip + endpoint + r = requests.get(url, auth=(username, password), timeout=4) + r.raise_for_status() + +def lights_on(): + np_02B_api(settings.LIGHT_IP, settings.LIGHT_USER, settings.LIGHT_PASS, True) + +def lights_off(): + np_02B_api(settings.LIGHT_IP, settings.LIGHT_USER, settings.LIGHT_PASS, False) + + +if __name__ == '__main__': + try: + print('Turning lights on...') + lights_on() + + print('Waiting three seconds...') + time.sleep(3) + + print('Turning lights off...') + lights_off() + except BaseException as e: + logging.error('Problem with lights: {} - {}'.format(e.__class__.__name__, str(e))) diff --git a/server/settings.py b/server/settings.py new file mode 100644 index 0000000..d180801 --- /dev/null +++ b/server/settings.py @@ -0,0 +1,7 @@ +LIGHT_IP = '192.168.99.25' +LIGHT_USER = 'admin' +LIGHT_PASS = 'admin' + +GRID_IP = '192.168.99.20' +GRID_USER = 'admin' +GRID_PASS = 'admin' From 2c0c838bdb69be300b32bd6d2fbafcfe56c4cc1c Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 7 Mar 2021 17:24:46 -0700 Subject: [PATCH 5/9] Add driver for grid projectors --- server/power.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/power.py b/server/power.py index 8ed7a69..bddf530 100644 --- a/server/power.py +++ b/server/power.py @@ -19,6 +19,12 @@ def lights_on(): def lights_off(): np_02B_api(settings.LIGHT_IP, settings.LIGHT_USER, settings.LIGHT_PASS, False) +def grid_on(): + np_02B_api(settings.GRID_IP, settings.GRID_USER, settings.GRID_PASS, True) + +def grid_off(): + np_02B_api(settings.GRID_IP, settings.GRID_USER, settings.GRID_PASS, False) + if __name__ == '__main__': try: @@ -32,3 +38,15 @@ if __name__ == '__main__': lights_off() except BaseException as e: logging.error('Problem with lights: {} - {}'.format(e.__class__.__name__, str(e))) + + try: + print('Turning grid on...') + grid_on() + + print('Waiting three seconds...') + time.sleep(3) + + print('Turning grid off...') + grid_off() + except BaseException as e: + logging.error('Problem with grid: {} - {}'.format(e.__class__.__name__, str(e))) From 23f15aed3452d8c11cdd80cde8a114a8fe62ff11 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 7 Mar 2021 18:52:38 -0700 Subject: [PATCH 6/9] Ditch logging module --- server/power.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/power.py b/server/power.py index bddf530..5710e23 100644 --- a/server/power.py +++ b/server/power.py @@ -1,6 +1,5 @@ import requests import settings -import logging import time def np_02B_api(ip, username, password, is_on): @@ -37,7 +36,7 @@ if __name__ == '__main__': print('Turning lights off...') lights_off() except BaseException as e: - logging.error('Problem with lights: {} - {}'.format(e.__class__.__name__, str(e))) + print('Problem with lights: {} - {}'.format(e.__class__.__name__, str(e))) try: print('Turning grid on...') @@ -49,4 +48,4 @@ if __name__ == '__main__': print('Turning grid off...') grid_off() except BaseException as e: - logging.error('Problem with grid: {} - {}'.format(e.__class__.__name__, str(e))) + print('Problem with grid: {} - {}'.format(e.__class__.__name__, str(e))) From d1f527c93b59ff39e29fbd3895569d31a0bfd533 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 7 Mar 2021 18:53:06 -0700 Subject: [PATCH 7/9] Add module to download photos --- server/.gitignore | 2 + server/download.py | 42 +++++++++++++++++++++ server/settings.py | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 server/download.py diff --git a/server/.gitignore b/server/.gitignore index 4a8da09..947f30e 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -101,3 +101,5 @@ ENV/ # Editor *.swp *.swo + +paramiko.log diff --git a/server/download.py b/server/download.py new file mode 100644 index 0000000..5ad784b --- /dev/null +++ b/server/download.py @@ -0,0 +1,42 @@ +import os +import settings +import threading +import paramiko +import time +paramiko.util.log_to_file('paramiko.log') + +def download(ip, dest): + print('Downloading from', ip) + + port = 22 + transport = paramiko.Transport((ip, port)) + transport.connect(None, settings.RASPBERRY_USER, settings.RASPBERRY_PASS) + + sftp = paramiko.SFTPClient.from_transport(transport) + + files = sftp.listdir('/3dscan/') + + for f in files: + source_file = '/3dscan/' + f + dest_file = dest + f + print('Grabbing file', source_file) + sftp.get(source_file, dest_file) + sftp.remove(source_file) + + if sftp: sftp.close() + if transport: transport.close() + + print('Finished downloading from', ip) + +def download_all_photos(dest): + if not dest.endswith('/'): + raise Exception('Destination must end with /') + + if not os.path.exists(dest): + raise Exception('Destination does not exist') + + print('Downloading all photos to', dest) + + for ip in settings.RASPBERRY_IPS: + t = threading.Thread(target=download, args=(ip, dest)) + t.start() diff --git a/server/settings.py b/server/settings.py index d180801..648a02c 100644 --- a/server/settings.py +++ b/server/settings.py @@ -5,3 +5,97 @@ LIGHT_PASS = 'admin' GRID_IP = '192.168.99.20' GRID_USER = 'admin' GRID_PASS = 'admin' + +RASPBERRY_USER = 'root' +RASPBERRY_PASS = '3dscan' +RASPBERRY_IPS = [ + '192.168.99.101', + '192.168.99.103', + '192.168.99.104', + '192.168.99.105', + '192.168.99.106', + '192.168.99.107', + '192.168.99.108', + '192.168.99.109', + '192.168.99.110', + '192.168.99.111', + '192.168.99.112', + '192.168.99.113', + '192.168.99.114', + '192.168.99.115', + '192.168.99.116', + '192.168.99.117', + '192.168.99.118', + '192.168.99.119', + '192.168.99.120', + '192.168.99.121', + '192.168.99.122', + '192.168.99.123', + '192.168.99.124', + '192.168.99.125', + '192.168.99.126', + '192.168.99.127', + '192.168.99.128', + '192.168.99.129', + '192.168.99.130', + '192.168.99.131', + '192.168.99.132', + '192.168.99.133', + '192.168.99.134', + '192.168.99.135', + '192.168.99.136', + '192.168.99.137', + '192.168.99.138', + '192.168.99.139', + '192.168.99.140', + '192.168.99.141', + '192.168.99.142', + '192.168.99.143', + '192.168.99.144', + '192.168.99.145', + '192.168.99.146', + '192.168.99.147', + '192.168.99.148', + '192.168.99.149', + '192.168.99.150', + '192.168.99.151', + '192.168.99.152', + '192.168.99.153', + '192.168.99.154', + '192.168.99.155', + '192.168.99.156', + '192.168.99.157', + '192.168.99.158', + '192.168.99.159', + '192.168.99.160', + '192.168.99.161', + '192.168.99.162', + '192.168.99.163', + '192.168.99.164', + '192.168.99.165', + '192.168.99.166', + '192.168.99.167', + '192.168.99.168', + '192.168.99.169', + '192.168.99.170', + '192.168.99.171', + '192.168.99.172', + '192.168.99.173', + '192.168.99.174', + '192.168.99.175', + '192.168.99.176', + '192.168.99.177', + '192.168.99.178', + '192.168.99.179', + '192.168.99.180', + '192.168.99.181', + '192.168.99.182', + '192.168.99.183', + '192.168.99.184', + '192.168.99.185', + '192.168.99.191', + '192.168.99.192', + '192.168.99.193', + '192.168.99.194', + '192.168.99.195', +] From ba63fcaf01b83a1f770058517c75006af07a6ee2 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 7 Mar 2021 19:16:14 -0700 Subject: [PATCH 8/9] Add module to trigger a capture --- server/capture.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 server/capture.py diff --git a/server/capture.py b/server/capture.py new file mode 100644 index 0000000..262e14e --- /dev/null +++ b/server/capture.py @@ -0,0 +1,30 @@ +import socket +import sys +import time + +# make sure multicast is being routed to the right interface ie. +# sudo route add -net 224.0.0.0 netmask 240.0.0.0 dev enx00249b649e67 + +def trigger_capture(): + charid = 1 + unitid = 1 + groupid = 1 + + gtdate = time.gmtime() + now = str(gtdate.tm_year) + str(gtdate.tm_mon) + str(gtdate.tm_mday) + str(gtdate.tm_hour) + str(gtdate.tm_min) + str(gtdate.tm_sec) + + SDATA = str(now) + + print('Sending: ' + SDATA) + MCAST_GRP = '224.1.1.1' + MCAST_PORT = 5007 + SCMD = chr(charid) + SUNIT = chr(unitid) + SGROUP = chr(groupid) + SEND = SCMD+SUNIT+SGROUP+SDATA + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) + dev = 'eth0' + '\0' + sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) + sock.sendto(SEND.encode('utf-8'), (MCAST_GRP, MCAST_PORT)) + sock.close() + print('Sent.') From 026913013a903d950fcb28dc830c8e7ff7001227 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 7 Mar 2021 19:16:35 -0700 Subject: [PATCH 9/9] Install Flask and serve index.html --- client/build/index.html | 1 + server/main.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 client/build/index.html diff --git a/client/build/index.html b/client/build/index.html new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/client/build/index.html @@ -0,0 +1 @@ +hello world diff --git a/server/main.py b/server/main.py index 3baf8a9..aabbdd4 100644 --- a/server/main.py +++ b/server/main.py @@ -1,3 +1,12 @@ -import socket -import sys -import time +from flask import Flask +from flask_cors import CORS + +build_folder = '../client/build' +app = Flask(__name__, static_folder=build_folder, static_url_path='') +CORS(app) + +@app.route('/') +def index(): + return app.send_static_file('index.html') + +app.run()