Необходимо написать скрипт - tcp сервер, который будет стартовать при запуске системы raspberry pi,
и принимать данные на 6000 порт и при получении текстовой строки совпадающей с требуемой - менять логическое значение GPIO.
Ниже скрипт который был написан мной, но считывается только единичный символ, и работает не со всеми устройствами. Стоимость работи комментарии пишите в личку.
##server.py
from socket import * #import the socket library
import RPi.GPIO as GPIO
import time
##let's set up some constants
HOST = '' #we are the host
PORT = 6000 #arbitrary port not currently in use
ADDR = (HOST,PORT) #we need a tuple for the address
BUFSIZE = 4096 #reasonably sized buffer for data
## now we create a new socket object (serv)
## see the python docs for more information on the socket types/flags
serv = socket( AF_INET,SOCK_STREAM)....
##bind our socket to the address
serv.bind((ADDR)) #the double parens are to create a tuple with one element
serv.listen(5) #5 is the maximum number of queued connections we'll allow
serv = socket( AF_INET,SOCK_STREAM)....
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(18, GPIO.OUT) #relay1
GPIO.setup(16, GPIO.OUT) #relay2
GPIO.setup(15, GPIO.OUT) #relay3
GPIO.setup(13, GPIO.OUT) #relay4
GPIO.setup(7, GPIO.OUT) #relay5
GPIO.setup(11, GPIO.OUT) #relay6
GPIO.setup(22, GPIO.OUT) #led
GPIO.output(18, GPIO.HIGH)
GPIO.output(16, GPIO.HIGH)
.
##bind our socket to the address
serv.bind((ADDR)) #the double parens are to create a tuple with one element
serv.listen(1) #1 is the maximum number of queued connections we'll allow
while 1:
conn,addr = serv.accept() #accept the connection
while 1:
data = conn.recv(1024)
if (data=='4'):
GPIO.output(22,True)
time.sleep(0.3)
GPIO.output(18,False)
time.sleep(0.5)
GPIO.output(18,True)
time.sleep(0.3)
GPIO.output(22,False)
if (data=='3'):
GPIO.output(22,True)
time.sleep(0.3)
GPIO.output(16,False)
time.sleep(0.5)
GPIO.output(16,True)
time.sleep(0.3)
GPIO.output(22,False)
if (data=='5'):
GPIO.output(22,True)
time.sleep(0.3)
GPIO.output(16,False)
GPIO.output(18,False)
time.sleep(0.9)
GPIO.output(16,True)
GPIO.output(18,True)
time.sleep(0.3)
GPIO.output(22,False)
if not data:
break