Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions senseapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import time

import subprocess

class SenseApp:

settings_manager = None
Expand All @@ -31,6 +33,19 @@ def __init__(self):

# self.sense.display("*** SenseApp ***")

def get_ip(self):
ip = subprocess.getoutput("ip -4 addr | grep -oP '(?<=inet\s)\d+(\.\d+){3}'")
if ip=="127.0.0.1":
return "NO IP!"
else:
return ip.replace("127.0.0.1\n", "").replace("\n", " | ")

def print_ip(self):
ip = self.get_ip()
print("IP: {}".format(ip))
screen_output = ip + " - " + ip + " - " + ip
self.sense.display(screen_output, color=[255,98,1])

def run(self):
while True:
self.update_sensors()
Expand Down Expand Up @@ -75,5 +90,8 @@ def settings_updated(self, setting, value):


if __name__ == "__main__":
# sleep for 5 sec to let DHCP finish first before requesting the ip
time.sleep(5.0)
app = SenseApp()
app.print_ip()
app.run()