Implemented platform specific stuff
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Pünkösd Marcell 2020-09-30 03:35:20 +02:00
parent 561dea69ba
commit 3a129f8518
4 changed files with 38 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration
from utils import config, LoopingTimer
from signal_processor import SoundSignalProcessor
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver
"""
Main Entrypoint
@ -46,6 +47,7 @@ def main() -> None:
Main function
:return:
"""
BirbnetesIoTPlatformStatusDriver.init()
listofabcsignaprocessors = (SoundSignalProcessor())
loopingtimer = LoopingTimer(function=timer_tick, args=[listofabcsignaprocessors], interval=config.TICK_INTERVAL)
loopingtimer.start()

View File

@ -1,5 +1,8 @@
#!/usr/bin/env python3
from typing import Optional
from .abcsensor import AbcSensor
from utils import config
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformRecordDriver
"""
Sound sensor high level API
@ -15,11 +18,17 @@ class SoundSensor(AbcSensor):
"""
SoundSensor class. Responsible for sound retrieval from any microphones present.
"""
def getvalue(self) -> str:
def __init__(self):
BirbnetesIoTPlatformRecordDriver.init(config.SAMPLE_LENGTH)
def getvalue(self) -> Optional[str]:
"""
Retrieve a 5 second sound clip from a microphone.
Retrieve a configurable length second sound clip from a microphone.
:return:
"""
# Recieve sound from microphone and save it to a file on the filesystem.
# Then return the filename
return "filename.wav"
return BirbnetesIoTPlatformRecordDriver.get_recording(False)
def __del__(self):
# In theory you should not put anything to __del__ as it is not guaranteed to be called.
BirbnetesIoTPlatformRecordDriver.cleanup()

View File

@ -1,9 +1,13 @@
#!/usr/bin/env python3
import logging
import requests
from sensor import SoundSensor
from sender import SoundSender
from preprocessor import SoundPreProcessor
from .abcsignalprocessor import AbcSignalProcessor
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver
"""
Abstract base class for signalprocessor
"""
@ -33,5 +37,20 @@ class SoundSignalProcessor(AbcSignalProcessor):
:return:
"""
soundsample_name = self.soundsensor.getvalue()
sample_decision = self.soundpreprocessor.preprocesssignal(soundsample_name)
self.soundsender.sendvalue(soundsample_name, sample_decision)
try:
sample_decision = self.soundpreprocessor.preprocesssignal(soundsample_name)
except Exception as e:
logging.exception(e)
BirbnetesIoTPlatformStatusDriver.enqueue_pattern('red', [1, 1, 1])
return
if sample_decision:
BirbnetesIoTPlatformStatusDriver.enqueue_pattern('green', [1, 0, 1])
try:
self.soundsender.sendvalue(soundsample_name, sample_decision)
except (ConnectionError, requests.HTTPError) as e:
logging.exception(e)
BirbnetesIoTPlatformStatusDriver.enqueue_pattern('red', [1, 0, 1, 0, 1])
return

View File

@ -17,6 +17,7 @@ RELEASEMODE = os.environ.get("RELEASEMODE", "dev")
DEVICE_ID = os.environ.get("DEVICE_ID", "devraspi")
TICK_INTERVAL = float(os.environ.get("TICK_INTERVAL", 0.4))
SAMPLE_LENGTH = float(os.environ.get("SAMPLE_LENGTH", 1))
TARGET_NAME = os.environ.get("TARGET_CLASS_NAME")