This commit is contained in:
Trygve 2022-01-21 12:13:25 +01:00
commit 62c0fe857b
3 changed files with 33 additions and 5 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
### Python ###
*__pycache__/
### Configs ###
camera/config.py
api/config.py

3
camera/config.py Normal file
View File

@ -0,0 +1,3 @@
config = {
'uploadurl': 'http://10.10.40.2:5000/post_img'
}

View File

@ -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.')