Skip to content

Commit

Permalink
check if dir exists before trying to create file
Browse files Browse the repository at this point in the history
  • Loading branch information
TrystanLea committed Oct 4, 2019
1 parent 94ebe89 commit c3ad4a5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lcd/emonPiLCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,16 @@ def __init__(self, logger):
logger.info("I2C LCD DETECTED 0x%s" % i2c_address)
current_lcd_i2c = "0x%s" % i2c_address
# add file to identify device as emonpi
open('/home/pi/data/emonpi', 'a').close()
if os.path.isdir('/home/pi/data/'):
open('/home/pi/data/emonpi', 'a').close()
break

if lcd_status.rstrip() == 'False':
print ("I2C LCD NOT DETECTED on either 0x" + str(lcd_i2c) + " ...exiting LCD script")
logger.error("I2C LCD NOT DETECTED on either 0x" + str(lcd_i2c) + " ...exiting LCD script")
# add file to identify device as emonbase
open('/home/pi/data/emonbase', 'a').close()
if os.path.isdir('/home/pi/data/'):
open('/home/pi/data/emonbase', 'a').close()
sys.exit(1)

# Init LCD using detected I2C address with 16 characters
Expand Down

0 comments on commit c3ad4a5

Please sign in to comment.