added get interface ip
Signed-off-by: Ebbe Baß <ebbe.bass>
This commit is contained in:
@@ -91,6 +91,7 @@ pip3 install stupidArtnet
|
|||||||
pip3 install wifi
|
pip3 install wifi
|
||||||
pip3 install paho-mqtt
|
pip3 install paho-mqtt
|
||||||
pip3 install get-mac
|
pip3 install get-mac
|
||||||
|
pip3 install netifaces
|
||||||
```
|
```
|
||||||
|
|
||||||
### Setup the wifi access point:
|
### Setup the wifi access point:
|
||||||
|
|||||||
+11
-1
@@ -6,6 +6,7 @@ import threading
|
|||||||
from stupidArtnet import StupidArtnet
|
from stupidArtnet import StupidArtnet
|
||||||
import os
|
import os
|
||||||
from getmac import get_mac_address
|
from getmac import get_mac_address
|
||||||
|
import netifaces
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@@ -88,6 +89,15 @@ def get_assigned_params(tube_unique_id):
|
|||||||
def flask_api():
|
def flask_api():
|
||||||
app.run(host='0.0.0.0', port=5000)
|
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 connect_mqtt():
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
@@ -106,7 +116,7 @@ def mqtt_publisher(universe):
|
|||||||
mqtt_client = connect_mqtt()
|
mqtt_client = connect_mqtt()
|
||||||
try:
|
try:
|
||||||
# Create a new Art-Net listener
|
# Create a new Art-Net listener
|
||||||
artnet = StupidArtnet()
|
artnet = StupidArtnet(bind=get_eth0_ip())
|
||||||
artnet.start(universe=universe)
|
artnet.start(universe=universe)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Reference in New Issue
Block a user