Cannot find Camera GUID programitcally.

First I get a token using the login API that was generated by the WSDL. then I use that token to get the configuration (again with WSDL generated API). Where I’m lost is where to get the Camera GUID from the configuration. so far everything I try to send to the ImageServer returns with an error “Unknown device”.

I tried all 4 of these:

ServerCommandServiceStub.CameraInfo testCamera =configureationResponse.getGetConfigurationResult().getRecorders().getRecorderInfo()[0].getCameras().getCameraInfo()[0];

1. ServerCommandServiceStub.Guid cameraGuid = testCamera.getDeviceId();

2. ServerCommandServiceStub.Guid cameraGuid = testCamera.getHardwareId();

3. ServerCommandServiceStub.Guid cameraGuid = testCamera.getRecorderId();

4. ServerCommandServiceStub.Guid cameraGuid = configureationResponse.getGetConfigurationResult().getCameraGroups().getCameraGroupInfo()[0].getCameras().getGuid()[0];

this is the error that I get:

<?xml version="1.0" encoding="UTF-8"?>

1

connect

no

Unknown device

no

no

no

no

no

no

0

no

no

yes

yes

Regarding the following code that you wrote -

ServerCommandServiceStub.CameraInfo testCamera =configureationResponse.getGetConfigurationResult().getRecorders().getRecorderInfo()[0].getCameras().getCameraInfo()[0];

We are suspecting if the code might have a cause of the issue. So can you please break down the code and check what variables contain?

For example, first break down might be;

ServerCommandServiceStub.CameraInfo testCamera =configureationResponse.getGetConfigurationResult()

and see the result. And then check “.getRecorders()” and repeat.

I’ve only included the basic extraction part for keeping this condensed because I don’t know where the GUID should come from. What I’m really doing is looping through all the cameras and mating the name of a specific camera to use as my test. That camera, and every other one I have tried to use, fails the same way.

This is extremely messy as I’m just trying to get it to work right now but here is the code. I skipped the auth part but otherwise, this is what I have:

        ServerCommandServiceStub.GetConfigurationResponse configureationResponse =
                service.getConfiguration(configureation);
 
        ServerCommandServiceStub.RecorderInfo[] recorderInfos =
                configureationResponse.getGetConfigurationResult().getRecorders().getRecorderInfo();
 
        ServerCommandServiceStub.CameraInfo testCamera = null;
        ServerCommandServiceStub.RecorderInfo testRecorder = null;
        
int count = 0;
        for (int i = 0; i<recorderInfos.length; i++) {
            ServerCommandServiceStub.RecorderInfo recorderInfo = recorderInfos[i];
            ServerCommandServiceStub.CameraInfo[] cameraInfos = recorderInfo.getCameras().getCameraInfo();
            System.out.println("recorderInfo.getWebServerUri(): "+recorderInfo.getWebServerUri());
            for (int j = 0; j < cameraInfos.length; j++) {
                ServerCommandServiceStub.CameraInfo cameraInfo = cameraInfos[j];
                System.out.println("recorder["+i+"] camera["+j+"] name: "+cameraInfo.getName());
                count++;
                if(cameraInfo.getName().equals("<Camera name form the printed names above>")){
                    testRecorder = recorderInfo;
                    testCamera = cameraInfo;
                    System.out.println("^^^^");
                }
            }
        }
        System.out.println("count: "+count);
        ServerCommandServiceStub.Guid cameraGuid = testCamera.getDeviceId();
 
System.out.println("cameraGuid: "+cameraGuid);
 
//tried both literal "dummy" and the actual username and password
        String simpleConnect =
                "<?xml version=\"1.0\"  encoding=\"UTF-8\"?>"
                        + "<methodcall>"
                        + "  <requestid>1</requestid>"
                        + "  <methodname>connect</methodname>"
                        + "  <username>"+"dummy"+"</username>"
                        + "  <password>"+"dummy"+"</password>"
