Commit 50451cd4 authored by Nelso Jost's avatar Nelso Jost

FIX: minor refactorings

parent a19915ff
PYBIN := python3
VENVDIR := $(shell pwd)/.venv
VENVPY := ${VENVDIR}/bin/python
INO_DIR := .ino
USE := ino
ARDUINO :=#~/Downloads/arduino-1.6.5
INODIR := .ino
BUILDWITH := ino
ARDUINOPATH :=#~/Downloads/arduino-1.6.5
.PHONY: help setup firmware
.PHONY: help setup firmware serial run deploy undeploy
all: help
......@@ -60,12 +60,12 @@ check-venv:
printf "Python binary other than 'python3', like\n'python-3.x' ";\
printf "(where x is a number) for instance. \n\n"; exit 1; }
firmware: ${USE}-install
firmware: ${BUILDWITH}-install
chmod +x scripts/ino-build.sh
./scripts/ino-build.sh ${USE} ${INO_DIR} ${ARDUINO}
./scripts/ino-build.sh ${BUILDWITH} ${INODIR} ${ARDUINOPATH}
serial:
cd logger && ${VENVPY} -i init_serial.py
${VENVPY} -i scripts/init_serial.py
run: check-venv
${VENVPY} logger/run.py
......
......@@ -16,6 +16,7 @@ BOARD_ID =
; authentication token for the board's user
USER_HASH =
[reading]
; CSV list of sensor names/nicknames (order reflect columns on datalog files)
SENSORS = DHT22_TEMP, DHT22_AH, BMP085_PRESSURE, LDR
......@@ -95,11 +96,7 @@ class Config:
def __init__(self):
self.default = configparser.ConfigParser()
self.default.read_string(DEFAULT_INI)
try:
self.load_settings()
except Exception as e:
print('Exception: {}'.format(e))
raise e
def __getitem__(self, key):
return self._parser._sections[key]
......@@ -168,10 +165,8 @@ class Config:
try:
bid = int(self['server']['board_id'])
except:
raise Exception(
"Invalid numeric value for the server/BOARD_ID key.\n"
"Expected to be of type integer.\n"
"Was given:\n {}".format(self['server']['board_id']))
raise self.ConfigValueError('server', 'BOARD_ID',
'TypeError: Integer number expected!', self)
self['server']['api_post_url'] = self.URL_API_POST_RAWSENSORDATA\
.format(base=self['server']['url'] +
......@@ -183,9 +178,8 @@ class Config:
self['reading']['sensors'].split(',') if x.strip() != '']
if len(self['reading']['sensors']) == 0:
raise Exception(
"At least one sensor must be present on the reading/"
"SENSORS key.")
raise self.ConfigValueError('reading', 'SENSORS',
"EmptyListError: At least one sensor must be present!", self)
if 'true' in self['reading']['rtc_ds1307'].lower():
self['reading']['sensors'].append(self.RTC_NAME)
......@@ -206,10 +200,9 @@ class Config:
self['datalog']['csv_sep'] = bytes(value, 'utf8').decode(
'unicode_escape')
if not value in (',', ';', r'\t'):
raise Exception(
"Invalid character value for the datalog/CSV_SEP key.\n"
"Supported values:\n ',' ';' '\\t'\n"
"Was given:\n {}".format(value))
raise self.ConfigValueError('datalog', 'CSV_SEP',
"InvalidCharacter: Supported values are\n"
"',' ';' '\\t'\n", self)
def validate_arduino(self):
......
from app.main import Meteorologger
import sys
Meteorologger(background='--background' in sys.argv).run()
try:
Meteorologger(background='--background' in sys.argv).run()
except Exception as e:
print(e.message)
......@@ -2,10 +2,33 @@ import serial
import time
from datetime import datetime
from app.main import Meteorologger
def get_serial(baudrate=9600, read_timeout=1.5, board_reset_timeout=3,
find_port_timeout=0.5):
ports = []
for i in range(5):
ports.append('/dev/ttyACM{}'.format(i))
ports.append('/dev/ttyUSB{}'.format(i))
i = 0
while True:
serial_port = ports[i]
try:
ser = serial.Serial(port=serial_port,
baudrate=baudrate,
timeout=read_timeout,
xonxoff=True)
time.sleep(board_reset_timeout)
return ser
except Exception as e:
print("Exception: {}".format(e))
if i < len(ports) - 1:
i += 1
else:
i = 0
time.sleep(find_port_timeout)
print("\nAttempting serial connection ...\n")
ser = Meteorologger().get_serial()
ser = get_serial()
print(ser)
ser.flush()
......
......@@ -3,16 +3,16 @@ INO_DIR=$2 # provided by the Makefile
ARDUINO=$3 # toolchain path (defaults to empty)
if [ "$ARDUINO" = '' ]; then
printf "\nTrying to use the system's Arduino Installation\n\n";
printf "\nUsing system's Arduino Toolchain\n\n";
else
ARDUINO_PATH="-d $ARDUINO"
printf "\nUsing Arduino at $ARDUINO\n\n"
printf "\nUsing Arduino Toolchain at $ARDUINO\n\n"
fi
rm -rf $INO_DIR
mkdir -p $INO_DIR
mkdir -p $INO_DIR/src/ $INO_DIR/lib/
cp -rf meteorolog/. $INO_DIR/src/
mkdir -p $INO_DIR/src $INO_DIR/lib
cp -rf firmware/meteorolog/. $INO_DIR/src/
$BUILD_TOOL list-models $ARDUINO_PATH
#@ echo "\nGetting board model from settings.yaml"
......@@ -24,11 +24,11 @@ read -p "Type your board model (or hit ENTER to proceed with 'uno'): " MODEL_CON
cd ${INO_DIR}/ && $BUILD_TOOL build $ARDUINO_PATH -m ${MODEL_CONF:-$DEFAULT_MODEL} && $BUILD_TOOL upload -m ${MODEL_CONF:-$DEFAULT_MODEL} ${ARDUINO_PATH}
if [ ! $? -eq 0 ]; then
printf "\nSomething went wrong with the build & upload process when using '$BUILD_TOOL' command line tool. Probably there is some icompatibility with it and the Arduino toolchain $ARDUINO.\n\nHere is what else you can try:\n"
printf "\nSomething went wrong with the build & upload process when using the '$BUILD_TOOL' command line tool. Probably there is some icompatibility with it and the Arduino toolchain $ARDUINO.\n\nHere is what else you can try:\n"
printf "\n * Specify a new Arduino toolchain (for instance, downloaded at https://www.arduino.cc/en/Main/Software) with:\n"
printf "\n $ make bu ARDUINO=~/Downloads/arduino-1.6.5\n"
printf "\n $ make firmware ARDUINOPATH=~/Downloads/arduino-1.0.5\n"
printf "\n * Use the Arturo tool (http://32bits.io/Arturo/):\n"
printf "\n $ make bu USE=ano\n"
printf " $ make bu USE=ano ARDUINO=~/Downloads/arduino-1.6.5\n"
printf "\n * Simply use de Arduino IDE to compile meteorolog/meteorolog.ino and upload the firmware yourself.\n"
printf "\n $ make firmware BUILDWITH=ano\n"
printf " $ make firmware BUILDWITH=ano ARDUINOPATH=~/Downloads/arduino-1.6.5\n"
printf "\n * Simply use the Arduino IDE to compile the file\n firmware/meteorolog/meteorolog.ino\n and upload it to the board yourself.\n"
fi
......@@ -5,7 +5,7 @@ if ! type ino > /dev/null; then
# echo "I need the 'ino' command line tool (inotool.org) to be installed";
sudo apt-get update
sudo apt-get install python-pip arduino;
echo "Finding pip2 binary..";
echo "Trying to finding pip2 binary..";
PIP2=`dpkg -L python-pip | grep /usr/bin/pip | tail -1`;
echo "Got it! PIP2=$PIP2";
sudo $PIP2 install -v ino;
......@@ -17,13 +17,14 @@ fi
ino list-models > /dev/null
if [ ! $? -eq 0 ]; then
printf "\nIno Tool (http://inotool.org/) seems not be working with your system's Arduino instalation. Here is what you can try:\n"
printf "=============================================================="
printf "\nRequired Ino Tool (http://inotool.org/) seems not be working with your system's Arduino instalation. Here is what you can try:\n"
printf "\n * Specify a new Arduino toolchain (for instance, downloaded at https://www.arduino.cc/en/Main/Software) with:\n"
printf "\n $ make firmware ARDUINO=~/Downloads/arduino-1.0.5\n"
printf "\n $ make firmware ARDUINOPATH=~/Downloads/arduino-1.0.5\n"
printf "\n BEWARE: Ino Tool only support versions 1.0.x of the Arduino toolchain!\n"
printf "\n * Use the Arturo tool (http://32bits.io/Arturo/):\n"
printf "\n $ make firmware USE=ano\n"
printf " $ make firmware USE=ano ARDUINO=~/Downloads/arduino-1.6.5\n"
printf "\n $ make firmware BUILDWITH=ano\n"
printf " $ make firmware BUILDWITH=ano ARDUINOPATH=~/Downloads/arduino-1.6.5\n"
printf "\n PS: Arturo DOES support newer versions of the Arduino toolchain.\n"
printf "\n * Simply use de Arduino IDE to compile meteorolog/meteorolog.ino and upload the firmware yourself.\n"
else
......
......@@ -22,7 +22,7 @@ RTC_DS1307 = true
[datalog]
; CSV delimiter for local log files (valid options: , or ; or \t )
CSV_SEP = \t
CSV_SEP = ;
; format of the datetime column
; %Y : years | %m : months | %d : days | %H : hours | %M : mins | %S : secs
......
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