did good
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-10-20 00:45:08 +02:00
parent 336a2c0a12
commit c1f214c9d2
2 changed files with 207 additions and 10 deletions

View File

@@ -5,7 +5,7 @@ import os
import sys
import time
import json
import datetime
from datetime import datetime
import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration
import paho.mqtt.client
@@ -26,10 +26,10 @@ RELEASEMODE = os.environ.get("RELEASEMODE", "dev")
DEVICE_ID = os.environ.get("DEVICE_ID", "devraspi")
MQTT_USERNAME = ""
MQTT_PASSWORD = ""
MQTT_HOSTNAME = ""
MQTT_PORT = ""
MQTT_USERNAME = "birbnetes"
MQTT_PASSWORD = "de4d2182"
MQTT_HOSTNAME = "mqtt.kmlabz.com"
MQTT_PORT = 1883
STARTTIME = time.time()
ENDTIME = time.time()
@@ -55,19 +55,20 @@ if SENTRY_DSN:
def mqtt_on_connect(client, userdata, flags, rc):
client.subscribe(f"command/benchmark-script")
global STARTTIME
client.subscribe(f"command/10")
logging.info("Sending Message")
files = {
"file": (
os.path.basename(FILE), open(FILE, 'rb').read(), 'audio/wave', {'Content-length': os.path.getsize(FILE)}),
"description": (None, json.dumps({'date': datetime.now().isoformat(), 'device_id': '1'}), "application/json")
"description": (None, json.dumps({'date': datetime.now().isoformat(), 'device_id': '10'}), "application/json")
}
requests.post(URL, files=files)
nonlocal STARTTIME
STARTTIME = time.time()
def mqtt_on_command(client, userdata, message):
global ENDTIME
try:
msg = json.loads(message.payload.decode())
except (UnicodeError, json.JSONDecodeError) as e:
@@ -75,7 +76,6 @@ def mqtt_on_command(client, userdata, message):
return
if msg.get("command") == 'doAlert':
nonlocal ENDTIME
ENDTIME = time.time()
elapsed = ENDTIME - STARTTIME
logging.info(f"Elapsed time: {elapsed}")
@@ -89,7 +89,7 @@ def main() -> None:
logging.basicConfig(stream=sys.stdout, format="%(asctime)s - %(name)s [%(levelname)s]: %(message)s",
level=logging.DEBUG if '--debug' in sys.argv else logging.INFO)
client = paho.mqtt.client.Client(client_id="benchmark-script")
client = paho.mqtt.client.Client(client_id="10")
client.on_connect = mqtt_on_connect
client.on_message = mqtt_on_command