Push notifications are a web service that allows a remote server to send short information messages to all registered subscribers. Messages are displayed on the terminal device (mobile phone, PC, etc.) in the form of a pop-up window. The only necessary condition for subscribing to notifications is an installed Internet browser, with which the user loads the web pages of the server and registers the subscription.
This service, intended primarily for web servers, was also used with the Foxtrot system, primarily for the purpose of sending any information about the system status. The great advantage of this solution is that no supporting application is required to receive notification messages, just a suitable internet browser. Today, the Web Push notification service is already supported by most well-known browsers (Chrome, Firefox, Opera) on all platforms. However, the service is not supported on Apple's iOS systems. To register for the notification, it is necessary to load the generated web page of the PLC web server into the internet browser. The script contained in the page ensures the installation of the client necessary to receive messages. However, the second limiting factor here may be the fact that the Internet browser allows the installation of the client only from a verified source, which can only be an HTTPS server with a certificate verified by a certification authority. Foxtrot 1 does not have a server that enables HTTPS communication. Foxtrot 2 already offers a server with HTTPS communication, but by default the system is equipped with a self-signed certificate, which is not enough to verify security. A simple solution for both systems is to use the TecoRoute service. This allows an encrypted connection to the PLC web server, while the communication passes through the domain route.tecomat.com, whose identity is verified.
The primary part of the entire implementation is a notification server providing the distribution of information messages. This server is distributed for the Foxtrot 2 series PLC as an optional installable SW package. The installation can be done from the system configuration web pages. For the Foxtrot 1 system, it is necessary to use external HW (eg FoxBerry module), on which the server is subsequently started. The PLC program is connected to the server by a defined protocol and gives it instructions for sending notification messages.
Let's now show a simple implementation of a notification system with a Foxtrot 2 PLC.
First it is necessary to install the software package teco-notifications from the web configuration interface:
The package contains a notification server that can be configured:
Access to the server can be secured using a password that is used to encrypt communications. Another restriction may be restricting access to the server only from a defined IP address. Since we use Foxtrot 2, where the PLC client runs on the same machine as the server, we can set the acceptance of connections only from localhost (127.0.0.1). The Submit button must be used to save the changes and restart the server.
We will insert the NotifyLib library into the project in the Mosaic environment:
In the WebMaker tool, we then define a web page in which a button for registering a notification subscription will be generated:
The use of the library can be demonstrated on the following simple program:
PROGRAM prgMain
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
init : BOOL;
sendRqst : BOOL;
notification : TWebPushNotif;
webPush : fbWebPushService;
END_VAR
VAR_TEMP
END_VAR
IF NOT init THEN
notification.title := 'Notice';
notification.body := 'The end of the service interval is approaching';
notification.image := 'https://bit.ly/2Lurtu7';
notification.icon := 'https://bit.ly/2Lkb3DH';
init := TRUE;
END_IF;
webPush(init := (NOT webPush.ready) AND System_S.R_EDGE_10SEC, send := sendRqst, serverPort := 5000, chanCode := ETH1_uni, notification := notification);
sendRqst := FALSE;
END_PROGRAM
The basis is the fbWebPushService
function block, which ensures communication with our notification server. The connection parameters must match the server configuration (127.0.0.1:5000). In our case, an attempt to establish a connection with the server is performed at regular 10s intervals until it is successfully established, which is signaled by the output variable webPush.ready
. The content of the notification message is given by the structure of the TWebPushNotif
type. In the example, it is initialized to default values after starting the program. Images that we want to display in the notification message must be defined using the url address. Therefore, to display an image on a device receiving a notification message, the image must be publicly available. The instruction itself to send a notification message is controlled by the sendRqst
variable, which can be controlled in a real situation, for example by a button in a web page or an event in an application program.
If the PLC program is running and the function block is successfully connected to the notification server, we can now connect clients to receive notifications. The client can be a mobile phone or PC, or an Internet browser installed on such a device. To register a subscription, it is necessary to visit the PLC web server page, which we set up for this purpose in the previous steps. An important condition is that this site is hosted by a server verified by a certification authority. If this condition is not met, the browser will not allow you to register notifications (the registration button will not be displayed on the page). In our case, we will solve this problem by accessing the PLC using the TecoRoute service.
It can be noticed that in our loaded PLC web page, a button with a bell symbol is displayed in the lower right corner. Pressing this button will register the browser to receive notifications. If the receipt of notifications is registered for the first time for a given server domain name (route.tecomat.com), the browser will display the notification itself, which must be acknowledged. If the symbol of the registration button changes, the registration was successful and it is possible to try to receive notification messages. In our case, we control the sendRqst variable with a button from a web page.
On an Android mobile phone, the same situation will look like this:
If the user wishes to unsubscribe from notification messages on the given device (browser), this can be done by pressing the registration button with the bell symbol again.
Notification subscriptions allowed
Notification subscriptions disabled