Create a UDP "server" socket on the Pi, and use a client on the laptop to send commands to it. Just send more packages to be sure to get it. UDP won't need you to connect, and it has good latency. Or you can use TCP as well, it's not that different on the Python side.
Since you probably wrote your image recognition program in Python (and added a Python tag), I wrote a simple example (all right, copy-pasted from a project I copy-pasted from somewhere):
Server side:
import socket
UDP_IP = "0.0.0.0" # listen to everything
UDP_PORT = 12345 # port
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(512) # random buffer size, doesn't matter here..
print("received message:", data)
#simplest way to react.. of course, a better parser should be used, and add GPIO code, etc..
if data==b'LED=1\n':
print("LED ON")
elif data==b'LED=0\n':
print("LED OFF")
Client:
import socket
import time
UDP_IP = "127.0.0.1" # set it to destination IP.. RPi in this case
UDP_PORT = 12345
print("UDP target IP:", UDP_IP)
print("UDP target port:", UDP_PORT)
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
while True:
print("Turn ON")
sock.sendto(b'LED=1\n', (UDP_IP, UDP_PORT))
time.sleep(2)
print("Turn OFF")
sock.sendto(b'LED=0\n', (UDP_IP, UDP_PORT))
time.sleep(2)
You could use broadcast to flood everything in your LAN as well.. but RPi gets your message whatever its address is. Also, I added newlines to the protocol, so you can simply test in in netcat: nc -u localhost 12345
then type LED=0
and press Enter.