Commit ce2015e1 authored by Nelso Jost's avatar Nelso Jost

FIX: better genaral usage from single Makefile

parent 995c2c8b
.venv/
ino/src
ino/lib
.ino
*.pyc
*.swp
*.csv
......
PY := 2
PYVER := 3
VENV := .venv
all: help
......@@ -6,7 +6,7 @@ all: help
help:
@ echo "USAGE"
@ echo ""
@ echo " make apt-install -- Uses apt to install system tools"
@ echo " make apt-install -- Uses Debian's apt to install required system tools"
@ echo ""
@ echo " make setup -- Install Python requirements"
@ echo ""
......@@ -14,23 +14,37 @@ help:
@ echo ""
@ echo " make upload -- Send the compiled sketch to the board"
@ echo ""
@ echo " make bus -- build & upload & start serial picocom"
@ echo " make serial -- Enter IPython session with serial opened"
@ echo ""
@ echo " make serial -- Starts a picocom serial communication"
@ echo " make bu -- build & upload"
@ echo " make bus -- build & upload & serial"
@ echo ""
@ echo " make list-models -- List possible Arduino models for ino.ini"
@ echo " make sync-rtc -- Synchronizes the board's clock with the system's"
@ echo ""
@ echo " make run-logger -- Starts the logger. Results apper on the screen."
@ echo ""
@ echo " make deploy-logger -- Activate logger daemon. Results apper on logs/execution.log"
@ echo ""
@ echo " make undeploy-logger -- Deactivate logger daemon."
@ echo ""
@ echo " make tail-logger -- Exibits and follow daemon execution log."
apt-install:
sudo apt-get install python-pip picocom
sudo apt-get install python python3 python3-pip supervisor
sudo pip${PYVER} install virtualenv
install-ino:
sudo apt-get install python-pip
sudo pip2 install ino
setup: clean-venv
@ echo "-------------------------------------------------------"
virtualenv -v --python='python${PYVER}' ${VENV}
@ echo "Virtualenv with 'python${PYVER}' interpreter was created at ${VENV}"
@ echo "-------------------------------------------------------"
${VENV}/bin/pip${PYVER} install --upgrade pip
${VENV}/bin/pip install --upgrade pip
@ echo "-------------------------------------------------------"
${VENV}/bin/pip${PYVER} install -r requirements.pip
${VENV}/bin/pip install -r logger/app/requirements.pip
@ echo "-------------------------------------------------------"
@ echo "Virtualenv is ready at ${VENV}!"
@ echo " "
......@@ -44,18 +58,34 @@ clean:
rm -rf .build src/*
build:
mkdir -p src/ lib/
cp -rf ../meteorolog/. src/
${VENV}/bin/ino build
mkdir -p .ino
mkdir -p .ino/src/ .ino/lib/
cp -rf meteorolog/. .ino/src/
cp logger/ino.ini .ino/
cd .ino/ && ino build
upload:
${VENV}/bin/ino upload
cd .ino/ && ino upload
serial:
${VENV}/bin/ipython3 -i logger/init_serial.py
bu: build upload
bus: build upload serial
serial:
${VENV}/bin/ino serial -- -c -r -l
sync-rtc:
${VENV}/bin/python${PYVER} run.py --syncrtc
run-logger:
${VENV}/bin/python logger/run.py
deploy-logger:
mkdir -p logger/logs
sudo ${VENV}/bin/python${PYVER} logger/deploy.py
list-models:
${VENV}/bin/ino list-models
undeploy-logger:
sudo ${VENV}/bin/python${PYVER} logger/deploy.py -u
tail-logger:
tail -F logger/logs/execution.log
PY := 3
VENV := .venv
all: help
help:
@ echo "USAGE:"
@ echo ""
@ echo " make apt-install -- Uses apt to install required system tools"
@ echo " (for Debian-based systems only)"
@ echo ""
@ echo " make setup -- Create a local Python virtual environment"
@ echo " that will hold requirements.pip modules"
@ echo ""
@ echo " make run -- Executes the logger"
@ echo ""
@ echo " make deploy -- Register meteorologger proccess on the"
@ echo " supervisor daemon tool (requires root)"
@ echo ""
@ echo " make undeploy -- Unregister meteorologger proccess on the"
@ echo " supervisor daemon tool (requires root)"
@ echo ""
@ echo " make tail-exec -- Follow the logger's execution.log"
@ echo ""
@ echo " make sync-rtc -- Send the current system time to the board"
apt-install:
sudo apt-get install python python3-pip supervisor
sudo pip${PYVER} install virtualenv
setup: clean-venv
@ echo "-------------------------------------------------------"
virtualenv -v --python='python${PYVER}' ${VENV}
@ echo "Virtualenv with 'python${PYVER}' interpreter was created at ${VENV}"
@ echo "-------------------------------------------------------"
${VENV}/bin/pip${PYVER} install --upgrade pip
@ echo "-------------------------------------------------------"
${VENV}/bin/pip${PYVER} install -r requirements.pip
@ echo "-------------------------------------------------------"
@ echo "Virtualenv is ready at ${VENV}!"
@ echo " "
@ echo "TOTAL SIZE: "
@ du -sh ${VENV}
clean-venv:
rm -rf ${VENV}
run:
${VENV}/bin/python${PYVER} run.py
deploy:
sudo ${VENV}/bin/python${PYVER} app/deploy.py
undeploy:
sudo ${VENV}/bin/python${PYVER} app/deploy.py -u
tail-exec:
tail -F logs/execution.log
sync-rtc:
${VENV}/bin/python${PYVER} run.py --syncrtc
......@@ -47,10 +47,10 @@ class Meteorologger:
Call the run() method to start the logging process.
'''
SETTINGS_SCHEMA_FILENAME = 'app/settings_schema.yaml'
SETTINGS_SCHEMA_FILENAME = 'logger/app/settings_schema.yaml'
SETTINGS_FILENAME = 'settings.yaml'
EXECUTION_LOG_FILENAME = 'logs/execution.log'
EXECUTION_LOG_FILENAME = 'logger/logs/execution.log'
OUTGOING_BASENAME = 'outgoing.json'
FILE_TIMESTAMP_FORMAT = '%Y-%m-%d-%H-%M-%S'
......@@ -121,10 +121,6 @@ class Meteorologger:
if using_rtc:
d['datetime']['source'] = rtc
rtc_datetime_fmt = self.CFG['LOGGER']['RTC_DATETIME_FORMAT']
else:
d['datetime']['source'] = 'logger'
d['datetime']['value'] = datetime.now().strftime(
d['datetime']['format'])
for i, v in enumerate(raw_line.split(self.SERIAL_CSV_SEP)):
......@@ -132,7 +128,7 @@ class Meteorologger:
type_name = self.CFG['SENSORS_AVAILABLE'][nickname]['data_format']
if type_name == 'datetime':
if using_rtc:
if using_rtc and not v.strip().startswith('<'):
d['datetime']['value'] = datetime.strptime(
v, rtc_datetime_fmt).strftime(d['datetime']['format'])
continue
......@@ -146,6 +142,11 @@ class Meteorologger:
d['sensors'][nickname] = v
if not 'value' in d['datetime']:
d['datetime']['source'] = 'logger'
d['datetime']['value'] = datetime.now().strftime(
d['datetime']['format'])
logging.info("Validated JSON: {}".format(d))
return d
......
import jinja2
import os
import subprocess
import sys
......@@ -12,22 +11,27 @@ SUPERVISOR_CONFIG_FILENAME = '/etc/supervisor/conf.d/{}.conf'\
PID_FILENAME = 'logs/pid_{}'.format(PROCESS_NAME)
def deploy_supervisor():
with open('app/supervisor.conf') as f_temp:
template = jinja2.Template(f_temp.read())
config_file_str = template.render(base_dir=BASE_DIR,
process_name=PROCESS_NAME)
TEMPLATE_SUPERVISOR_CONF =\
"""\
[program:{PROCESS_NAME}]
command={BASE_DIR}/.venv/bin/python3 {BASE_DIR}/logger/run.py -s
directory={BASE_DIR}
user=root
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile={BASE_DIR}/logger/logs/stdout.log
logfile={BASE_DIR}/logger/logs/supervisor-{PROCESS_NAME}.log
""".format(**globals())
print('\nRegistering supervisor config at \n {}'
.format(SUPERVISOR_CONFIG_FILENAME))
def deploy_supervisor():
print('='*60)
print(config_file_str)
print('='*60)
print('\nRegistering supervisor config at \n {}\n'
.format(SUPERVISOR_CONFIG_FILENAME) + '='*60 + '\n'
+ TEMPLATE_SUPERVISOR_CONF + '='*60)
with open(SUPERVISOR_CONFIG_FILENAME, 'w') as f:
f.write(config_file_str + '\n')
f.write(TEMPLATE_SUPERVISOR_CONF + '\n')
print('\nRestarting supervisor..')
proc = subprocess.Popen('supervisorctl update', shell=True)
......
import serial
import time
ser = serial.Serial(port='/dev/ttyACM0',
baudrate=9600)
def send(command_str):
ser.write(bytes(command_str, encoding='utf-8'))
time.sleep(1.5)
try:
raw = ser.readline()
return raw.decode('ascii').strip()
except:
print("Unable do decode raw line read:\n{}".format(raw))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment