Knifa / led-matrix-zmq-server

A tool for streaming frames to rpi-rgb-led-matrix over ZeroMQ.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example request for sending frames

iamalexriley opened this issue · comments

Hi @Knifa

Thank you for your work on this. I'm new to everything here, but I think I am close to understanding zeroMq w/ rpi-rgb-led-matrix.

I'm not sure how the server is sending the frames. Could you please show example of server API and how you send the byte frame from another rpi?

Cheers!

commented

Hello! Yes, I can put together a better example soon. If you're looking for a quick example to grab you can take a look at this repository here: https://github.com/Knifa/matryx-gl.

These files in particular will be of interest:

https://github.com/Knifa/matryx-gl/blob/master/src/Matrix.hpp
https://github.com/Knifa/matryx-gl/blob/master/src/Canvas.cpp

The summary though is:

  • The ZMQ server listens with REQ, the client sending data should use REQ.
  • On starting the server immediately waits for frame data on the specified address.
  • The client should connect to this, and send a byte array that matches the frame size with the selected bit-depth. By default this is 24bit, so e.g., for a 64x64 LED array you should send 12,228 bytes. E.g., you send the first pixel's red colour byte, then blue colour byte, then green colour byte, then the next pixel's red colour byte, etc. and so on.
  • The client should then wait for an empty reply. The server will acknowledge with an empty reply.
  • That's it! It'll loop from here. There's no framing, protocol, or anything else.

@Knifa thanks for implementing this, feel like I am almost there but would love for a more dumbed down example coming from an art background and trying to hack a live display together.

@Knifa I have successfully implemented a REQ-REP server + client in python on port 42024 (can see hello world on the pi and my desktop) and am now trying to send gif frames to your server from a python client (as far as I can tell there should be no issue sending from python to C++). There doesn't seem to be an issue running the docker instance but there is no indication that anything is being received. Any help would be greatly appreciated, I would love to avoid redoing the matrix link in python and don't know C++.

Rpi
sudo bash zmqMatrixServer.sh (contains matrix parameters)
Listening on tcp://*:42024 @ 24BPP
Frame dimensions: 64x32
Expected frame size: 6144 bytes

Desktop Client:
Connecting to matrix server
expected frame size:6144, actual frame size: 6144
sending frame
sent frame

Python client:

from PIL import Image
import zmq
tcp = "tcp://192.168.10.2:42024"

print("Connecting to matrix server")
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect(tcp)

try:
im = Image.open("./gradient2.gif")
for frame in range(0,im.n_frames):
im.seek(frame)
im = im.convert("RGB")
frameToSend = im.tobytes("raw")
print("expected frame size:6144, actual frame size:",len(frameToSend))
print("sending frame")
socket.send(frameToSend)
print("sent frame")
message = socket.recv()
print("Received reply [ %s ]" % (message))
except EOFError:
print("done")
pass

commented

@aidanfowler are you running your Python client on a different machine? You might need to do some fiddling with Docker to get it to allow external connections, e.g. pass -p 42024:42024 to Docker to forward the port from the container to your machine properly --- bit of a guess! I haven't looked at this project for a little while but you should at least get some output even if you're sending the wrong data.