How can we get the online/offline status of our cameras from the Milestone Server from a custom Windows service written in C#. Should this be done through the Websocket API? I would be grateful if someone could point me in the right direction. Thanks!
Hi
You can get the status using messaging. Check out ProvideCurrentStateResponse in the SDK doc. You’ll need to send a message and then listen for the response
eg.
//You need to setup the messaging object etc.
//Send the request message
private void GetCameraStatus(Item cameraItem)
{
try
{
\_messageCommunication.TransmitMessage(new VideoOS.Platform.Messaging.Message(MessageCommunication.ProvideCurrentStateRequest, new String\[\] { cameraItem.FQID.ObjectId.ToString() }), null, null, null);
}
catch (Exception ex)
{
}
}
//set up a listener
_registrations.Add(_messageCommunication.RegisterCommunicationFilter(ProvideCurrentStateResponseHandler, new VideoOS.Platform.Messaging.CommunicationIdFilter(MessageCommunication.ProvideCurrentStateResponse)));
//Handler
private object ProvideCurrentStateResponseHandler(VideoOS.Platform.Messaging.Message message, FQID dest, FQID source)
{
if (InvokeRequired)
{
Invoke(new MessageReceiver(ProvideCurrentStateResponseHandler), message, dest, source);
}
else
{
Collection<ItemState> result = message.Data as Collection<ItemState>;
if (result != null)
{
foreach (ItemState itemState in result)
{
// DO Something Here
}
}
}
return null;
}
Hope this helps
Ian
Thanks! I can just iterate though all the cameras we have (90 cameras or so), send message and listen for a response (500ms or something)?
Not sure how long it will take to respond. It will depend on your Milestone system. Its normally pretty quick though.
Perhaps you would like to see it in use, in that case you can explore the Status Viewer which uses ProvideCurrentStateRequest at startup.
Thanks! this will help greatly!
In the StatusViewer demo, I relocated all the code from the OnLoad function to a new function named
RefreshList , which is triggered by a button click. However, disabling a camera and subsequently invoking
RefreshList doesn’t result in the removal of the disabled camera from the list. Even though I clear the tree view each time, the issue persists. I also attempted adding Configuration.Instance.RefreshConfiguration(EnvironmentManager.Instance.MasterSite.ServerId.Id);
but it didn’t resolve the problem. Interestingly, restarting the app does successfully remove the disabled camera.
Restarting works, the issue and a possible solution is described here..