Apr-08-2021, 01:01 PM
When I run this in Thonny IDE, the LEDs light up like they are supposed to and the rest of the code works fine. when I run this as a cronjob I get everything except the LEDs. How do I make the LEDs persist until the cron job runs again on the next tenth minute (*/10 * * * *)?
import time import sys import requests from gpiozero import LED from gpiozero import Button #Define LED indicators - these are GPIO numbers LED1 = LED(21) #Blue LED2 = LED(26) #Red LED3 = LED(20) #Amber LED4 = LED(19) #Green LED5 = LED(16) #Green LED6 = LED(13) #Green LED7 = LED(6) #Green LED8 = LED(12) #Green LED9 = LED(5) #Pink EMULATE_HX711=False reset = Button(18) #def reset(): # average = keg1 # print("Average has been reset to current weight") #reset.when_released = reset referenceUnit = 1 if not EMULATE_HX711: import RPi.GPIO as GPIO from hx711 import HX711 else: from emulated_hx711 import HX711 hx = HX711(27, 22) hx.set_reading_format("MSB", "MSB") hx.set_reference_unit(1) #hx.reset() #hx.tare() keg1 = hx.get_weight() + 250000 keg1 = keg1 - 75700 print(keg1) alert = "Keg1Q " + str(keg1) base = "autoremotejoaomgcd.appspot.com/sendmessage?key=SecretDeviceIDHiddenForSecurity&message=" alerturl = "https://"+base+alert r = requests.post(alerturl) percent = (keg1/502700) * 100 print(percent) percentT = str(round(percent, 2)) print(percentT) if 1 >= percent <= 102: #keg is outside of usable range - flashes when keg is missing (indicating tare is complete at startup) LED1.blink(.2,.2) else: LED1.off() if 1.1 >= percent >= 5: #Red less than 5% - DANGER LED2.blink(.5,.5) else: LED2.off() if 101 >= percent >= 10: #Amber less than 10% - Warning LED3.on() else: LED3.off() if 101 >= percent >= 20: # Green 10-20% - Caution LED4.on() else: LED4.off() if 101 >= percent >= 40: #Green2 20-40% LED5.on() else: LED5.off() if 101 >= percent >= 60: #Green3 40-60% LED6.on() else: LED6.off() if 101 >= percent >= 80: #Green4 60-80% LED7.on() else: LED7.off() if 101 >= percent >= 80.1: #Green5 80-100% LED8.on() else: LED8.off() hx.power_down() hx.power_up()