We are going to do a walkthrough of how we can send a notification using Connect IoT. This is just a suggestion of an implementation, every use case may have its particularities and variations.
Topics
- Notification
- Setting up the MES
- Adding to our Workflow
- Enriching our Notification
Notification
A Notification
is an asynchronous way of broadcasting a message to all or some MES users. It allows to generate an alarm within the MES and without namely through sending emails. This is very useful to call the users to act upon a particular event. In this use case we will setup for a case, where we want to be notified whenever the system is disconnected.
Info: Notifications are part of Alarm Management, which is a Critical Manufacturing optional module.
Info: The user must have an Employee object associated in order to be able to use Notifications.
Setting up the MES
In order to create a notification we must create a Rule that will invoke a DEE that will create a notification. This DEE may have inputs that will feed information to our Notification.
Creating a DEE
In this use case we will want to send a notification on disconnect. I will create a DEE called CustomSendNotificationOnDisconnected
with classification ConnectIoT
. I want my DEE to be flexible in creating a notification, this can be achieved with a table or in our case with configuration.
The first thing in our DEE is importing Foundation:
UseReference("Cmf.Foundation.BusinessObjects.dll", "Cmf.Foundation.BusinessObjects");
var serviceProvider = (IServiceProvider)Input["ServiceProvider"];
Now we can retrieve all our configs, in my case they live under /Notification/:
Config.TryGetConfig("/Notification/Name", out var notificationName);
Config.TryGetConfig("/Notification/Description", out var notificationDescription);
Config.TryGetConfig("/Notification/Details", out var notificationDetails);
Config.TryGetConfig("/Notification/EmailDistributionList", out var notificationEmailDistributionList);
Config.TryGetConfig("/Notification/SendEmailToAssignedParty", out var notificationSendEmailToAssignedParty);
Config.TryGetConfig("/Notification/Severity", out var notificationSeverity);
Config.TryGetConfig("/Notification/Title", out var notificationTitle);
Config.TryGetConfig("/Notification/Type", out var notificationType);
Config.TryGetConfig("/Notification/NotificationAssignedToRole", out var notificationAssignedToRole);
Feel free to create the configurations and populate with default values.
Now we can create our notification:
Cmf.Foundation.BusinessObjects.Abstractions.INotification notification = serviceProvider.GetService<Cmf.Foundation.BusinessObjects.Abstractions.INotification>();
notification.Name = notificationName.Value + Guid.NewGuid().ToString();
notification.Description = notificationDescription.Value as string;
notification.Details = notificationDetails.Value as string;
notification.EmailDistributionList = notificationEmailDistributionList.Value as string;
notification.SendEmailToAssignedParty = ((bool?) notificationSendEmailToAssignedParty.Value) ?? false;
notification.Severity = notificationSeverity.Value as string;
notification.Title = notificationTitle.Value as string;
notification.Type = notificationType.Value as string;
if (!string.IsNullOrEmpty(notificationAssignedToRole.Value as string))
{
IRole role = serviceProvider.GetService<IRole>();
role.Load(notificationAssignedToRole.Value as string);
notification.AssignedToRole = role;
}
notification.Create();
For now we are just using the configurations to provide information to our notification.
Now we can execute our DEE (select Execute
button) and see the notification being created.
Creating a Rule
The DEE is working, we need the action that will wrap it and be used to trigger it. The action must be of Scope
ConnectIoT and of course it needs to select the DEE that was created.
Adding to our Workflow
We have a Rule and this rule can be invoked in the Connect IoT Workflow. In our example, we want to create a notification if we disconnect. The communication state is given by the task On Equipment Setup
output OnCommunicationChange. This output will always emit the new communication state. In order to address, this we will create a switch for the state machine of the communication state.
After having our switch we can use the Disconnected output to feed our Rule. In order to invoke rules in Connect IoT we use the task Execute Action
. In this task, select the Rule that we’ve created.
Info: Only Rules created under the scope ConnectIoT will show in the task to be selected.
Connecting everything:
Running the Automation Manager
In order to test this implementation, simply start the Automation Manager and then Stop it. This will trigger a Disconnected communication state that will trigger the notification.
You can see the notification is called and it will show as the one generated when we executed the DEE.
Enriching our Notification
In our previous use case, even with configurations, we had a very static definition of our notification. Let’s then save an error message in the Notification
details. This could come from the Error output of a task, but in this case let’s just create a constant message saying Controller Disconnected
.
In the Execute Action task create an Input ErrorMessage and as default value Controller Disconnected
. In the DEE we will need to change it to receive an external input called ErrorMessage and change the details of the notification to log our error message.
var errorMessage = Input["ErrorMessage"] as string;
notification.Details = errorMessage;
Save the DEE as a new effective version.
Now, repeating the process of starting and stopping the automation a new notification is create and has as details our expected message.
This finishes our post, as you can see the mechanisms of communication between the Connect IoT and the MES are very powerful and can provide a lot of synergies.
Author
Hello 👏 , my name is João Roque ✌️
I’ve been working for some years at Critical Manufacturing. I split my time working in the IoT Team and working with the project’s teams. You can visit me at https://j-roque.com/ or check me at LinkedIn
Skills: Connect IoT / DevOps