I have the following script which is meant to write/read a json file. The problem is it will only write/read the file from the command line and not when using a remote via LIRC.
import RPi.GPIO as GPIO
from time import sleep
import json
GPIO.setmode(GPIO.BOARD)
GPIO.setup(22,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(19,GPIO.OUT)
GPIO.setup(21,GPIO.OUT)
GPIO.setup(23,GPIO.OUT)
abort = False
counter = 0
# read config
try:
with open('config.json') as readfile:
data = json.load(readfile)
if data['lastrun'] == 'up':
print('blind is already up')
abort = True
except:
pass
data = {'lastrun': 'up'}
if abort:
quit()
# write config
with open('config.json', 'w') as outfile:
json.dump(data, outfile, sort_keys=True, indent=4)
print('blind up')
GPIO.output(19,GPIO.HIGH)
GPIO.output(21,GPIO.LOW)
GPIO.output(23,GPIO.HIGH)
while True:
input_state = GPIO.input(22)
if input_state == False:
counter = counter + 1
print counter
if counter == 13:
GPIO.output(23,GPIO.LOW)
exit()
GPIO.cleanup()
sleep (0.3)
This is the entry in the lircrc file
begin
button = KEY_4
prog = irexec
config = sudo python /home/pi/up.py
end