146 lines
3.7 KiB
Python
146 lines
3.7 KiB
Python
__author__ = 'asc'
|
|
DEBUG = True
|
|
import logging
|
|
|
|
if DEBUG:
|
|
from instruments import Barometer_Debug2 as Barometer
|
|
from instruments import Camera_Debug2 as Camera
|
|
from datahandling import Datalogger_Debug as Datalogger
|
|
from datahandling import Datareporter_Debug3 as Datareporter
|
|
from system import System_Debug as System
|
|
import threading
|
|
|
|
import datetime
|
|
|
|
import configparser
|
|
|
|
# logging.basicConfig(level=logging.DEBUG, format=("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
|
|
# log = logging.getLogger("instruments")
|
|
# log.setLevel(logging.DEBUG)
|
|
# log.
|
|
# # log.setFo
|
|
|
|
log = logging.getLogger(__name__)
|
|
log1 = logging.getLogger("instruments")
|
|
log2 = logging.getLogger("datahandling")
|
|
handler = logging.FileHandler('myapp.log')
|
|
|
|
formatter = logging.Formatter('[%(asctime)-15s] %(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)
|
|
|
|
#start-up
|
|
#log denotes write to local, report denotes sending to server
|
|
|
|
#TODO startup message
|
|
|
|
#loadconfig
|
|
from config import *
|
|
|
|
notebook = Datalogger (text_path=None,
|
|
log_path=log_path,
|
|
photo_path=photo_path)
|
|
log.debug ("System started")
|
|
# logger.log("Log Intiated")
|
|
|
|
#system check
|
|
system = System()
|
|
|
|
log.debug (system.stats)
|
|
|
|
#todo test cell connection
|
|
reporter = Datareporter (
|
|
use_lan = True,
|
|
url = "http://home.ascorrea.com",
|
|
server_port = 5010,
|
|
data_path = "upload-data",
|
|
image_path = "upload-file",
|
|
ping_path = "ping",
|
|
com_port_name="/dev/ttyAMA0",
|
|
baud_rate = 9600)
|
|
|
|
#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=True,
|
|
hflip=True,
|
|
exposure_mode='sports'
|
|
)
|
|
|
|
|
|
#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()
|
|
notebook.log(bar, message_type="data")
|
|
|
|
def update_image_local():
|
|
global img
|
|
img = camera.capture()
|
|
notebook.log(img.get('hi'), message_type="image")
|
|
|
|
|
|
scheduler(2, update_barometer_local)
|
|
scheduler(5, update_image_local)
|
|
|
|
counter=1
|
|
while counter>0:
|
|
global img
|
|
global bar
|
|
# bar=None
|
|
# img=None
|
|
|
|
try:
|
|
reporter.send(1, message_type="ping")
|
|
|
|
# if (counter % refresh_camera_local) == 0:
|
|
# if not img:
|
|
# img = camera.capture()
|
|
# notebook.log(img.get('hi'), message_type="image")
|
|
|
|
if (counter % refresh_barometer_transmit) == 0:
|
|
if not bar:
|
|
bar = barometer.read()
|
|
reporter.send(bar, message_type="data")
|
|
|
|
if (counter % refresh_camera_transmit) == 0:
|
|
# log.debug('Need to transmit picture, {}'.format(img))
|
|
if not img:
|
|
img = camera.capture()
|
|
reporter.send(img.get('lo'), message_type="image")
|
|
|
|
if (counter % refresh_system) == 0:
|
|
log.debug(system.stats)
|
|
|
|
except Exception as e:
|
|
log.debug("Exception: {}".format(e))
|
|
continue
|
|
|
|
counter += 1
|
|
log.debug("Counter = {}".format(counter))
|
|
|
|
pass
|