From 436ef35d46654e9b453a29ac8355bf4738714b66 Mon Sep 17 00:00:00 2001 From: Joel Klimont Date: Wed, 6 Oct 2021 00:19:58 +0200 Subject: [PATCH] renamed /getMeteoroid to /getMeteoroids small corrections in ip daemon --- build_deb.sh | 2 +- compLib/Api.py | 12 ++++++------ compLib/Vision.py | 24 +++++++++++++++++++----- compLib/VisionDaemon.py | 2 +- compLib/__init__.py | 2 +- docs/source/lib/Api.rst | 2 +- setup.py | 2 +- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/build_deb.sh b/build_deb.sh index 2e2de31..14ccbe9 100755 --- a/build_deb.sh +++ b/build_deb.sh @@ -34,7 +34,7 @@ fpm -s python --python-bin python3 --python-pip pip3 --python-package-name-prefi -d "python3-pigpio" \ -d "python3-numpy" \ -d "ffmpeg" \ - -v 0.2.5-0 -t deb setup.py + -v 0.2.6-0 -t deb setup.py # --deb-changelog changelog \ # --deb-upstream-changelog changelog \ diff --git a/compLib/Api.py b/compLib/Api.py index 4c87a8c..f518f9b 100644 --- a/compLib/Api.py +++ b/compLib/Api.py @@ -194,18 +194,18 @@ class DoubleElim: return response, res.status_code @staticmethod - def get_meteoroid() -> Tuple[List[Dict], int]: - """Makes the /api/getMeteoroid call to the api. + def get_meteoroids() -> Tuple[List[Dict], int]: + """Makes the /api/getMeteoroids call to the api. :return: A list will all meteoroids currently on the game field. Meteoroids are dictionaries that look like: {"x": 0, "y": 0} :rtype: Tuple[List[Dict], int] """ res = requests.get(API_URL_GET_METEOROID) if res.status_code == 408: - Logging.get_logger().error(f"DoubleElim.get_meteoroid timeout!") + Logging.get_logger().error(f"DoubleElim.get_meteoroids timeout!") time.sleep(0.01) - return DoubleElim.get_meteoroid() + return DoubleElim.get_meteoroids() response = json.loads(res.content) - Logging.get_logger().debug(f"DoubleElim.get_meteoroid = {response}, status code = {res.status_code}") - return response, res.status_code \ No newline at end of file + Logging.get_logger().debug(f"DoubleElim.get_meteoroids = {response}, status code = {res.status_code}") + return response, res.status_code diff --git a/compLib/Vision.py b/compLib/Vision.py index 2bd3558..a560cc9 100644 --- a/compLib/Vision.py +++ b/compLib/Vision.py @@ -1,14 +1,13 @@ import os import queue -from queue import Queue +import socket +import threading import cv2 -import logging -import threading -from compLib.LogstashLogging import Logging - from flask import Flask, Response +from compLib.LogstashLogging import Logging + RTMP_SERVER = os.getenv("RTMP_SERVER", "rtmp://localhost/live/stream") SERVE_VIDEO = os.getenv("SERVER_SRC", "/live") BUILDING_DOCS = os.getenv("BUILDING_DOCS", "false") @@ -161,6 +160,18 @@ def __index(): return HTML +def get_ip(): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + try: + s.connect(('10.255.255.255', 1)) + IP = s.getsockname()[0] + except Exception: + IP = '127.0.0.1' + finally: + s.close() + return IP + + def __start_flask(): """ Function for running flask server in a thread. @@ -169,6 +180,9 @@ def __start_flask(): """ Logging.get_logger().info("starting flask server") app.run(host="0.0.0.0", port=9898, debug=True, threaded=True, use_reloader=False) + ip = get_ip() + Logging.get_logger().info(f"Vision stream started and can be viewed on: {ip}:9898") + print(f"\033[92mVision stream started and can be viewed on: {ip}:9898\033[0m") if BUILDING_DOCS == "false": diff --git a/compLib/VisionDaemon.py b/compLib/VisionDaemon.py index 3643f92..2af82ac 100644 --- a/compLib/VisionDaemon.py +++ b/compLib/VisionDaemon.py @@ -60,7 +60,7 @@ def write_ip_to_screen(): Logging.get_logger().info(f"writing {ip} to display") Display.write(1, "Current IP:") Display.write(2, ip) - time.sleep(60) + time.sleep(5) if __name__ == '__main__': diff --git a/compLib/__init__.py b/compLib/__init__.py index 6a57bd7..38904af 100644 --- a/compLib/__init__.py +++ b/compLib/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.2.5-0" +__version__ = "0.2.6-0" import importlib import compLib.LogstashLogging diff --git a/docs/source/lib/Api.rst b/docs/source/lib/Api.rst index 59ad2d6..850f69b 100644 --- a/docs/source/lib/Api.rst +++ b/docs/source/lib/Api.rst @@ -101,7 +101,7 @@ Calling Double Elimination API score, status = DoubleElim.get_score() print(f"The current score of the game is {score}, the server responded with status code: {status}") - meteoroids, status = DoubleElim.get_meteoroid() + meteoroids, status = DoubleElim.get_meteoroids() print(f"The current meteoroids in the game are {meteoroids}, the server responded with status code: {status}") In this second example we wait until the game is started by the judges and then make all possible requests once. You should use the wait_for_start function in your double elimination program. If your robot starts too soon your run will not count! diff --git a/setup.py b/setup.py index b74ab04..1ca6220 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ else: setuptools.setup( name="complib", - version="0.2.5-0", + version="0.2.6-0", author="F-WuTs", author_email="--", description="",