From 1cb602f024e67e0668f75f96f45cc1b22151d1bc Mon Sep 17 00:00:00 2001 From: Trygve Date: Wed, 19 Jan 2022 19:01:20 +0100 Subject: [PATCH 1/3] =?UTF-8?q?N=C3=A5=20tar=20den=20bilde=20med=20termux.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- camera/__pycache__/config.cpython-310.pyc | Bin 0 -> 213 bytes camera/config.py | 3 +++ camera/upload_img.py | 29 ++++++++++++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 camera/__pycache__/config.cpython-310.pyc create mode 100644 camera/config.py diff --git a/camera/__pycache__/config.cpython-310.pyc b/camera/__pycache__/config.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7a9a4dd25e7ca1b49ffa0e897abd2aa91dd20e84 GIT binary patch literal 213 zcmd1j<>g`k0&Bk)i7r6;F^Gc(44TZhI7#6Zu;%GAKXK))crxFkL^H{DN@@fKTheqLH;`bvf(W}sPM z;+L&{N@7VOghi_@% literal 0 HcmV?d00001 diff --git a/camera/config.py b/camera/config.py new file mode 100644 index 0000000..bf916fe --- /dev/null +++ b/camera/config.py @@ -0,0 +1,3 @@ +config = { + 'uploadurl': 'http://10.10.40.2:5000/post_img' +} diff --git a/camera/upload_img.py b/camera/upload_img.py index ca6f42d..b9b3ed3 100644 --- a/camera/upload_img.py +++ b/camera/upload_img.py @@ -1,10 +1,29 @@ from flask import Flask, request, jsonify import requests +import subprocess +import time +import logging -url = 'http://10.10.40.2:5000/post_img' -my_img = {'image': open('test.png', 'rb')} -r = requests.post(url, files=my_img) +import config +logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO) -# convert server response into JSON format. -print(r.json()) +try: + start = time.time() + picturecmd=subprocess.Popen("termux-camera-photo -c 0 latest.jpg", shell=True) + picturecmd.communicate() + end = time.time() +except Exception as e: + logging.info('Feil under fotografering: {0}'.format(e)) +else: + logging.info('Det tok '+ str(end-start) +'s å ta bilde.') +try: + start = time.time() + img = {'image': open('latest.jpg', 'rb')} + response = requests.post(config.config['uploadurl'], files=img) + end = time.time() +except Exception as e: + logging.info('Feil under opplasting: {0}'.format(e)) +else: + print(response.json()) + logging.info('Det tok '+ str(end-start) +'s å sende bildet.') From fe9da5ba89f7bc3f80cfe28b67fc6ee5adf38722 Mon Sep 17 00:00:00 2001 From: Trygve Date: Wed, 19 Jan 2022 19:05:57 +0100 Subject: [PATCH 2/3] La til .gitignore --- .gitignore | 2 ++ camera/__pycache__/config.cpython-310.pyc | Bin 213 -> 0 bytes 2 files changed, 2 insertions(+) create mode 100644 .gitignore delete mode 100644 camera/__pycache__/config.cpython-310.pyc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f574e4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +### Python ### +*__pycache__/ diff --git a/camera/__pycache__/config.cpython-310.pyc b/camera/__pycache__/config.cpython-310.pyc deleted file mode 100644 index 7a9a4dd25e7ca1b49ffa0e897abd2aa91dd20e84..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 213 zcmd1j<>g`k0&Bk)i7r6;F^Gc(44TZhI7#6Zu;%GAKXK))crxFkL^H{DN@@fKTheqLH;`bvf(W}sPM z;+L&{N@7VOghi_@% From 72fb716199a03679cd2a1739cf3074a44195f956 Mon Sep 17 00:00:00 2001 From: Trygve Date: Fri, 21 Jan 2022 11:58:39 +0100 Subject: [PATCH 3/3] La til autentikasjon i klienten --- .gitignore | 4 ++++ camera/upload_img.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0f574e4..6508e9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ ### Python ### *__pycache__/ + +### Configs ### +camera/config.py +api/config.py diff --git a/camera/upload_img.py b/camera/upload_img.py index b9b3ed3..8fdcceb 100644 --- a/camera/upload_img.py +++ b/camera/upload_img.py @@ -20,7 +20,7 @@ else: try: start = time.time() img = {'image': open('latest.jpg', 'rb')} - response = requests.post(config.config['uploadurl'], files=img) + response = requests.post(config.config['uploadurl'], files=img, headers={'Authorization': 'Basic ' + config.config['key']}) end = time.time() except Exception as e: logging.info('Feil under opplasting: {0}'.format(e))