diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6508e9a --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +### Python ### +*__pycache__/ + +### Configs ### +camera/config.py +api/config.py 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..8fdcceb 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, headers={'Authorization': 'Basic ' + config.config['key']}) + 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.')