User Tools

Site Tools


burim:python:lcd

lcd_cron_temp_v2.py

#!/usr/bin/python
import os
import glob
import time
import lcddriver
import subprocess, platform
lcd = lcddriver.lcd()

#os.system('modprobe w1-gpio')
#os.system('modprobe w1-therm')

dest_check = 'ssh -i /home/pi/.ssh/id_rsa -o ConnectTimeout=1 -o ConnectionAttempts=2 -o StrictHostKeyChecking=no pi@10.11.12.130 exit; echo $?'
dest_check_nc_aruba_fr = 'nc -z -v -w5 172.17.17.7 22; echo $?'
dest_check_nc_aruba_cz = 'nc -z -v -w5 172.31.32.1 22; echo $?'
dest_temp = 'ssh -i /home/pi/.ssh/id_rsa pi@10.11.12.130 "python /usr/local/bin/temp-sensor1.py"'

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
#device_file = device_folder + '/w1_slave'
device_file = '/sys/bus/w1/devices/28-020e91771447/w1_slave'
def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_c

def read_temp_zlla():
    conn_check_temp = subprocess.Popen(dest_check, shell=True, stdout=subprocess.PIPE)
    conn_check = float(conn_check_temp.stdout.read())
    if conn_check == 0:
      temp_zlla_c_temp = subprocess.Popen(dest_temp, shell=True, stdout=subprocess.PIPE)
      temp_zlla_c = float(temp_zlla_c_temp.stdout.read())
      return temp_zlla_c
    else:
      return "DOWN"

def check_up_or_down(dest_check):
    conn_check_nc_shell = subprocess.Popen(dest_check, shell=True, stdout=subprocess.PIPE)
    conn_check_nc = float(conn_check_nc_shell.stdout.read())
    if conn_check_nc == 0:
      return "Up"
    else:
      return "DOWN"


lcd.lcd_clear()
temp1 = "Temp1: " + str(read_temp())
lcd.lcd_display_string(str(temp1),1)
temp2 = "Temp2: " + str(read_temp_zlla())
lcd.lcd_display_string(str(temp2),2)
lcdrow3 = "Link Aruba Fr: " + str(check_up_or_down(dest_check_nc_aruba_fr))
lcd.lcd_display_string(str(lcdrow3),3)
lcdrow4 = "Link Aruba CZ: " + str(check_up_or_down(dest_check_nc_aruba_cz))
lcd.lcd_display_string(str(lcdrow4),4)
#logging
loggertemp1 = "/usr/bin/logger temp executed - " + temp1
loggertemp2 = "/usr/bin/logger temp executed - " + temp2
#print(temp1)
#print(temp2)
subprocess.Popen(loggertemp1, shell=True, stdout=subprocess.PIPE)
subprocess.Popen(loggertemp2, shell=True, stdout=subprocess.PIPE)
  • other option
#!/usr/bin/python
import os
import glob
import time
import lcddriver
import subprocess, platform
lcd = lcddriver.lcd()

#os.system('modprobe w1-gpio')
#os.system('modprobe w1-therm')

dest_check = 'ssh -i /home/pi/.ssh/id_rsa -o ConnectTimeout=1 -o ConnectionAttempts=2 -o StrictHostKeyChecking=no pi@10.11.12.130 exit; echo $?'
dest_check_nc_aruba_pi4_zllapek = 'nc -z -v -w5 10.11.12.130 22; echo $?'
dest_check_nc_aruba_fr = 'nc -z -v -w5 172.17.17.7 22; echo $?'
dest_check_nc_aruba_cz = 'nc -z -v -w5 172.31.32.1 22; echo $?'
dest_temp = 'ssh -i /home/pi/.ssh/id_rsa pi@10.11.12.130 "python /usr/local/bin/temp-sensor1.py"'

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
#device_file = device_folder + '/w1_slave'
device_file = '/sys/bus/w1/devices/28-020e91771447/w1_slave'
def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_c

def read_temp_zlla():
    conn_check_temp = subprocess.Popen(dest_check_nc_aruba_pi4_zllapek, shell=True, stdout=subprocess.PIPE)
    conn_check = float(conn_check_temp.stdout.read())
    if conn_check == 0:
      temp_zlla_c_temp = subprocess.Popen(dest_temp, shell=True, stdout=subprocess.PIPE)
      temp_zlla_c = float(temp_zlla_c_temp.stdout.read())
      return temp_zlla_c
    else:
      return "DOWN"

