How to send a warning message when Raspberry Pi industrial PLC is Powered Off

Learn to send a warning notification to your PLC thanks to Raspberry Pi automation
September 17, 2021 by
How to send a warning message when Raspberry Pi industrial PLC is Powered Off
Boot & Work Corp. S.L., Quesada Dani Salvans

 Introduction

The industrial Raspberry PLC can always work properly unless it is disconnected from the power supply. It is always a problem to suffer a power outage or disconnection. Fortunately, Industrial Shields Raspberry-based devices also have the UPS, a part that provides a long enough period of time to power the device until the shutdown process is executed correctly, ensuring that the data will not be corrupted. In this post, you will see how to send a warning message when this phenomenon happens, sending it to an MQTT server, so you can receive the notification wherever you want thanks to industrial automation.

 Related links

How to

Connect Raspberry PLC to Wi-Fi


Read 

Basics about

Raspberry Pi PLC
Analog Outputs


Read 

Raspberry PLC

Family products


See 

Touchberry Pi

Family products


See 

How to

Install Mosquitto: the MQTT-Broker on Raspberry PLC


Read   

  MQTT Client: open source PLC Raspberry Pi

 1. First of all, you have to make the set-up for the MQTT: 

    sudo apt update
    sudo apt upgrade
    sudo apt-get install mosquitto mosquitto-clients

2. Now, you must follow the steps shown on the section 14.1.1 of the UserGuide or the last link on Requirements and write the following code inside the pre-poweroff file:

    #!/bin/bash
    server=10.10.10.3 #MQTT broker server address
    port=1883 #MQTT broker server port
    topic=test #MQTT topic
    message="Raspberry_PLC_power_off"
    mosquitto_pub -h $server -p $port -t $topic -m $message


  MQTT Server: PC (Localhost)

The MQTT broker server can be installed in the most convenient location in each case. In this example, the broker will be a PC, and the alert message will be received using Node-RED.

1. First of all, you have to make the set-up for the MQTT: 

    sudo apt update
    sudo apt upgrade
    sudo apt-get install mosquitto mosquitto-clients

2. You have to run Node-RED in the free port that you prefer:

    node-red -p 8081
3. To receive the notification, you only need to use two nodes; a “mqtt in node” and a “debug node”. Here you must take into account the configuration of the first one, focusing on the mqtt-broker server and port parameters, which must be the same fixed on the client:

debug - MQTT Server: PC (Localhost) - How to send a warning message when Raspberry PLC is Powered Off

Properties - Edit mqtt in node - MQTT Server: PC (Localhost) - How to send a warning message when Raspberry PLC is Powered OffConnection - Properties - Edit mqtt in node - MQTT Server: PC (Localhost) - How to send a warning message when Raspberry PLC is Powered Off


4. Finally, if the industrial Raspberry Pi PLC power goes off, or you disconnect the power supply wire to test it, the UPS will be activated as well as the pre-power off file. Then, you will receive the alert message of “Raspberry_PLC_power_off” in Node-RED or in the location where you have installed the MQTT broker.

​Search in our Blog

How to send a warning message when Raspberry Pi industrial PLC is Powered Off
Boot & Work Corp. S.L., Quesada Dani Salvans September 17, 2021
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>