Sending Emails with a Siemens 1500 PLC
Mohammed Omer
Lead Electrical & Automation Engineer Industrial Automation ?? Process Automation Certified Systems Integrator| SCADA Specialist Industry 4.0| PLC | RTU | HMI | VFD |IOT| BMS DCS |OT/ICS | Automation Courses Instructor
Out of the box, Siemens 1500 PLCs can send emails through a third-party email service provider. This interface supplies a mechanism for alerting relevant personal of faults, warnings, and other status information.
The following guide outlines the steps required for establishing a secure connection to an email server and using the TMAIL_C function block to send messages.
This configuration requires a 1500 PLC with minimum firmware V2.0. If you are using a PLC which does not meet these requirements, you may need an additional communication module to establish a connection to the server. These steps also assume that your PLC is connected to the internet via a router.
The basic tasks are outlined below:
I used TIA Portal V15.1 for this walkthrough. The procedure may differ slightly for different versions.
Configuring Email Server
For this example, we created a dedicated Gmail account to act as an email server. This server communicates with the PLC via Simple Mail Transfer Protocol (SMTP) and transmits emails to the final recipient. For most providers, the default settings will need to be changed to enable the sending of messages via an external program. If you're using a Gmail account, turn off two-step verification and enable less secure app access in your account settings. Without this access, the PLC connection to the server will be rejected.
Obtaining Encryption Certificate
The Transport Layer Security (TLS) protocol is used to encrypt the SMTP communications between the PLC client and the email server to ensure a secure connection. Consequently, the PLC needs the certificate associated with the email service provider to sign and encrypt messages.
In Internet Explorer, the name of the relevant certificate can be obtained by navigating to your service providers webpage and opening the security report. When I created this walkthrough, Gmail used the Google Trusted Services – GlobalSign Root CA-R2 certificate.
After determining the correct name, locate the certificate in your computer's certificate manager and export it as a *.cer file in the DER encoded binary format. In the next step, we will import this certificate into TIA Portal before adding it to the PLC hardware configuration. This allows the PLC to communicate with the email server using the additional security provided by the TLS protocol.
Importing Certificate into TIA Portal
After configuring the email server and obtaining the correct certification file, the remaining configuration is performed in TIA Portal. First, a project administrator must be specified, providing access to the additional security features of the project. These features allow us to add a third?party certificate to the project.
To create an administrator, navigate to the security settings for the project and define the necessary credentials. Note, these credentials will be required to access the project in the future.
After defining a security administrator, the security settings of the project should include additional security features, including the certificate manager. To import the certificate file, navigate to the certificate authority, and right-click to import the file. After importing, the certificate containing the public key required for the SMTP connection should appear in the manager.
Note the expiration date of the certificate, as it may need updating in the future. Furthermore, ensure that the PLC time is set correctly, as the factory default may fall outside of the certificate’s valid range.
Updating PLC Hardware Configuration
After importing the certificate into the project, the hardware configuration of the PLC must be updated to establish a connection to the email server. This process involves adding the certificate to the device and configuring the DNS server settings.
First, navigate to the certificate manager in the Protection & Security settings of the device configuration. Enable the use of the global security settings to provide full functionality. Then, add the certificate as a partner device. Note that if the certificate manager settings tab does not appear, then your hardware likely does not support this configuration. In this case, you may need to use an external communication module to use the TMAIL_C function block.
领英推荐
After adding the certificate to the hardware configuration, we need to verify the DNS server settings of the PLC. A Domain Name System (DNS) server is required to associate domain names with the IP addresses needed for routing information between the PLC and the email server.
For this application, the router connecting the PLC to the internet will act as the DNS server. Consequently, the router address must match the DNS server address in the hardware configuration. After verifying the router address in the PLC’s PROFINET interface, navigate to the DNS configuration and add it to the list of DNS server addresses.
If you are unsure the proper address, you can use the ipconfig command on a PC networked to the PLC to determine the default gateway of your local network.
Configuring the TMAIL_C Function Block
After the hardware configuration for the PLC is complete, the final task involves setting up the TMAIL_C function block to send messages. This block can be found under Communication in the Instruction Window.
The MAIL_ADDR_PARAM input is used to define the connection details. For an S7-1500 CPU, the TMail_V4_SEC system data type should be used to establish a secure connection using IPv4. Note, Siemens provides several additional data types for communicating with a server using different protocols.
The parameters of the TMail_V4_SEC data type need to be defined as follows:
Using the TMAIL_C Function Block
After configuring the address parameters, using the TMAIL_C block is relatively straightforward. A message's recipient, subject, and body are defined using the FBs respective inputs. Optionally, an attachment can be defined, allowing arrays of data to be included as an attachment to the email.
A message request is triggered on the rising edge of the REQ input. The block executes asynchronously over several cycles, during which the BUSY output will remain high. If the email is sent successfully, the DONE output will pulse for a single scan. If it fails, the ERROR output will pulse, and the STATUS will update with the relevant error code.
There you have it! These steps provide the basic outlining for setting up an SMTP client on a Siemens 1500 PLC. For additional information, see the related Siemens application example in addition to the help files associated with the TMAIL_C connect block.
Manager Electronic & Instrumentation Pakistan Beverage limited
2 周[email protected]