From e89ba006a0e37d1258de5d34568eed940b8655a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Mon, 12 Feb 2024 23:14:39 +0100 Subject: [PATCH] added get interface ip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- README.md | 1 + server/app.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e9b4e5..7f1379e 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ pip3 install stupidArtnet pip3 install wifi pip3 install paho-mqtt pip3 install get-mac +pip3 install netifaces ``` ### Setup the wifi access point: diff --git a/server/app.py b/server/app.py index 44b1b39..7f53815 100644 --- a/server/app.py +++ b/server/app.py @@ -6,6 +6,7 @@ import threading from stupidArtnet import StupidArtnet import os from getmac import get_mac_address +import netifaces app = Flask(__name__) @@ -88,6 +89,15 @@ def get_assigned_params(tube_unique_id): def flask_api(): app.run(host='0.0.0.0', port=5000) +def get_eth0_ip(): + try: + # Get the IP address of the eth0 interface + eth0_ip = netifaces.ifaddresses('eth0')[netifaces.AF_INET][0]['addr'] + return eth0_ip + except (KeyError, IndexError, OSError) as e: + print(f"Error getting eth0 IP: {e}") + return None + def connect_mqtt(): def on_connect(client, userdata, flags, rc): @@ -106,7 +116,7 @@ def mqtt_publisher(universe): mqtt_client = connect_mqtt() try: # Create a new Art-Net listener - artnet = StupidArtnet() + artnet = StupidArtnet(bind=get_eth0_ip()) artnet.start(universe=universe) while True: