-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
greenie.py
executable file
·64 lines (53 loc) · 1.91 KB
/
greenie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
import subprocess
import time
from lib import I2C_LCD_driver, SHT31_driver
mylcd = I2C_LCD_driver.lcd(1)
temp_rh_sensor = SHT31_driver.SHT31(1)
NIC = 'wlan0'
DEGREE = chr(223)
def get_ip_address(ifname):
cmd = "ifconfig %s |grep 'inet ' |awk '{print $2}'" % ifname
return subprocess.check_output(cmd, shell = True)
def get_ssid(ifname):
cmd = "iwconfig %s |grep ESSID |rev |cut -d '\"' -f2 |rev" % ifname
return subprocess.check_output(cmd, shell = True)
def display_network_info(ssid, ip, display_seconds):
mylcd.lcd_clear()
if len(ssid) > 16:
str_pad = " " * 16
ssid = str_pad + ssid
mylcd.lcd_display_string(ip, 1)
for i in range (0, len(ssid)):
lcd_text = ssid[i:(i+16)]
mylcd.lcd_display_string(lcd_text,2)
time.sleep(0.4)
mylcd.lcd_display_string(str_pad,2)
else:
mylcd.lcd_display_string(IP, 1)
mylcd.lcd_display_string(SSID, 2)
time.sleep(display_seconds)
def display_temp_rh(readings):
mylcd.lcd_clear()
temperature, humidity = temp_rh_sensor.get_temp_and_humidity(unit = 'F')
temp = int(round(temperature))
rh = int(round(humidity))
mylcd.lcd_display_string("Temp: %d%sF" % (temp, DEGREE), 1)
mylcd.lcd_display_string("RH: %d %%" % rh, 2)
time.sleep(1)
for reading in range(1, readings):
temperature, humidity = temp_rh_sensor.get_temp_and_humidity(unit = 'F')
new_temp = int(round(temperature))
new_rh = int(round(humidity))
if new_temp != temp:
mylcd.lcd_display_string("%d%sF" % (new_temp, DEGREE), 1, 6)
if new_rh != rh:
mylcd.lcd_display_string("%d %%" % new_rh, 2, 4)
time.sleep(1)
# Start with a clean display
mylcd.lcd_clear()
while True:
SSID = get_ssid(NIC).rstrip()
IP = get_ip_address(NIC).rstrip()
display_network_info(SSID, IP, 3)
display_temp_rh(7)