Exemplo n.º 1
0
class InfoHelper:
    def __init__(self):
        self.config = LocalConfig()
        self.attempt_size = 0.046  # constant
        self.wav_attempt_size = 0.061  # constant

    @staticmethod
    def current_volt():
        try:
            v_out = []
            with open(mapping.witty_pi_log) as f:
                for i, line in enumerate(f):
                    if 'Current' in line:
                        v_out.append(line)
            length = len(v_out) - 1

            return v_out[length][:-1]
        except IOError:
            return False

    def calc(self, usb_path):
        try:
            self.config.get_config_data()
            if self.config.data["wav"]:
                self.attempt_size = self.wav_attempt_size * int(self.config.audio["duration"])

            total, used, free = shutil.disk_usage("/media/usb/")
            free_space = (free / 1024 / 1024)
            possible_cycles = float(free_space) / self.attempt_size
            measure_cycle = ((3 * int(self.config.settings["median"])) + int(self.config.audio["duration"])) * 2
            cycles_per_hour = (((float(self.config.settings["app_wait_seconds"])) + float(measure_cycle)) / 60) / 60
            mb_per_hour = (1 / cycles_per_hour) * self.attempt_size
            estimated_cycles = round(free_space / mb_per_hour, 2)

            log_file_path = os.path.join(usb_path, "info.log")

            if not os.path.exists(log_file_path):
                os.system(f"sudo touch {log_file_path}")
            f = open(log_file_path, "r+")
            f.write(f"ID: {self.config.settings['device_id']} \n")
            f.write("Speicherplatz gesamt: %d GiB \n" % (total // (2**30)))
            f.write("Speicherplatz belegt: %d MB \n" % (used / 1024 / 1024))
            f.write("Speicherplatz frei: %d MB \n" % (free / 1024 / 1024))
            f.write("------------------------------------------------------- \n")
            f.write(f"Gesamt Anzahl Messungen bis Speicher voll: {round(possible_cycles, 2)} \n")
            f.write(f"Messungen pro Stunde: {round(cycles_per_hour, 2)} \n")
            f.write(f"Stunden bis Speicher voll: {estimated_cycles} Stunden \n")
            f.write(f"Tage bis Speicher voll: {round(estimated_cycles / 24, 1)} Tage \n")
            f.write(f"Datum bis Speicher voll: {get_new_date(estimated_cycles)}")
            f.write("------------------------------------------------------- \n")
            f.write("WITTYPI")
            if self.current_volt():
                f.write(str(self.current_volt()))
            f.write("\n")
            f.close()
            return True
        except Exception as e:
            print(e)
            return False
Exemplo n.º 2
0
 def __init__(self):
     self.config = LocalConfig()  # config init
     self.hx = HX711(5, 6)  # initialize scale
     self.ratio = 0  # scale ratio for calibration
     self.offset = 0
     self.value = 0
     self.result = 0
     self.data = 0
     self.error = ErrorHandler()
     self.config.get_config_data()
     if self.config.scale["calibrated"]:
         self.hx.set_offset(float(self.config.scale["offset"]))
         self.hx.set_scale(float(self.config.scale["ratio"]))
Exemplo n.º 3
0
class SystemTest:
    def __init__(self):
        self.config = LocalConfig()
        self.dataset = Dataset()

    def start_test(self):
        duration = self.config.audio["duration"]
        self.config.set_config_data("AUDIO", "duration", 10)
        try:

            for sensor, is_active in self.config.data.items():
                # get data from sensor if active
                if is_active:
                    is_ok = self.dataset.get_data(sensor)
                    if is_ok:
                        print(f"{sensor}...ok!")
                    else:
                        print(f"{sensor}...failed!")
        except Exception as e:
            print("something went wrong!")
            print(e)
        finally:
            self.config.set_config_data("AUDIO", "duration", duration)

    def test_audio(self):
        duration = self.config.audio["duration"]
        try:
            self.config.set_config_data("AUDIO", "duration", 10)
            test_data = self.dataset.get_data('wav')
            print(test_data)
        except Exception as e:
            print(e)
        finally:
            self.config.set_config_data("AUDIO", "duration", duration)
Exemplo n.º 4
0
class Microphone:
    def __init__(self):
        self.fs = 0
        self.duration = 0
        self.error = ErrorHandler()
        self.config = LocalConfig()

    def get_fft_data(self):

        try:
            self.config.get_config_data()
            audiodata = sd.rec(int(self.config.audio["duration"]) * int(self.config.audio["fs"]),
                               samplerate=int(self.config.audio["fs"]), channels=1, dtype='float64')
            sd.wait()
            data = audiodata.transpose()
            f, pxx = scipy.signal.welch(data,
                                        fs=int(self.config.audio["fs"]),
                                        window='hanning',
                                        nperseg=int(self.config.audio["nperseg"]),
                                        noverlap=int(self.config.audio["noverlap"]),
                                        nfft=int(self.config.audio["nfft"]),
                                        detrend=False,
                                        return_onesided=True,
                                        scaling='density',
                                        )

            temp_data = np.array(pxx).astype(float)
            data = temp_data.tolist()

            return {"status": True, "data": data}

        except Exception as e:
            print(e)
            self.error.log.exception(e)
            return {"status": False, "data": 0}

    def write_wav_data(self, filepath):
        try:
            self.config.get_config_data()
            recording = sd.rec(int(self.config.audio["duration"]) * int(self.config.audio["fs"]),
                               samplerate=int(self.config.audio["fs"]),
                               channels=1)
            sd.wait()
            write(filepath, int(self.config.audio["fs"]), recording)
            return True
        except Exception as e:
            self.error.log.exception(e)
            return False
Exemplo n.º 5
0
    def __init__(self):
        self.config = LocalConfig()
        self.config.get_config_data()
        self.sensors = self.config.data
        self.error = ErrorHandler()
        # deprecated
        if self.config.data["dht22"]:
            from sensorlib.dht22 import DHT22
            self.dht22 = DHT22()
        if self.config.data["ds18b20"]:
            from sensorlib.ds1820 import DS18B20
            self.temp_sensor = DS18B20()
        if self.config.data["fft"] or self.config.data["wav"]:
            from sensorlib.microphone import Microphone
            self.microphone = Microphone()
        if self.config.data["scale"]:
            from sensorlib.scale import Scale
            self.scale = Scale()
        if self.config.data["aht20"]:
            from sensorlib.aht20 import AHT20
            self.aht20 = AHT20()

        self.data = dict()
        self.timestamp = ""
Exemplo n.º 6
0
class USBHelper:
    def __init__(self):
        self.config = LocalConfig()
        self.config.get_config_data()
        self.info_helper = InfoHelper()
        self.stick_path = mapping.usb_path
        self.error = ErrorHandler()

    def update_config(self):
        # copy conf.ini data to local from usb stick
        self.config.get_config_data()
        scale_offset = self.config.scale["offset"]
        scale_ratio = self.config.scale["ratio"]
        scale_calibrated = self.config.scale["calibrated"]
        shutil.copy(os.path.join(self.config.usb_path, "conf.ini"),
                    mapping.config_path)
        self.config.get_config_data()
        self.config.set_config_data("SCALE", "ratio", scale_ratio)
        self.config.set_config_data("SCALE", "offset", scale_offset)
        self.config.set_config_data("SCALE", "calibrated", scale_calibrated)

    def reset_scale(self):
        # set scale values to zero
        self.config.get_config_data()
        self.config.set_config_data("SCALE", "ratio", 0)
        self.config.set_config_data("SCALE", "offset", 0)
        self.config.set_config_data("SCALE", "calibrated", 0)

        os.system(f"sudo rm {self.config.usb_path}/reset")

    def update_system(self):
        # update app data from github

        # create usb update file path
        usb_update_file = os.path.join(self.config.usb_path, "update.sh")

        # copy update file to local path
        shutil.copy(usb_update_file, mapping.update_file)

        # execute and remove update file
        os.system(f"sudo chmod +x {mapping.update_file}")
        os.system(f"sudo rm {usb_update_file}")
        call(mapping.update_file)

        os.system("sudo reboot")

    def prepare_usb_drive(self):
        is_config = False
        is_scale_reset = False
        is_wittypi_script = False
        is_tara = False
        is_update = False
        is_wpa = False
        try:
            # init
            if self.config.settings["device_id"] == "init":
                dirs = os.listdir(mapping.usb_path)
                for stick_dir in dirs:
                    if "." not in stick_dir:
                        self.config.set_config_data("SETTINGS", "device_id",
                                                    stick_dir)
                        self.config.get_config_data()
            # create device dir on usb stick
            if not os.path.exists(self.config.usb_path):
                os.mkdir(self.config.usb_path)
                os.system(
                    f"touch {os.path.join(self.config.usb_path, 'error.log')}")
                self.info_helper.calc(self.config.usb_path)

            # create fft dir on usb stick
            if not os.path.exists(os.path.join(self.config.usb_path, "fft")):
                os.mkdir(os.path.join(self.config.usb_path, "fft"))

            # create wav dir on usb stick
            if not os.path.exists(os.path.join(self.config.usb_path, "wav")):
                os.mkdir(os.path.join(self.config.usb_path, "wav"))

            # list usb files
            device_stick_files = os.listdir(self.config.usb_path)
            for stick_files in device_stick_files:

                if "conf.ini" in stick_files:
                    is_config = True

                if "schedule.wpi" in stick_files:
                    is_wittypi_script = True

                if "tara" in stick_files:
                    is_tara = True

                if "reset" in stick_files:
                    is_scale_reset = True

                if "update.sh" in stick_files:
                    is_update = True
                if "wpa_supplicant.conf" in stick_files:
                    is_wpa = True

            if is_update:
                self.update_system()

            if is_config:
                self.update_config()

            if is_wittypi_script:
                shutil.copy(os.path.join(self.config.usb_path, "schedule.wpi"),
                            mapping.witty_pi)
                call("/home/pi/wittypi/syncTime.sh")
                call("/home/pi/wittypi/runScript.sh")

            if is_tara:
                from sensorlib.scale import Scale
                scale = Scale()
                scale.tare()
                os.system(f"sudo rm {self.config.usb_path}/tara")
                print("restart")
                time.sleep(5)
                os.system("sudo reboot")

            if is_scale_reset:
                self.reset_scale()

            if is_wpa:
                shutil.copy(
                    os.path.join(self.config.usb_path, "wpa_supplicant.conf"),
                    mapping.wpa_path)
                os.system(
                    f"rm {os.path.join(self.config.usb_path, 'wpa_supplicant.conf')}"
                )
                time.sleep(5)
                os.system("sudo reboot")

        except Exception as e:
            print(e)
Exemplo n.º 7
0
 def __init__(self):
     self.fs = 0
     self.duration = 0
     self.error = ErrorHandler()
     self.config = LocalConfig()
Exemplo n.º 8
0
class Scale:
    def __init__(self):
        self.config = LocalConfig()  # config init
        self.hx = HX711(5, 6)  # initialize scale
        self.ratio = 0  # scale ratio for calibration
        self.offset = 0
        self.value = 0
        self.result = 0
        self.data = 0
        self.error = ErrorHandler()
        self.config.get_config_data()
        if self.config.scale["calibrated"]:
            self.hx.set_offset(float(self.config.scale["offset"]))
            self.hx.set_scale(float(self.config.scale["ratio"]))

    def setup(self):
        try:
            self.offset = self.hx.read_average()
            self.hx.set_offset(self.offset)
            return True
        except Exception as e:
            self.error.log.exception(e)
            return False

    def has_error(self):
        value_list = []
        try:
            for x in range(15):
                self.hx.power_up()
                value_list.append(self.hx.get_grams())
                self.hx.power_down()
                time.sleep(0.1)

            median_val = median(value_list)
            if value_list[3] == median_val:
                return True
            else:
                return False

        except Exception as e:
            self.error.log.exception(e)
            return True

    def calibrate(self, weight):
        try:
            self.value = int(weight)

            median_weight_list = []
            median_offset_list = []

            for x in range(7):
                median_weight_list.append(self.hx.read_average())

            for x in range(7):
                median_offset_list.append(self.hx.get_offset())

            average_weight = median(median_weight_list)
            average_offset = median(median_offset_list)

            measured_weight = (average_weight - average_offset)
            self.ratio = int(measured_weight) / self.value
            self.hx.set_scale(self.ratio)
            self.config.get_config_data()
            self.config.set_config_data("SCALE", "ratio", self.ratio)
            self.config.set_config_data("SCALE", "offset",
                                        self.hx.get_offset())
            self.config.set_config_data("SCALE", "calibrated", 1)
            return True
        except ValueError as e:
            self.error.log.exception(e)
            return False

    def get_data(self):
        try:
            self.hx.power_up()
            vals = []
            for i in range(5):
                vals.append(self.hx.get_grams(times=1))
            val = median(vals)
            measure_weight = round((val / 1000), 2)
            self.hx.power_down()
            return measure_weight
        except Exception as e:
            self.error.log.exception(e)
            return False

    def reset(self):
        self.config.set_config_data("SCALE", "ratio", 0)
        self.config.set_config_data("SCALE", "offset", 0)
        self.config.set_config_data("SCALE", "calibrated", 0)

    def tare(self):
        self.hx.tare()
        self.config.set_config_data("SCALE", "offset", self.hx.get_offset())

    @staticmethod
    def clean():
        GPIO.cleanup()
Exemplo n.º 9
0
class USBHelper:
    def __init__(self):
        self.config = LocalConfig()
        self.config.get_config_data()
        self.info_helper = InfoHelper()
        self.error = ErrorHandler()

    def test_system(self):
        from dataset import Dataset
        sensor_is_ok = True

        dataset = Dataset()
        self.config.get_config_data()

        duration = self.config.audio["duration"]
        self.config.set_config_data("AUDIO", "duration", 10)

        try:
            for sensor, is_active in self.config.data.items():
                # get data from sensor if active
                if is_active:
                    is_data = dataset.get_data(sensor)
                    if not is_data:
                        sensor_is_ok = False

            if sensor_is_ok:
                return True
            else:
                return False

        except Exception as e:
            self.error.log.exception(e)
        finally:
            self.config.set_config_data("AUDIO", "duration", duration)

    def update_config(self):
        # copy conf.ini data to local from usb stick
        self.config.get_config_data()
        device_id = self.config.settings['device_id']
        scale_offset = self.config.scale["offset"]
        scale_ratio = self.config.scale["ratio"]
        scale_calibrated = self.config.scale["calibrated"]
        shutil.copy(os.path.join(self.config.usb_path, "conf.ini"),
                    mapping.config_path)
        os.system(f"sudo chmod 755 {mapping.config_path}")
        self.config.get_config_data()
        self.config.set_config_data("SETTINGS", "device_id", device_id)
        self.config.set_config_data("SCALE", "ratio", scale_ratio)
        self.config.set_config_data("SCALE", "offset", scale_offset)
        self.config.set_config_data("SCALE", "calibrated", scale_calibrated)

        self.config.get_config_data()

        os.system(f"sudo rm {os.path.join(self.config.usb_path, 'conf.ini')}")

    def reset_scale(self):
        # set scale values to zero
        self.config.get_config_data()
        self.config.set_config_data("SCALE", "ratio", 0)
        self.config.set_config_data("SCALE", "offset", 0)
        self.config.set_config_data("SCALE", "calibrated", 0)

        os.system(f"sudo rm {os.path.join(self.config.usb_path, 'reset')}")

    def update_system(self):
        try:
            # update app data from github

            # create usb update file path
            usb_update_file = os.path.join(self.config.usb_path, "update.sh")

            # copy update file to local path
            shutil.copy(usb_update_file, mapping.update_file)

            # execute and remove update file
            os.system(f"sudo chmod 777 {mapping.update_file}")
            os.system(f"sudo rm {usb_update_file}")

            os.system(f"sudo sh {mapping.update_file}")

            os.system("sudo reboot")
        except Exception as e:
            self.error.log.exception(e)

        os.system("sudo reboot")

    def prepare_usb_drive(self):
        is_config = False
        is_scale_reset = False
        is_wittypi_script = False
        is_tara = False
        is_update = False
        is_wpa = False
        is_test = False
        is_sync_time = False
        try:
            # init
            if self.config.settings["device_id"] == "init":
                dirs = os.listdir(mapping.usb_path)
                for stick_dir in dirs:
                    if "." not in stick_dir and "System" not in stick_dir:
                        self.config.set_config_data("SETTINGS", "device_id",
                                                    stick_dir)
                        self.config.get_config_data()

            # create device dir on usb stick
            if not os.path.exists(self.config.usb_path):
                os.mkdir(self.config.usb_path)
                os.system(
                    f"touch {os.path.join(self.config.usb_path, 'error.log')}")

            # calc information and write to stick
            self.info_helper.calc(self.config.usb_path)

            # create fft dir on usb stick
            if not os.path.exists(os.path.join(self.config.usb_path, "fft")):
                os.mkdir(os.path.join(self.config.usb_path, "fft"))

            # create wav dir on usb stick
            if not os.path.exists(os.path.join(self.config.usb_path, "wav")):
                os.mkdir(os.path.join(self.config.usb_path, "wav"))

            # list usb files
            device_stick_files = os.listdir(self.config.usb_path)
            for stick_files in device_stick_files:

                if "test" in stick_files:
                    is_test = True

                if "sync" in stick_files:
                    is_sync_time = True

                if "conf.ini" in stick_files:
                    is_config = True

                if "schedule.wpi" in stick_files:
                    is_wittypi_script = True

                if "tara" in stick_files:
                    is_tara = True

                if "reset" in stick_files:
                    is_scale_reset = True

                if "update.sh" in stick_files:
                    is_update = True

                if "wpa_supplicant.conf" in stick_files:
                    is_wpa = True

            if is_update:
                self.update_system()

            if is_sync_time:
                try:
                    call("/home/pi/wittypi/syncTime.sh")
                    os.system(
                        f"sudo rm {os.path.join(self.config.usb_path, 'sync')}"
                    )
                except Exception as e:
                    self.error.log.exception(e)

            if is_test:
                from sensorlib.rgb import RGB
                os.system(
                    f"sudo rm {os.path.join(self.config.usb_path, 'test')}")

                led = RGB()
                if not self.test_system():
                    led.red()
                    time.sleep(3600)
                else:
                    led.blink("green", 5, 1)
                os.system("sudo reboot")

            if is_config:
                self.update_config()

            if is_wittypi_script:
                # todo wittipy log wird voll
                shutil.copy(os.path.join(self.config.usb_path, "schedule.wpi"),
                            mapping.witty_pi)
                os.system(
                    f"sudo rm {os.path.join(self.config.usb_path, 'schedule.wpi')}"
                )
                call("/home/pi/wittypi/runScript.sh")

            if is_tara:
                from sensorlib.scale import Scale
                scale = Scale()
                scale.tare()
                os.system(f"sudo rm {self.config.usb_path}/tara")
                time.sleep(5)
                os.system("sudo reboot")

            if is_scale_reset:
                self.reset_scale()

            if is_wpa:
                shutil.copy(
                    os.path.join(self.config.usb_path, "wpa_supplicant.conf"),
                    mapping.wpa_path)
                os.system(
                    f"rm {os.path.join(self.config.usb_path, 'wpa_supplicant.conf')}"
                )
                time.sleep(5)
                os.system("sudo reboot")

        except Exception as e:
            print(e)
Exemplo n.º 10
0
from helper.time_helper import get_file_time, set_timezone
from helper.usb_helper import USBHelper
from sensorlib.rgb import RGB
from subprocess import call
from datetime import datetime
import git
import mapping

repo = git.Repo(mapping.app_path)
master = repo.head.reference

led = RGB()
usb_handler = USBHelper()
usb_handler.prepare_usb_drive()

config = LocalConfig()
error = ErrorHandler()

current_version = config.settings['version']
git_version = master.commit.message

try:
    is_tmp = config.data['tmp117']
except KeyError:
    config.set_config_data('DATA', 'tmp117', 0)


dataset = Dataset()


if current_version != git_version:
Exemplo n.º 11
0
from dataset import Dataset
from configuration.local_config import LocalConfig
from helper.log_helper import ErrorHandler
import time
import os
import csv
from helper.time_helper import get_file_time
from helper.usb_helper import USBHelper
from sensorlib.rgb import RGB
import subprocess

led = RGB()
usb_handler = USBHelper()
usb_handler.prepare_usb_drive()
dataset = Dataset()
config = LocalConfig()
error = ErrorHandler()


def write_data(data):
    """
    format: time, device+location, hum, temp, weight, ds18b20x
    :param data: csv list data
    :return: bool
    """
    try:
        with open(os.path.join(f"{config.usb_path}/data.csv"),
                  mode='a+') as dataset_file:
            dataset_writer = csv.writer(dataset_file,
                                        delimiter=',',
                                        quotechar='"',
Exemplo n.º 12
0
class Dataset:
    def __init__(self):
        self.config = LocalConfig()
        self.config.get_config_data()
        self.sensors = self.config.data
        self.error = ErrorHandler()
        # deprecated
        if self.config.data["dht22"]:
            from sensorlib.dht22 import DHT22
            self.dht22 = DHT22()
        if self.config.data["ds18b20"]:
            from sensorlib.ds1820 import DS18B20
            self.temp_sensor = DS18B20()
        if self.config.data["fft"] or self.config.data["wav"]:
            from sensorlib.microphone import Microphone
            self.microphone = Microphone()
        if self.config.data["scale"]:
            from sensorlib.scale import Scale
            self.scale = Scale()
        if self.config.data["aht20"]:
            from sensorlib.aht20 import AHT20
            self.aht20 = AHT20()

        self.data = dict()
        self.timestamp = ""

    def get_data(self, sensor):
        try:
            self.config.get_config_data()
            return getattr(self, 'get_' + sensor)()
        except Exception as e:
            self.error.log.exception(e)

    def get_ds18b20(self):
        try:
            sensor_counter = self.temp_sensor.device_count()
            ds_temp = []
            if sensor_counter != 0 and sensor_counter != "NoneType":
                for x in range(sensor_counter):
                    for i in range(int(self.config.settings["median"])):
                        value = self.temp_sensor.tempC(x)
                        if value == 998 or value == 85.0:
                            raise SensorDataError("DS18B20")
                        else:
                            ds_temp.append(self.temp_sensor.tempC(x))
                            time.sleep(1)

                    if range(len(ds_temp)) != 0 or ds_temp != "nan":
                        median_ds_temp = median(ds_temp)
                        self.data[f"ds18b20-{x}"] = median_ds_temp
                return True
            else:
                raise SensorDataError("DS18B20")

        except Exception as e:
            print(e)
            self.error.log.exception(e)
            return False

    def get_aht20(self):
        try:
            aht_data = self.aht20.get_data()

            if aht_data["status"]:
                self.data["temp"] = aht_data["temp"]
                self.data["hum"] = aht_data["hum"]
                return True
            else:
                raise SensorDataError("AHT20")
        except Exception as e:
            self.error.log.exception(e)

    def get_dht22(self):
        try:
            dht_data = self.dht22.get_data()

            if dht_data:
                self.data["temp"] = dht_data["temp"]
                self.data["hum"] = dht_data["hum"]
                return True
            else:
                raise SensorDataError("DHT22")

        except Exception as e:
            self.error.log.exception(e)

    def get_scale(self):
        try:
            weight = self.scale.get_data()
            if weight:
                self.data["weight"] = weight
                return True
            else:
                raise SensorDataError("SCALE")

        except Exception as e:
            self.error.log.exception(e)

    def get_fft(self):
        try:
            fft_data = self.microphone.get_fft_data()
            if fft_data["status"]:

                dir_name = get_dir_time()
                dir_path = f"{self.config.usb_path}/fft/{dir_name}"

                file_name = self.timestamp
                file_path = f"{dir_path}/{file_name}.json"

                if not os.path.exists(dir_path):
                    os.mkdir(dir_path)

                os.system(f"sudo touch {file_path}")
                db = TinyDB(file_path)
                db.insert({
                    "source": "microphone",
                    "time": get_time(),
                    "data": str(fft_data["data"]),
                })
                return True
            else:
                raise SensorDataError("MICROPHONE")

        except Exception as e:
            print(e)
            self.error.log.exception(e)

    def get_wav(self):
        try:
            dir_name = get_dir_time()
            dir_path = f"{self.config.usb_path}/wav/{dir_name}"

            filename = self.timestamp
            filepath = f"{dir_path}/{filename}.wav"

            if not os.path.exists(dir_path):
                os.mkdir(dir_path)

            if self.microphone.write_wav_data(filepath):
                return True
            else:
                raise SensorDataError("MICROPHONE")

        except Exception as e:
            self.error.log.exception(e)
            return False
Exemplo n.º 13
0
 def __init__(self):
     self.config = LocalConfig()
Exemplo n.º 14
0
class Reset:
    def __init__(self):
        self.config = LocalConfig()

    def reset_settings(self):
        self.config.set_config_data("SETTINGS", "timezone", "Europe/Berlin")
        self.config.set_config_data("SETTINGS", "device_id", "init")
        self.config.set_config_data("SETTINGS", "app_wait_seconds", 2700)
        self.config.set_config_data("SETTINGS", "errors_before_restart", 3)
        self.config.set_config_data("SETTINGS", "median", 5)
        self.config.set_config_data("SETTINGS", "version", "0.2.2")
        self.config.set_config_data("SETTINGS", "autoshutdown", 1)

    def reset_audio(self):
        self.config.set_config_data("AUDIO", "duration", 600)
        self.config.set_config_data("AUDIO", "fs", 8000)
        self.config.set_config_data("AUDIO", "nperseg", 4096)
        self.config.set_config_data("AUDIO", "noverlap", 2048)
        self.config.set_config_data("AUDIO", "nfft", 4096)

    def reset_scale(self):
        self.config.set_config_data("SCALE", "ratio", 0)
        self.config.set_config_data("SCALE", "offset", 0)
        self.config.set_config_data("SCALE", "calibrated", 0)
        self.config.set_config_data("SCALE", "calibrate_weight", 12250)

    def reset_data(self):
        self.config.set_config_data("DATA", "scale", 1)
        self.config.set_config_data("DATA", "dht22", 0)
        self.config.set_config_data("DATA", "ds18b20", 1)
        self.config.set_config_data("DATA", "fft", 0)
        self.config.set_config_data("DATA", "wav", 1)
        self.config.set_config_data("DATA", "aht20", 1)
        self.config.set_config_data("DATA", "tmp117", 0)
Exemplo n.º 15
0
 def __init__(self):
     self.config = LocalConfig()
     self.config.get_config_data()
     self.info_helper = InfoHelper()
     self.error = ErrorHandler()
Exemplo n.º 16
0
 def __init__(self):
     self.config = LocalConfig()
     self.config.get_config_data()
     self.info_helper = InfoHelper()
     self.stick_path = mapping.usb_path
     self.error = ErrorHandler()
Exemplo n.º 17
0
from dataset import Dataset
from configuration.local_config import LocalConfig

config = LocalConfig()
dataset = Dataset()

print("start testing sensors...")
duration = config.audio["duration"]
config.set_config_data("AUDIO", "duration", 10)

try:

    for sensor, is_active in config.data.items():
        # get data from sensor if active
        if is_active:
            is_ok = dataset.get_data(sensor)
            if is_ok:
                print(f"{sensor}...ok!")
            else:
                print(f"{sensor}...failed!")
except Exception as e:
    print("something went wrong!")
    print(e)
finally:
    config.set_config_data("AUDIO", "duration", duration)


Exemplo n.º 18
0
 def __init__(self):
     self.config = LocalConfig()
     self.attempt_size = 0.046  # constant
     self.wav_attempt_size = 0.061  # constant
Exemplo n.º 19
0
 def __init__(self):
     self.config = LocalConfig()
     self.dataset = Dataset()
Exemplo n.º 20
0
#!/usr/bin/env python
#  -------------------------------------------------------------------------
#  Copyright (C) 2015 BMW Car IT GmbH
#  -------------------------------------------------------------------------
#  This Source Code Form is subject to the terms of the Mozilla Public
#  License, v. 2.0. If a copy of the MPL was not distributed with this
#  file, You can obtain one at https://mozilla.org/MPL/2.0/.
#  -------------------------------------------------------------------------

from ramses_test_framework.cores import core
from configuration.local_config import LocalConfig

_core = core.Core(core.LOCAL, LocalConfig())
_core.read_arguments()
_core.setup()
result = _core.run_tests()
_core.tear_down(shutdownTargets=False)
if not result and _core.coreImpl.config.useExitcodeOnTestFailure:
    exit(1)