//                        + "  <username>"+username+"</username>"
//                        + "  <password>"+password+"</password>"
                        + "  <cameraid>"+cameraGuid+"</cameraid>"
                        + "  <connectparam>id="+UUID.randomUUID().toString()+"&amp;connectiontoken="+token+"</connectparam>"
                        + "</methodcall>";
 
        System.out.println("testRecorder.getWebServerUri(): "+testRecorder.getWebServerUri());
        int colonIndex = testRecorder.getWebServerUri().lastIndexOf(':');
        int slashIndex = testRecorder.getWebServerUri().lastIndexOf('/');
 
        System.out.println("testRecorder.getWebServerUri() ':' index: "+colonIndex);
        System.out.println("testRecorder.getWebServerUri() '/' index: "+slashIndex);
 
        int port = Integer.parseInt(testRecorder.getWebServerUri().substring(colonIndex + 1, slashIndex));
 
        System.out.println("port: "+port);
 
 
        Socket socket = new Socket(testRecorder.getHostName(),port);
 
        PrintStream out = new PrintStream(socket.getOutputStream());
        BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
 
        System.out.println("output Stream: ");
        out.println(simpleConnect);
        out.println();
 
        System.out.println("input Stream: ");
        String line = in.readLine();
        while(line != null && !line.equals("")) {
            System.out.println(line);
            line = in.readLine();
        }
        System.out.println("end");

Let me explain a little bit more. What we suggest in the previous post was to break down the code.

If configureationResponse.getGetConfigurationResult() is empty, then you cannot get correct return from the rest of the methods. So please check if configureationResponse.getGetConfigurationResult() is not empty and get configurationresult, and then run .getRecorders() and check if you can get recorders. If you get recorders then please run getRecorderInfo(); and please see what the rerun contains.

I don’t see how my response fails to answer that. if you go through my code it goes through every part of the configurationResutls printing most of them along the way. the proof that I have the camera objects is when I print the recorderInfo.getWebServerUri() and cameraInfo.getName(). more than that I print the Camera GUID as well. nothing is empty.

We cannot know the output of what your code is doing so still a bit hard to determine what is happening.

However, this part of your code: “UUID.randomUUID().toString()” should be the guid of the camera, which I doubt the current is? Please try with changing that.

Also, to ensure you have a proper camera GUID you can check it by going to the camera in Management Client and hold down CTRL while navigating to the Info tab for the camera. You should then see the camera ID near the bottom of the tab.

The goal is to get whatever comes back from “connect” method.

The initial response was to traverse the object in a single line because if any part of it was missing it would fail. Regardless of anything else I’m able to print the values so they are not missing. Regardless, I’m not actually doing it in a single I’m looping though the objects exactly as suggested. Not only that but I’m printing stuff as I go, no nothing is empty. Once I get down to an individual camera I’m trying to assign it’s guid to “cameraGuid” where it will be filled into the XML. I have tried 4 different values (all of them are not null or empty) and all of them give me an error.

1. ServerCommandServiceStub.Guid cameraGuid = testCamera.getDeviceId();

2. ServerCommandServiceStub.Guid cameraGuid = testCamera.getHardwareId();

3. ServerCommandServiceStub.Guid cameraGuid = testCamera.getRecorderId();

4. ServerCommandServiceStub.Guid cameraGuid = configureationResponse.getGetConfigurationResult().getCameraGroups().getCameraGroupInfo()[0].getCameras().getGuid()[0];

(the last one is a completely different rout so I included the path in a single line but, again, there was no nullPointer exception and it printed a non-null non-empty string.)

I’m not sure why you think I’m using UUID.randomUUID for the camera when it’s not in the camera field. As I understand it, based on the documentation, you’re meant to use a random guid in the connection param to create a unique id for your connection. if I made more calls I would use the same id for that session. Now I suppose that could be wrong but the error I’m getting tells me the error I’m getting seem to be pretty clear that the device id I’m providing isn’t working so I’m inclined to believe that this is not the problem.

Because the error says “Unknown device” I leads me to believe that the “cameraid” filed populated with “cameraGuid” in my code, is wrong. I’ve tried to populate that field with everything I could think of, listed in my initial post, and non of them work.

Could you please let me know where you read that the GUID provided after id= in the connectparam should be a random GUID? According to this it has to be the GUID of the camera: https://doc.developer.milestonesys.com/html/index.html?base=reference/protocols/imageserver_request_response.html&tree=tree_3.html

If this still does not work please try with camera ID found in Management Client (and put it in both connectparam and cameraid) as I suggested above.

It has this in the connect method for the XML

<?xml version="1.0"  encoding="UTF-8"?>
<methodcall>
  <requestid>1</requestid>
  <methodname>connect</methodname>
  <username>dummy</username>
  <password>dummy</password>
  <cameraid>[guid]</cameraid>
  <connectparam>id=[guid]&amp;streamid=[guid]&amp;connectiontoken=[token]</connectparam>
</methodcall>

In it says “[guid]” so I assumed the camera guid went there. Then it fails without the value “id=[guid]” so I assumed it needed a new guid like when we made one for “instance” when getting the token. that being said I added the camera guid to the id as suggested and I was able to get a Success response.