def check_up_or_down(dest_check):
    conn_check_nc_shell = subprocess.Popen(dest_check, shell=True, stdout=subprocess.PIPE)
    conn_check_nc = float(conn_check_nc_shell.stdout.read())
    if conn_check_nc == 0:
      return "UP"
    else:
      return "DOWN"


lcd.lcd_clear()
temp1 = "Temp1: " + str(read_temp())
lcd.lcd_display_string(str(temp1),1)
temp2 = "Temp2: " + str(read_temp_zlla())
lcd.lcd_display_string(str(temp2),2)
lcdrow3 = "Link Aruba Fr: " + str(check_up_or_down(dest_check_nc_aruba_fr))
lcd.lcd_display_string(str(lcdrow3),3)
lcdrow4 = "Link Aruba CZ: " + str(check_up_or_down(dest_check_nc_aruba_cz))
lcd.lcd_display_string(str(lcdrow4),4)
#logging
loggertemp1 = "/usr/bin/logger temp executed - " + temp1
loggertemp2 = "/usr/bin/logger temp executed - " + temp2
#print(temp1)
#print(temp2)
subprocess.Popen(loggertemp1, shell=True, stdout=subprocess.PIPE)
subprocess.Popen(loggertemp2, shell=True, stdout=subprocess.PIPE)

version 3

  • import of lcd library happens right before the execution of lcd clear
  #!/usr/bin/python
import os
import glob
import time
import lcddriver
import subprocess, platform
#lcd = lcddriver.lcd() using it down

#os.system('modprobe w1-gpio')
#os.system('modprobe w1-therm')

dest_check = 'ssh -i /home/pi/.ssh/id_rsa -o ConnectTimeout=1 -o ConnectionAttempts=2 -o StrictHostKeyChecking=no pi@10.11.12.130 exit; echo $?'
dest_check_nc_aruba_pi4_zllapek = 'nc -z -v -w5 10.11.12.130 22; echo $?'
dest_check_nc_aruba_fr = 'nc -z -v -w5 172.17.17.7 22; echo $?'
dest_check_nc_aruba_cz = 'nc -z -v -w5 172.31.32.1 22; echo $?'
dest_check_nc_peje = 'nc -z -v -w5 172.17.17.3 22; echo $?'
dest_check_nc_dardi = 'nc -z -v -w5 172.17.17.2 22; echo $?'
dest_temp = 'ssh -i /home/pi/.ssh/id_rsa pi@10.11.12.130 "python /usr/local/bin/temp-sensor1.py"'

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
#device_file = device_folder + '/w1_slave'
device_file = '/sys/bus/w1/devices/28-020e91771447/w1_slave'
def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_c

def read_temp_zlla():
    conn_check_temp = subprocess.Popen(dest_check_nc_aruba_pi4_zllapek, shell=True, stdout=subprocess.PIPE)
    conn_check = float(conn_check_temp.stdout.read())
    if conn_check == 0:
      temp_zlla_c_temp = subprocess.Popen(dest_temp, shell=True, stdout=subprocess.PIPE)
      temp_zlla_c = float(temp_zlla_c_temp.stdout.read())
      return temp_zlla_c
    else:
      return "DOWN"

def check_up_or_down(dest_check):
    conn_check_nc_shell = subprocess.Popen(dest_check, shell=True, stdout=subprocess.PIPE)
    conn_check_nc = float(conn_check_nc_shell.stdout.read())
    if conn_check_nc == 0:
      return "UP"
    else:
      return "DOWN"


temp1 = "T1: " + str(read_temp())
temp2 = ", T2: " + str(read_temp_zlla())
lcdrow2_peje = "Peje:" + str(check_up_or_down(dest_check_nc_peje))
lcdrow2_dardi = ", Dardi:" + str(check_up_or_down(dest_check_nc_dardi))
lcdrow3 = "Link Aruba Fr: " + str(check_up_or_down(dest_check_nc_aruba_fr))
lcdrow4 = "Link Aruba CZ: " + str(check_up_or_down(dest_check_nc_aruba_cz))

