commit to present

This commit is contained in:
2015-11-12 23:14:03 -06:00
parent 1b569da791
commit e813c71f7c
6 changed files with 160 additions and 79 deletions

146
test.py
View File

@@ -1,68 +1,110 @@
import csv, requests
from instruments import Camera
from datahandling import Datareporter
from system import System
import serial
import sys
__author__ = 'asc'
DEBUG = True
import logging
import base64
from requests_toolbelt import MultipartEncoder
from time import sleep
from logging import config
import logging.handlers,logging.config
config.fileConfig('logging.ini')
logging.getLogger("inetgsm")
from instruments import Barometer, Camera
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')
image = image.read()
# image = image.read()
#start-up
#log denotes write to local, report denotes sending to server
# e=base64.b64encode(image)
#loadconfig
from config import *
# e=b'alksdjnfkljanslkjnaklsfnglkanlkfgnlakalksdjnaklsfnglkajnaklsfnglkanlkfgnlakalksdjnfkljanslkjnglkjnaklsfnglkanlkfgnlakalksdjnfkljanslkjnglknlkfgnlakalksdjnfkljanslkjnglkanlkfgnlakalksdjnfkljanngnlakalksdjnfkljanslkjnglkanlkfgnlakalksdjnfkljannlkanlkfgnlakalksdjnfkljannglkanlkfgnlakalksdjnfkljannglkanlkfgnlakalksdjnfkl=='
mission = Mission()
# m = MultipartEncoder(fields={'image': ('image', image, 'image/jpeg')})
report = Datareporter (
# use_lan = True,
url = "http://home.ascorrea.com",
#todo test cell connection
reporter = Datareporter (
missiontime = mission,
use_lan = True,
url = "http://10.0.1.4",
server_port = 5010,
data_path = "upload-data",
image_path = "upload-file",
image_path = "missions",
ping_path = "ping",
com_port_name="/dev/ttyAMA0",
ping_path="ping",
baud_rate = 9600)
baud_rate = 9600
)
# camera = Camera (low_quality_compression_pct=10,
# 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")
#intiate mission
# execfile("test_sms.py")
for i in range(1,10):
print (i)
report.send(image,message_type="image")
sleep(1)
#TODO test camera
camera = Camera (low_quality_compression_pct=low_quality_compression_pct,
low_quality_resolution=low_quality_resolution,
high_quality_compression_pct=high_quality_compression_pct,
high_quality_resolution=high_quality_resolution,
vflip=False,
hflip=False,
exposure_mode='sports',
# debug=True
)
pass
#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