The official Wiki for CompanionPI shows several methods for getting Raspberry Pi IP address.
Here is another approach. Making use of Sctream Deck as screen. You need to previously create 4 buttons in page 1. The script will will display the IP address in the first 4 buttons of Stream Deck
import socket
import requests
import time
def get_private_ip():
try:
# Create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# This does not need to be connected to a real address, just a placeholder
s.connect(("8.8.8.8", 80)) # Using Google's public DNS server
private_ip = s.getsockname()[0]
finally:
s.close()
return private_ip
if __name__ == "__main__":
myip = get_private_ip()
data = myip.split(".")
print(myip)
btn = 0
for a in data:
while True:
try:
bank = f"1/0/{btn}"
url = f"http://{myip}:8000/api/location/{bank}/style"
data = { "text": a}
res = requests.post(url, data=data)
if res.text == "ok":
print(res.content)
btn += 1
break
else:
print("no response")
# time.sleep(1)
except:
time.sleep(1)