This commit is contained in:
commit
32a3808ca8
1 changed files with 71 additions and 0 deletions
71
neo2lcdscript.py
Normal file
71
neo2lcdscript.py
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import socket
|
||||
import fcntl
|
||||
import struct
|
||||
import psutil
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
home_dir = os.path.expanduser("~")
|
||||
sys.path.append(home_dir)
|
||||
import I2C_LCD_Driver
|
||||
import SDL_DS1307
|
||||
|
||||
|
||||
|
||||
|
||||
mylcd = I2C_LCD_Driver.lcd()
|
||||
ds1307 = SDL_DS1307.SDL_DS1307(0, 0x68)
|
||||
|
||||
def get_ip_address(ifname):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
return socket.inet_ntoa(fcntl.ioctl(
|
||||
s.fileno(),
|
||||
0x8915,
|
||||
struct.pack('256s', ifname[:15])
|
||||
)[20:24])
|
||||
|
||||
#mylcd.lcd_display_string("hello",1)
|
||||
#mylcd.lcd_display_string("IP Address:", 1)
|
||||
|
||||
#mylcd.lcd_display_string(get_ip_address('eth0'), 2)
|
||||
# Return RAM information (unit=kb) in a list
|
||||
# Index 0: total RAM
|
||||
# Index 1: used RAM
|
||||
# Index 2: free RAM
|
||||
|
||||
|
||||
def getRAMinfo():
|
||||
p = os.popen('free')
|
||||
i = 0
|
||||
while 1:
|
||||
i = i + 1
|
||||
line = p.readline()
|
||||
if i==2:
|
||||
return(line.split()[1:4])
|
||||
|
||||
mylcd.lcd_clear()
|
||||
while True:
|
||||
#CPU usage and time
|
||||
|
||||
CPU_usage = psutil.cpu_percent(interval = .5)
|
||||
mylcd.lcd_display_string("CPU Load %s%% " % (CPU_usage), 1)
|
||||
mylcd.lcd_display_string("%s" % ds1307.read_datetime(), 2)
|
||||
time.sleep(3)
|
||||
mylcd.lcd_clear()
|
||||
#IP ADDRESS
|
||||
mylcd.lcd_display_string("IP Address : ", 1)
|
||||
mylcd.lcd_display_string(get_ip_address('eth0'), 2)
|
||||
time.sleep(3)
|
||||
mylcd.lcd_clear()
|
||||
#RAM USAGE
|
||||
RAM_stats = getRAMinfo()
|
||||
RAM_used = round(int(RAM_stats[1]) / 1000,1)
|
||||
RAM_free = round(int(RAM_stats[2]) / 1000,1)
|
||||
mylcd.lcd_display_string("RAM Used %sMB" % (RAM_used),1)
|
||||
mylcd.lcd_display_string("RAM Free %sMB" % (RAM_free),2)
|
||||
time.sleep(3)
|
||||
mylcd.lcd_clear()
|
||||
mylcd.lcd_display_string("All your base",1)
|
||||
mylcd.lcd_display_string("are belong to us",2)
|
||||
time.sleep(3)
|
||||
mylcd.lcd_clear()
|
||||
Loading…
Reference in a new issue