#lcd display
lcd = lcddriver.lcd()
lcd.lcd_display_string(str(temp1+temp2),1)
lcd.lcd_display_string(str(lcdrow2_peje+lcdrow2_dardi),2)
lcd.lcd_display_string(str(lcdrow3),3)
lcd.lcd_display_string(str(lcdrow4),4)


#logging
loggertemp1 = "/usr/bin/logger temp executed - " + temp1
loggertemp2 = "/usr/bin/logger temp executed - " + temp2
#print(temp1)
#print(temp2)
subprocess.Popen(loggertemp1, shell=True, stdout=subprocess.PIPE)
subprocess.Popen(loggertemp2, shell=True, stdout=subprocess.PIPE)

version 4

adding for nc check x times with nc

#!/usr/bin/python
import os
import glob
import time
import lcddriver
import subprocess, platform
#lcd = lcddriver.lcd() using it down

#os.system('modprobe w1-gpio')
#os.system('modprobe w1-therm')

dest_check = 'ssh -i /home/pi/.ssh/id_rsa -o ConnectTimeout=1 -o ConnectionAttempts=2 -o StrictHostKeyChecking=no pi@10.11.12.130 exit; echo $?'
dest_check_nc_aruba_pi4_zllapek = 'nc -z -v -w2 10.11.12.130 22; echo $?'
dest_check_nc_aruba_fr = 'nc -z -v -w2 172.17.17.7 22; echo $?'
dest_check_nc_aruba_cz = 'nc -z -v -w2 172.31.32.1 22; echo $?'
dest_check_nc_peje = 'nc -z -v -w5 172.17.17.3 22; echo $?'
dest_check_nc_dardi = 'nc -z -v -w5 172.17.17.2 22; echo $?'
dest_temp = 'ssh -i /home/pi/.ssh/id_rsa pi@10.11.12.130 "python /usr/local/bin/temp-sensor1.py"'

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
#device_file = device_folder + '/w1_slave'
device_file = '/sys/bus/w1/devices/28-020e91771447/w1_slave'
def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_c

def read_temp_zlla():

  i=0
  x=5
  while i < x:
    conn_check_temp = subprocess.Popen(dest_check_nc_aruba_pi4_zllapek, shell=True, stdout=subprocess.PIPE)
    conn_check = int(conn_check_temp.stdout.read())
    i += 1
    time.sleep(5)
    if conn_check == 0:
      temp_zlla_c_temp = subprocess.Popen(dest_temp, shell=True, stdout=subprocess.PIPE)
      temp_zlla_c = float(temp_zlla_c_temp.stdout.read())
      return temp_zlla_c
      i = x
  else:
    return "DOWN"

def check_up_or_down(dest_check):
    conn_check_nc_shell = subprocess.Popen(dest_check, shell=True, stdout=subprocess.PIPE)
    conn_check_nc = float(conn_check_nc_shell.stdout.read())
    if conn_check_nc == 0:
      return "UP"
    else:
      return "DOWN"


temp1 = "T1: " + str(read_temp())
temp2 = ", T2: " + str(read_temp_zlla())
lcdrow2_peje = "Peje:" + str(check_up_or_down(dest_check_nc_peje))
lcdrow2_dardi = ", Dardi:" + str(check_up_or_down(dest_check_nc_dardi))
lcdrow3 = "Link Aruba Fr: " + str(check_up_or_down(dest_check_nc_aruba_fr))
lcdrow4 = "Link Aruba CZ: " + str(check_up_or_down(dest_check_nc_aruba_cz))

#lcd display
lcd = lcddriver.lcd()
lcd.lcd_display_string(str(temp1+temp2),1)
lcd.lcd_display_string(str(lcdrow2_peje+lcdrow2_dardi),2)
lcd.lcd_display_string(str(lcdrow3),3)
lcd.lcd_display_string(str(lcdrow4),4)


#logging
loggertemp1 = "/usr/bin/logger temp executed - " + temp1
loggertemp2 = "/usr/bin/logger temp executed - " + temp2
#print(temp1)
#print(temp2)
subprocess.Popen(loggertemp1, shell=True, stdout=subprocess.PIPE)
subprocess.Popen(loggertemp2, shell=True, stdout=subprocess.PIPE)
burim/python/lcd.txt · Last modified: 2019/08/18 19:35 by burim

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki