How to send a warning message when the Raspberry PLC is Powered Off
17 September, 2021 by
How to send a warning message when the Raspberry PLC is Powered Off
Boot & Work Corp. S.L., Quesada Dani Salvans

 INTRODUCTION

Raspberry PLC can always work in a right way unless it is disconnected from the power supply. It is always an issue to suffer a power cut off or a disconnection. Fortunately, our Raspberry based devices also have the UPS, a piece that provides a period of time large enough to power the device until the power off process is executed in the right way, ensuring that the data is not going to be corrupted. In this post we are going to see how to send a warning message when this phenomena happens, sending it to an MQTT server so you can receive the notification wherever you want.

 RELATED LINKS

How to

Connect Raspberry PLC to Wi-Fi


Raspberry PLC

Family products


Basics about

Raspberry Pi PLC
Analog Outputs


Touchberry Pi

Family products


  MQTT Client: Raspberry PLC

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

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

 2. Now, we 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 every case. In this one, explained as an example, the broker is going to be a PC, and the alert message will be received using Node-RED.

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

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

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

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






4.-Finally, if the Raspberry power is cutted off, or we disconnect the power supply wire to test it, the UPS will be activated as well as the pre-poweroff file, and we will receive on Node-RED or the location that we have the MQTT broker installed,  the alert message of "Raspberry_PLC_power_off".

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

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 >>>

Do you want more information?

Just fill the form!

Tell me more!