1

I have a python script that besides other stuff does this:

        #turn all lights 3 on
        for val in EntranceFloodLights:
            time.sleep(timeBetweenSwitches) #delay between switches for overload
            GPIO.setup(val, GPIO.OUT) 
            GPIO.output(val, GPIO.LOW) # set LOW to switch ON

        #save TSLA
        f= open("lastActivation.txt","w+")
        f.write( "%s" % timeNow)
        f.close()

        #set delay for lights to go off in timeToStayOn
        time.sleep(timeToStayOn)

        for val in currentStatus:

            time.sleep(timeBetweenSwitches) #delay between switches for overload

            if currentStatus[val] == 0:
                GPIO.setup(val, GPIO.OUT)
                GPIO.output(val, GPIO.HIGH) # set HIGH to switch OFF

When i run this through shell, it works perfectly,
Unfortunately, when i run it through the web page i set up to control my lights, it does turn off the light, but stops somewhere before writing the file i ask it to.
Any ideas on what i'm missing?
Keep in mind this is my first python script, so i am a total newbie on this.

Thanks in advance

3
  • Please explain in detail: 1) Exactly how this is executed by what web server, 2) Exactly where "somewhere before writing the file" is; you should be able to determine this with debug logging yourself.
    – goldilocks
    Commented May 12, 2017 at 15:03
  • 1
    Whenever I have a problem like this I immediately suspect the file open statement. i.e., while I am testing I am probably in the correct directory and it works perfectly. Yet then while running it in another environment (cron or apache), I find I need to plan on it starting from a different current directory. Therefore, often these kinds of problems can be solved in Python by giving a fully-qualified filename in the open statement just to be sure it can find it.
    – SDsolar
    Commented May 12, 2017 at 16:48
  • Thanks SDsolar, will try full paths out and come back to you
    – krasatos
    Commented May 15, 2017 at 12:39

0

Browse other questions tagged or ask your own question.