Python API formatting

OK, I’m sorry for being totally ignorant about zmq but I need help. I’m trying to enable liveview and take a photo from python and I can’t get anything to happen. I am able to run the example script that listens for and prints messages so I think everything is setup correctly. I just don’t know how to format a request. I want to do something like this:

import zmq

context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.send(b’request that invokes “Shoot”’)

message = socket.recv()

and I expect the camera to capture an image. Can someone help me with an example of how to format the request?

The message needs to be in JSON format.
For python, the easiest thing is to use the “json” import from the python standard library.
You can then construct the message as a python object, and convert it to JSON using the json.dumps() function.

For example, for the “Shoot” request message:

import json

req = {}
req["msg_type"] = "Request"
req["msg_id"] = "Shoot"
req["msg_seq_num"] = 0
req["CameraSelection"] = "All"
msg = json.dumps(req)

There are some examples in the git repo:

Ok, thanks Francis. I see the examples now and I understand a little better but the API documentation is very confusing to me. For example:

I see a message called ‘CameraInfo’ with type ‘object’ and some fields listed. So I think I should be able to access that object like this.

req = {}
req[“msg_type”] = “Request”
req[“msg_id”] = “CameraInfo”
req[“msg_seq_num”] = 0
req[“CameraSelection”] = “All”

But the return value just says “message_result” : False.

Ultimately, I’m looking for some software that will allow me to connect, identify the ‘CameraKey’ for connected cameras, enable liveview and then get the live view data for display in my application. Is this possible?

Firstly, the “msg_id” field needs to be a valid request/response message.

You can see the list of valid messages here, in the “Request/Response Messages” section.

To get the list of all cameras and photos, you can send a “Synchronise” request message, like this:

req = {}
req[“msg_type”] = “Request”
req[“msg_id”] = “Synchronise”
req[“msg_seq_num”] = 0

Or alternatively, to get a list of specific cameras, use the “GetCamera” request, like this:
(this was missing from the docs, I just added it)

req = {}
req[“msg_type”] = “Request”
req[“msg_id”] = “GetCamera”
req[“msg_seq_num”] = 0
req[“CameraSelection”] = “All”