I am trying to use this code Can someone who is a better programmer make this multithread for me with up to 8 threads?
I cannot get more than 1 button to work when I press one it locks the pi/cayenne until that button/script/timer is done. I’d like to use this for pump controls and have multiple running at the same time but in different variations/seconds the pumps are on for each one. but not a single script because the times needed are different depending on soil moisture contents ( a whole other project ) so for now I just need this script turned into multithread and I’m tired of racking my brain trying and not getting it to work.
# The callback for when a message is received from Cayenne.
def on_message(message):
print("message received: " + str(message))
# If there is an error processing the message return an error string, otherwise return nothing.
if (message.channel == 2) and (message.value == "0"):
subprocess.Popen('python3 11.py', shell=True)
print("done")
if (message.channel == 3) and (message.value == "0"):
subprocess.Popen('python3 12.py', shell=True)
print("done")
that worked. new problem is i have to turn the button off/on to get it run the script is there a command to make it relay back to the button or for the buttom to check which status or just auto change back to last status or something?
so to get the button to work ( run the script ) I have to press it once for on ( run script) then a second time for off ( does nothing ) but then when i hit it a 3rd time for on it will run the script.
I tried to trigger “when press on turn button X off” but it did not always work just sometimes it would work and sometime it wouldnt trigger at all.
is there any way to add the button as a momentary button?