Skip to content

Instantly share code, notes, and snippets.

@sweemeng
Last active June 22, 2016 02:20
Show Gist options
  • Select an option

  • Save sweemeng/f3ce99966a253b9f9aeedff3a850ca52 to your computer and use it in GitHub Desktop.

Select an option

Save sweemeng/f3ce99966a253b9f9aeedff3a850ca52 to your computer and use it in GitHub Desktop.
Just a script to show system hostname and ip on piface 2. Works well if have .local domain setup properly
  • install python wireless module
sudo pip install wireless
#!/usr/bin/python
import pifacecad
import socket
import time
from wireless import Wireless
SLEEP_TIME=5
def main():
cad = pifacecad.PiFaceCAD()
network_detected = False
while True:
try:
try:
hostname = socket.gethostname()
ip_addr = socket.gethostbyname(hostname)
if not network_detected:
cad.lcd.write("Got network!")
time.sleep(SLEEP_TIME)
cad.lcd.clear()
network_detected = True
except socket.gaierror:
cad.lcd.write("No network, waiting")
time.sleep(SLEEP_TIME)
continue
cad.lcd.cursor_off()
show_hostname(cad, hostname)
show_ip(cad, ip_addr)
show_network(cad)
except KeyboardInterrupt:
cad.lcd.clear()
cad.lcd.write("Bye")
time.sleep(SLEEP_TIME)
cad.lcd.clear()
break
def show_hostname(cad, hostname):
cad.lcd.home()
cad.lcd.write("Hostname:")
cad.lcd.set_cursor(0,1)
cad.lcd.write(hostname)
time.sleep(SLEEP_TIME)
cad.lcd.clear()
def show_ip(cad, ip_addr):
cad.lcd.home()
cad.lcd.write("IP Address:")
cad.lcd.set_cursor(0,1)
cad.lcd.write(ip_addr)
time.sleep(SLEEP_TIME)
cad.lcd.clear()
def show_network(cad):
wl = Wireless()
essid = wl.current().split()[0]
cad.lcd.home()
cad.lcd.write("ESSID:")
cad.lcd.set_cursor(0,1)
cad.lcd.write(essid)
time.sleep(SLEEP_TIME)
cad.lcd.clear()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment