Skip to content

Instantly share code, notes, and snippets.

@sunng87
Created June 29, 2013 09:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunng87/5890563 to your computer and use it in GitHub Desktop.
Save sunng87/5890563 to your computer and use it in GitHub Desktop.
Displaying IP address of wlan0 on LCD.
#!/usr/bin/python
from Adafruit_CharLCD import Adafruit_CharLCD
from subprocess import *
from time import sleep, strftime
from datetime import datetime
lcd = Adafruit_CharLCD()
cmd = "ip -4 addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1"
lcd.begin(16,1)
def run_cmd(cmd):
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
output = p.communicate()[0]
if p.returncode != 0:
return None
return output
lcd.message("Obtaining IP\n")
lcd.message("...")
while 1:
lcd.clear()
ipaddr = run_cmd(cmd)
if ipaddr:
lcd.message("wlan0 IP Addr:\n")
lcd.message(ipaddr)
break
sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment