Iam using 2 raspberry pi, 1 raspberry( called client) has signal input which has to be forward to the 2nd raspberry (called server) which has to give an output.
On the client i made 2 scripts called check.py and send.py, when in check.py GPIO23 input is high it must call the script send.py. This script send.py connects to the server which activate the script ledup.py (ledup.py located at the 2nd raspberry) which makes his GPIO24 output high for an amount of time. In the meanwhile check.py is in a loop and keeps checking his input.
Problem is i not get it all working, i try to combine the scripts on the client to 1 script what makes more errors so i kept it split in 2 scripts. Check.py not working good, it not stays in a loop and does nothing when gpio input 23 get high. When i add print command, to check if its working standalone then i get an output. Send.py when i test standalone its working and activates ledup.py, but nothing happens when check.py has gpio23 high... I really need some help with the check.py, this is were i get stuck.
script check.py:
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
try:
while True:
input_state = GPIO.input(23)
if input_state == True:
os.sytem("python /home/pi/send.py")
time.sleep(0.5)
else:
GPIO.output(24, False)
time.sleep(0.5)
except:
GPIO.cleanup()
script send.py:
import subprocess
import sys
HOST="pi@10.10.4.180 -p22"
ssh = subprocess.Popen(["ssh",
"%s" % HOST],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
bufsize=0)
ssh.stdin.write("sudo python /home/pi/ledup.py")
ssh.stdin.close()
script ledup.py:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(24,GPIO.OUT)
GPIO.output(24,GPIO.HIGH)
time.sleep(0.8)
GPIO.output(24,GPIO.LOW)
GPIO.cleanup()