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

View File

@ -1,5 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from typing import Optional
from .abcsensor import AbcSensor from .abcsensor import AbcSensor
from utils import config
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformRecordDriver
""" """
Sound sensor high level API Sound sensor high level API
@ -15,11 +18,17 @@ class SoundSensor(AbcSensor):
""" """
SoundSensor class. Responsible for sound retrieval from any microphones present. 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: :return:
""" """
# Recieve sound from microphone and save it to a file on the filesystem. return BirbnetesIoTPlatformRecordDriver.get_recording(False)
# Then return the filename
return "filename.wav" 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 #!/usr/bin/env python3
import logging
import requests
from sensor import SoundSensor from sensor import SoundSensor
from sender import SoundSender from sender import SoundSender
from preprocessor import SoundPreProcessor from preprocessor import SoundPreProcessor
from .abcsignalprocessor import AbcSignalProcessor from .abcsignalprocessor import AbcSignalProcessor
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver
""" """
Abstract base class for signalprocessor Abstract base class for signalprocessor
""" """
@ -33,5 +37,20 @@ class SoundSignalProcessor(AbcSignalProcessor):
:return: :return:
""" """
soundsample_name = self.soundsensor.getvalue() 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") DEVICE_ID = os.environ.get("DEVICE_ID", "devraspi")
TICK_INTERVAL = float(os.environ.get("TICK_INTERVAL", 0.4)) 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") TARGET_NAME = os.environ.get("TARGET_CLASS_NAME")