Get ip address send it to a lcd display
Same with cpu temp and displaying date and time
The functions are written with a loop that is supposed to run for about a minute then what it's supposed to do is go to the next function
I want the LCD to display the temp for a minute then display the date and time again for a minute then the ip address for a minute then I'd like it to loop back to the start, the way I have it now each function called runs for a minute then it stops the script
Refer to the while true part at the bottom
curtime ()
tempcpu()
getip ()
Each one works on their own if I comment out 2 of the 3 definitions above but not as I intended as described, any help would be greatly appreciated as I'm new to python
Code: Select all
#!/usr/bin/env python
#import RPi.GPIO as GPIO
import lcd_driver
import socket
import struct
import fcntl
import time
import os
from time import sleep
disp = lcd_driver.lcd()
t_time = time.time() + 60 * 1
def tempcpu():
while time.time() < t_time:
def measure_temp():
temp = os.popen("vcgencmd measure_temp").readline(
return (temp.replace("temp=","").replace("'C\n",""
)
temp1 = int(float(measure_temp()))
temp2 = int(float(9.0/5.0*temp1+32))
disp.lcdstring("Temp: " + str(temp1) + " C", 1, 0)
disp.lcdstring("Conv: " + str(temp2) + " F", 2, 0)
if time.time() => t_time:
break
def curtime():
while time.time() < t_time:
disp.lcdstring("Time: %s" %time.strftime("%H:%M:%S"),
,0)
disp.lcdstring("Date: %s" %time.strftime("%m:%d:%Y"),
,0)
sleep(1)
def getip():
while time.time() < t_time:
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRA
)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915,
struct.pack('256s', ifname[:15]),
) [20:24])
disp.lcdstring("IP Address:",1)
disp.lcdstring(get_ip_address('wlan0'),2)
sleep(1)
try:
while True:
tempcpu()
curtime()
getip()
except KeyboardInterrupt:
disp.clear()
sleep(1)
disp.backlight(0)