commit to present
This commit is contained in:
@@ -12,7 +12,7 @@ refresh system = 10
|
|||||||
|
|
||||||
[camera settings]
|
[camera settings]
|
||||||
low quality resolution = (320, 240)
|
low quality resolution = (320, 240)
|
||||||
low quality compression pct = 10
|
low quality compression pct = 7
|
||||||
high quality resolution = (2592,1944)
|
high quality resolution = (2592,1944)
|
||||||
high quality compression pct = 100
|
high quality compression pct = 100
|
||||||
|
|
||||||
|
|||||||
@@ -98,13 +98,20 @@ class Datalogger():
|
|||||||
logger.info('item is {}'.format(type(item)))
|
logger.info('item is {}'.format(type(item)))
|
||||||
filename = item[0]
|
filename = item[0]
|
||||||
file = base64.b64decode(bytes(item[1],'ascii'))
|
file = base64.b64decode(bytes(item[1],'ascii'))
|
||||||
|
|
||||||
|
folder = os.path.join(self.photo_path, self._mt.mid)
|
||||||
|
file_path = os.path.join(self.photo_path, folder , filename)
|
||||||
|
|
||||||
|
if not os.path.exists(folder):
|
||||||
|
os.makedirs(folder)
|
||||||
|
|
||||||
with open(os.path.join(self.photo_path, filename), 'wb') as f:
|
with open(os.path.join(self.photo_path, filename), 'wb') as f:
|
||||||
f.write(file)
|
f.write(file)
|
||||||
# file.save(os.path.join(self.photo_path, filename))
|
# file.save(os.path.join(self.photo_path, filename))
|
||||||
|
|
||||||
return 'success'
|
return 'success'
|
||||||
|
|
||||||
class Datareporter():
|
class Datareporter():
|
||||||
#Debug 2 sends from cell to server
|
|
||||||
from lib.sim900.inetgsm import SimInetGSM
|
from lib.sim900.inetgsm import SimInetGSM
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
@@ -262,21 +269,6 @@ class Record():
|
|||||||
def _get_dict(self):
|
def _get_dict(self):
|
||||||
return self._transpondence
|
return self._transpondence
|
||||||
|
|
||||||
# def send(self):
|
|
||||||
# # self._transpondence['mid'] = m.name
|
|
||||||
# # self._transpondence['mt'] = m.now()
|
|
||||||
# # print ('Send transpondence {}'.format(self._transpondence))
|
|
||||||
#
|
|
||||||
# for k in self._transpondence.keys():
|
|
||||||
# if self._transpondence[k] is not str: #basically, check if image
|
|
||||||
# self._transpondence[k] = json.dumps(self._transpondence[k])
|
|
||||||
#
|
|
||||||
# r = self._send(message=self._transpondence, message_type='transpondence')
|
|
||||||
#
|
|
||||||
# #On error, do not clear transpondence
|
|
||||||
# if not r:
|
|
||||||
# self._transpondence = None
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class Camera:
|
|||||||
self._cam.capture("temp_img_hi.jpg",
|
self._cam.capture("temp_img_hi.jpg",
|
||||||
resize=self.high_quality_resolution,
|
resize=self.high_quality_resolution,
|
||||||
quality=self.high_quality_compression_pct,
|
quality=self.high_quality_compression_pct,
|
||||||
# **kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
with open("temp_img_hi.jpg", 'rb') as f:
|
with open("temp_img_hi.jpg", 'rb') as f:
|
||||||
# img_hi = base64.b64encode(f.read())
|
# img_hi = base64.b64encode(f.read())
|
||||||
@@ -64,7 +64,7 @@ class Camera:
|
|||||||
self._cam.capture("temp_img_lo.jpg",
|
self._cam.capture("temp_img_lo.jpg",
|
||||||
resize=self.low_quality_resolution,
|
resize=self.low_quality_resolution,
|
||||||
quality=self.low_quality_compression_pct,
|
quality=self.low_quality_compression_pct,
|
||||||
# **kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
with open("temp_img_lo.jpg", 'rb') as f:
|
with open("temp_img_lo.jpg", 'rb') as f:
|
||||||
img_lo = str(base64.b64encode(f.read()),'ascii')
|
img_lo = str(base64.b64encode(f.read()),'ascii')
|
||||||
@@ -139,6 +139,56 @@ class Barometer:
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
class Gps:
|
||||||
|
def __init__(self):
|
||||||
|
logger.debug("Intializing GPS")
|
||||||
|
# self.bmp = BMP085.BMP085()
|
||||||
|
logger.debug("Gps intilized")
|
||||||
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
def status (self):
|
||||||
|
return (0, "Barometer functioning properly")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def temperature (self):
|
||||||
|
if self.status[0]:
|
||||||
|
return 'error'
|
||||||
|
|
||||||
|
temp = self.bmp.read_temperature()
|
||||||
|
return temp
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pressure (self):
|
||||||
|
if (self.status[0]):
|
||||||
|
return 'error'
|
||||||
|
|
||||||
|
# press = 100000*random()
|
||||||
|
press = self.bmp.read_pressure()
|
||||||
|
|
||||||
|
return press
|
||||||
|
|
||||||
|
@property
|
||||||
|
def altitude (self):
|
||||||
|
if self.status[0]:
|
||||||
|
return 'error'
|
||||||
|
#TODO Set the altitude of your current location in meter
|
||||||
|
alt = self.bmp.read_altitude()
|
||||||
|
return alt
|
||||||
|
|
||||||
|
def read(self):
|
||||||
|
logger.debug("Reading from barometer")
|
||||||
|
#refresh each instrument
|
||||||
|
alt = self.altitude
|
||||||
|
press = self.pressure
|
||||||
|
temp = self.temperature
|
||||||
|
result = {"a":alt,
|
||||||
|
"t":temp,
|
||||||
|
"p":press,
|
||||||
|
}
|
||||||
|
logger.debug("Gps reads {}".format(result))
|
||||||
|
|
||||||
|
return result
|
||||||
# class Gps:
|
# class Gps:
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
main.py
11
main.py
@@ -40,9 +40,9 @@ mission = Mission()
|
|||||||
#todo test cell connection
|
#todo test cell connection
|
||||||
reporter = Datareporter (
|
reporter = Datareporter (
|
||||||
missiontime = mission,
|
missiontime = mission,
|
||||||
use_lan = False,
|
use_lan = True,
|
||||||
url = "http://spaceballoon-server.herokuapp.com",
|
url = "http://home.ascorrea.com",
|
||||||
server_port = 80,
|
server_port = 5010,
|
||||||
data_path = "upload-data",
|
data_path = "upload-data",
|
||||||
image_path = "missions",
|
image_path = "missions",
|
||||||
ping_path = "ping",
|
ping_path = "ping",
|
||||||
@@ -84,7 +84,7 @@ camera = Camera (low_quality_compression_pct=low_quality_compression_pct,
|
|||||||
high_quality_compression_pct=high_quality_compression_pct,
|
high_quality_compression_pct=high_quality_compression_pct,
|
||||||
high_quality_resolution=high_quality_resolution,
|
high_quality_resolution=high_quality_resolution,
|
||||||
vflip=False,
|
vflip=False,
|
||||||
hflip=True,
|
hflip=False,
|
||||||
exposure_mode='sports',
|
exposure_mode='sports',
|
||||||
# debug=True
|
# debug=True
|
||||||
)
|
)
|
||||||
@@ -128,12 +128,9 @@ def submit_report():
|
|||||||
# reporter.create_transpondence()
|
# reporter.create_transpondence()
|
||||||
|
|
||||||
if not transpondence:
|
if not transpondence:
|
||||||
log.info("type of transpondence is {}".format(type(transpondence)))
|
|
||||||
transpondence = Record()
|
transpondence = Record()
|
||||||
log.info("type of transpondence is {} and is {}".format(type(transpondence), transpondence))
|
|
||||||
|
|
||||||
if (counter % refresh_barometer_transmit) == 0:
|
if (counter % refresh_barometer_transmit) == 0:
|
||||||
log.info("type of transpondence is {} and is {}".format(type(transpondence), transpondence))
|
|
||||||
transpondence.add(bar,'b')
|
transpondence.add(bar,'b')
|
||||||
|
|
||||||
if (counter % refresh_camera_transmit) == 0:
|
if (counter % refresh_camera_transmit) == 0:
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Mission():
|
|||||||
def now(self):
|
def now(self):
|
||||||
#returns a string
|
#returns a string
|
||||||
d=datetime.datetime.now()-self._zero
|
d=datetime.datetime.now()-self._zero
|
||||||
return str(d.total_seconds())
|
return d.total_seconds()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def timezero(self):
|
def timezero(self):
|
||||||
|
|||||||
144
test.py
144
test.py
@@ -1,68 +1,110 @@
|
|||||||
import csv, requests
|
__author__ = 'asc'
|
||||||
from instruments import Camera
|
DEBUG = True
|
||||||
from datahandling import Datareporter
|
|
||||||
from system import System
|
|
||||||
import serial
|
|
||||||
import sys
|
|
||||||
import logging
|
import logging
|
||||||
import base64
|
import logging.handlers,logging.config
|
||||||
from requests_toolbelt import MultipartEncoder
|
|
||||||
from time import sleep
|
|
||||||
from logging import config
|
|
||||||
|
|
||||||
config.fileConfig('logging.ini')
|
from instruments import Barometer, Camera
|
||||||
logging.getLogger("inetgsm")
|
from datahandling import Datalogger, Datareporter
|
||||||
|
from system import System as System
|
||||||
|
import threading
|
||||||
|
from datahandling import Record
|
||||||
|
from mission import Mission
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
data = {"temp":1,"press":3,"altitude":2,"cheetas":"just enough"}
|
logging.config.fileConfig('logging.ini')
|
||||||
|
|
||||||
pass
|
log = logging.getLogger(__name__)
|
||||||
|
# log = logging.basicConfig()
|
||||||
|
# log1 = logging.getLogger("instruments")
|
||||||
|
# log2 = logging.getLogger("datahandling")
|
||||||
|
# handler = logging.handlers.RotatingFileHandler('spaceballoon.log', backupCount=5)
|
||||||
|
|
||||||
com_port_name = "/dev/ttyAMA0"
|
formatter = logging.Formatter('[%(asctime)-25s] %(name)-15s %(levelname)-8s %(message)s')
|
||||||
|
# handler.setFormatter(formatter)
|
||||||
|
# log.addHandler(handler)
|
||||||
|
# log1.addHandler(handler)
|
||||||
|
# log2.addHandler(handler)
|
||||||
|
log.setLevel(logging.DEBUG)
|
||||||
|
# log1.setLevel(logging.DEBUG)
|
||||||
|
# log2.setLevel(logging.INFO)
|
||||||
|
|
||||||
image = open("resized_image.jpg", 'rb')
|
#start-up
|
||||||
image = image.read()
|
#log denotes write to local, report denotes sending to server
|
||||||
# image = image.read()
|
|
||||||
|
|
||||||
# e=base64.b64encode(image)
|
#loadconfig
|
||||||
|
from config import *
|
||||||
|
|
||||||
# e=b'alksdjnfkljanslkjnaklsfnglkanlkfgnlakalksdjnaklsfnglkajnaklsfnglkanlkfgnlakalksdjnfkljanslkjnglkjnaklsfnglkanlkfgnlakalksdjnfkljanslkjnglknlkfgnlakalksdjnfkljanslkjnglkanlkfgnlakalksdjnfkljanngnlakalksdjnfkljanslkjnglkanlkfgnlakalksdjnfkljannlkanlkfgnlakalksdjnfkljannglkanlkfgnlakalksdjnfkljannglkanlkfgnlakalksdjnfkl=='
|
mission = Mission()
|
||||||
|
|
||||||
# m = MultipartEncoder(fields={'image': ('image', image, 'image/jpeg')})
|
#todo test cell connection
|
||||||
|
reporter = Datareporter (
|
||||||
report = Datareporter (
|
missiontime = mission,
|
||||||
# use_lan = True,
|
use_lan = True,
|
||||||
url = "http://home.ascorrea.com",
|
url = "http://10.0.1.4",
|
||||||
server_port = 5010,
|
server_port = 5010,
|
||||||
data_path = "upload-data",
|
data_path = "upload-data",
|
||||||
image_path = "upload-file",
|
image_path = "missions",
|
||||||
|
ping_path = "ping",
|
||||||
com_port_name="/dev/ttyAMA0",
|
com_port_name="/dev/ttyAMA0",
|
||||||
ping_path="ping",
|
baud_rate = 9600
|
||||||
baud_rate = 9600)
|
)
|
||||||
|
|
||||||
# camera = Camera (low_quality_compression_pct=10,
|
#intiate mission
|
||||||
# low_quality_resolution=(320, 240),
|
|
||||||
# high_quality_compression_pct=100,
|
|
||||||
# high_quality_resolution=(2592,1944),
|
|
||||||
# vflip=True,
|
|
||||||
# hflip=True,
|
|
||||||
# # exposure_mode='sports'
|
|
||||||
# )
|
|
||||||
|
|
||||||
# print (report.check())
|
|
||||||
# print (image)
|
|
||||||
# report.send(m.to_string(), message_type="image")
|
|
||||||
# report.send(data, message_type="data")
|
|
||||||
|
|
||||||
# img = camera.capture()
|
|
||||||
# report.send(img.get('lo'), message_type="image")
|
|
||||||
|
|
||||||
# report.send(image, message_type="image")
|
|
||||||
|
|
||||||
|
|
||||||
# execfile("test_sms.py")
|
#TODO test camera
|
||||||
for i in range(1,10):
|
camera = Camera (low_quality_compression_pct=low_quality_compression_pct,
|
||||||
print (i)
|
low_quality_resolution=low_quality_resolution,
|
||||||
report.send(image,message_type="image")
|
high_quality_compression_pct=high_quality_compression_pct,
|
||||||
sleep(1)
|
high_quality_resolution=high_quality_resolution,
|
||||||
|
vflip=False,
|
||||||
|
hflip=False,
|
||||||
|
exposure_mode='sports',
|
||||||
|
# debug=True
|
||||||
|
)
|
||||||
|
|
||||||
|
#todo test barometer
|
||||||
|
barometer = Barometer()
|
||||||
|
|
||||||
|
#todo test GPS, log, report
|
||||||
|
|
||||||
|
#todo check for errors, throw exception if error
|
||||||
|
|
||||||
|
def scheduler (interval, worker_func, iterations = 0):
|
||||||
|
if iterations != 1:
|
||||||
|
threading.Timer (
|
||||||
|
interval,
|
||||||
|
scheduler, [interval, worker_func, 0 if iterations == 0 else iterations-1]
|
||||||
|
).start ()
|
||||||
|
|
||||||
|
worker_func ()
|
||||||
|
|
||||||
|
|
||||||
|
def update_barometer_local():
|
||||||
|
global bar
|
||||||
|
bar = barometer.read()
|
||||||
|
bar.update({'mt':mission.now()})
|
||||||
|
record = Record(bar.copy(),'b')
|
||||||
|
# notebook.log(record)
|
||||||
|
|
||||||
|
def update_image_local():
|
||||||
|
global img
|
||||||
|
img = camera.capture(name=mission.now(), thumbnail=None)
|
||||||
|
record = Record([img.get('hi'), img.get('lo')], 'i')
|
||||||
|
# notebook.log(record)
|
||||||
|
|
||||||
|
transpondence = Record()
|
||||||
|
|
||||||
|
update_image_local()
|
||||||
|
|
||||||
|
transpondence.add(img.get('lo'),'i')
|
||||||
|
transpondence = reporter.send(transpondence) #returns none on success, (bad practice?)
|
||||||
|
|
||||||
|
counter=1
|
||||||
|
|
||||||
|
img = None
|
||||||
|
bar = None
|
||||||
|
transpondence = None
|
||||||
|
|
||||||
pass
|
pass
|
||||||
Reference in New Issue
Block a user