Commit 5da41416 authored by Nelso Jost's avatar Nelso Jost
Browse files

NEW: full RTC support; better settings management;

parent 2310b102
......@@ -44,13 +44,13 @@ clean-venv:
rm -rf ${VENV}
run:
sudo ${VENV}/bin/python${PYVER} logger.py
${VENV}/bin/python${PYVER} run.py
deploy:
sudo ${VENV}/bin/python${PYVER} deploy.py
sudo ${VENV}/bin/python${PYVER} app/deploy.py
undeploy:
sudo ${VENV}/bin/python${PYVER} deploy.py -u
sudo ${VENV}/bin/python${PYVER} app/deploy.py -u
tail-exec:
tail -F logs/execution.log
from .main import Meteorologger
......@@ -6,6 +6,7 @@ import sys
PROCESS_NAME = 'meteorologger'
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
BASE_DIR = BASE_DIR[:BASE_DIR.rfind(os.path.sep)]
SUPERVISOR_CONFIG_FILENAME = '/etc/supervisor/conf.d/{}.conf'\
.format(PROCESS_NAME)
......@@ -13,7 +14,7 @@ PID_FILENAME = 'logs/pid_{}'.format(PROCESS_NAME)
def deploy_supervisor():
with open('supervisor.conf') as f_temp:
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)
......@@ -37,12 +38,17 @@ def deploy_supervisor():
proc.wait()
pid = proc.stdout.read().decode('ascii').strip()
with open(PID_FILENAME, 'w') as f:
f.write(pid + '\n')
try:
pid = int(pid)
print("\nPID: {} (saved at '{}')".format(pid, PID_FILENAME))
print('\n[{} process is running]'.format(PROCESS_NAME))
print('\nYou can manage it with supervisorctl tool.')
with open(PID_FILENAME, 'w') as f:
f.write(str(pid) + '\n')
print("\nPID: {} (saved at '{}')".format(pid, PID_FILENAME))
print('\n[{} process is running]'.format(PROCESS_NAME))
print('\nYou can manage it with supervisorctl tool.')
except:
print("\nSomething went wrong and the daemon process was NOT created.")
def undeploy_supervisor():
......
This diff is collapsed.
docopt==0.6.2
ipython==3.1.0
Jinja2==2.7.3
MarkupSafe==0.23
pykwalify==1.2.0
pyreadline==2.0
pyserial==2.7
python-dateutil==2.4.2
PyYAML==3.11
requests==2.6.0
six==1.9.0
type: map
mapping:
SERVER:
required: true
type: map
mapping:
API_POST_URL:
required: true
type: str
LOGGER:
required: true
type: map
mapping:
SENSORS:
required: true
type: seq
sequence:
- type: str
unique: true
INTERVAL:
# default: {days: 0, hours: 0, minutes: 0, seconds: 10}
required: true
type: map
mapping:
days:
required: true
type: int
range:
min: 0
hours:
required: true
type: int
range:
min: 0
minutes:
required: true
type: int
range:
min: 0
seconds:
required: true
type: int
range:
min: 0
USE_RTC_DATETIME:
required: true
allowempty: true
type: map
RTC_DATETIME_FORMAT:
# default: '%Y-%m-%d %H:%M%:%S'
required: true
type: str
ARDUINO:
required: true
type: map
mapping:
SERIAL_PORT:
required: true
type: str
BAUD_RATE:
required: true
type: int
enum: [300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200]
RESPONSE_DELAY:
required: true
type: int
range:
min: 0
DATALOG:
required: true
type: map
mapping:
FILENAME:
required: true
type: str
CSV_SEP:
required: true
type: str
DATETIME_FORMAT:
required: true
type: str
SENSORS_AVAILABLE:
required: true
type: map
allowempty: true
[program:{{ process_name }}]
command={{ base_dir }}/.venv/bin/python3 {{ base_dir }}/logger.py -s
command={{ base_dir }}/.venv/bin/python3 {{ base_dir }}/run.py -s
directory={{ base_dir }}
user=root
autostart=true
......
from app import Meteorologger
import sys
if __name__ == '__main__':
Meteorologger(verbose = False if '-s' in sys.argv else True).run()
......@@ -2,50 +2,78 @@ SERVER:
# full URL that accepts POST method for sending data to the server
# WARNING: replace the end 'BID' with a valid board ID number
#
API_POST_URL: http://dados.cta.if.ufrgs.br/emm/api/post/rawsensordata/BID
API_POST_URL: 'http://localhost:5000/api/post/rawsensordata/2'
LOGGER:
# list of sensors to be read (ordering reflect columns of DATALOG file)
# to ignore one, comment it out by putting # in the beginning of the line
#
SENSORS:
- RTC_DS1307
- DHT22_TEMP
- DHT22_AH
- BMP085_PRESSURE
- LDR
# time between readings attempts (cycles of the logger execution)
#
READING_INTERVAL: {days: 0, hours: 0, minutes: 0, seconds: 10}
INTERVAL: {days: 0, hours: 0, minutes: 0, seconds: 3}
# format of the datetime column (see Python docs on datetime module)
#
DATETIME_FORMAT: '%Y%m%d%H%M%S'
# set false to use the system time or the RTC sensor name to use instead
#
USE_RTC_DATETIME: RTC_DS1307
# expected format of the time stamp returned by the RTC reading
#
RTC_DATETIME_FORMAT: '%Y-%m-%d %H:%M:%S'
# list of sensors to be read (the order reflect columns of DATALOG_CSV file)
# to ignore one, comment it out by putting # in the beginning of the line
#
SENSORS:
- {nickname: DHT22_TEMP, data_format: float}
- {nickname: DHT22_AH, data_format: float}
- {nickname: BMP085_PRESSURE, data_format: int}
- {nickname: LDR, data_format: float}
ARDUINO:
# comma-separated list of USB ports that may have the Arduino plugged in
# Arduino Uno usually mounts on /dev/ttyACMx; the others go on /dev/USBx
#
#
SERIAL_PORT: /dev/ttyACM0, /dev/ttyACM1
# Arduino serial communication protocol (same as in meteorolog.ino)
# OBS: 115200 seems unstable with Uno + PySerial
#
BAUD_RATE: 9600 # 115200 seems unstable with Uno + PySerial
BAUD_RATE: 9600
# time (in seconds) to wait before send a new serial read request
#
#
RESPONSE_DELAY: 3
FILES:
# file which will hold all data locally (regardless of the web server)
DATALOG:
# directory to store datalog.csv data as backup
#
DATALOG_CSV: data/datalog.csv
FILENAME: data/datalog.csv
# CSV delimiter to be used on the file DATA_LOG_FILENAME
# Sugestions: ',' or ';' or '\t' for tab (do not use the period '.')
#
DATALOG_CSV_SEP: '\t'
#
CSV_SEP: '\t'
# temp file that hold data when server is off and will be sent when on
# format of the datetime column (see Python docs on datetime module)
#
SERVER_OUTGOING_JSON: data/outgoing.json
DATETIME_FORMAT: '%Y%m%d%H%M%S'
# ============================================================================
# list of all the sensors available for this board, and their specs
# WARNING: should be synced with the server (edit only if you know)
#
SENSORS_AVAILABLE:
RTC_DS1307:
data_format: datetime
DHT22_TEMP:
data_format: float
DHT22_AH:
data_format: float
BMP085_PRESSURE:
data_format: int
LDR:
data_format: float
......@@ -7,7 +7,7 @@
// === LDR SETUP =======================================
#define LDR_PIN 0 // analog
#define LDR_PIN 1 // analog
String read_LDR()
{
......
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