Events from External Device

We are developing a plugin with some references to the SensorMonitor plugin, where we are trying to get the events from an external device. The external device has an API we call to get the events.

We have tested some hypothesis and are unsure about how to proceed, because we haven’t been able to integrate it successfully.

We have tried to communicate with the external device directly from a Background Plugin calling the external device’s API, but while checking the MIP Logs, after we verified the Event Server wasn’t starting properly, we found there was a large number of calls in the Logs referencing: “CommunicationService:URL net.tcp://:22333/CommunicationService”. Does this mean the Background Plugin, when sending a request to the external device, is communicating through this Communication Service, in the specific port (22333)? And in that case, the large amount of requests is probably making the Event Server malfunction?

I am aware that it is possible to send Analytics Events via XML, where we would have a program obtaining the events from the external device and translate them into a Anylitic Event XML file to send to the specific port. Is that the best method to work with events from an external device? Wouldn’t it have conflicts with any other product that uses the same methods?

Can you please explain how you communicate between external device’s API and the background plugin? Are you using Message communication or something else? It would be great if you could describe a bit more about it.

Yes, I understand the question to be quite vague. I don’t know if this explanation is better.

The program is supposed to send from the background plugin a HTTP request, using the RestSharp library. The API returns a JSON with information, that is parsed and “translated” into the correct Item in the Milestone VMS. This “translation” is basicly done by checking the values from the JSON message and matching them to an ID we’ve given to the plugin Item.

That’s just what I’m trying to accomplish. The way the background plugin knows the IP address of the external device from which to communicate, is that the IP address is sent from the Management Client after configuring an Item we created in the MIP plugin area, but that part hasn’t failed because I’ve checked.

I think what I’m struggling with is that I use the method that calls the API in the Init() part of the background plugin and I think it just makes the event server malfunction, because I’ve put it in a indefinite loop.

I should probably use a messagecommunication event handler in some way to then start the background plugin API caller function, instead of calling it directly in the Init() method.

Although I find it strange all the “CommunicationService:URL net.tcp://:22333/CommunicationService” mentions that appear in the log file.

I don’t know if a sample of the code helps understanding further, because the code that calls the API is the standard request/response call used in the RestSharp library, but I can provide it.

You should not use message communication for this.

Assuming you have received your event from the external device, construct a BaseEvent with a filled out EventHeader and use the EnvironmentManager.Instance.SendMessage with NewEventCommand to get the system to handle the new event.

I don’t know if it’s using message communication like you say. I’ve already done the handling of the event from the external device, where the JSON from the API is parsed and then inserted in an EventHeader and I handle the event like this:

EventHeader eventHeader = new EventHeader()
{
         ID = Guid.NewGuid(),
         Class = "Operational",
         etc...
 };
 AnalyticsEvent eventData = new AnalyticsEvent
 {
         EventHeader = eventHeader,
 };
 EnvironmentManager.Instance.SendMessage(new Message(MessageId.Server.NewEventCommand) { Data = eventData });

I know how to launch the event from the Milestone VMS with the API information, because instead of having the method calling the API be indefinite, I’ve run it once and it got it right.

But my problems are, I think, related to calling the external device’s API, within an indefinite method, in the Init() method of the Background Plugin and therefore it is blocking the event server from working/starting correctly.

you should not use a lot of time in the Init method, just start another thread to perform you action from the Init method.