HOW TO RESET A PLC USING THE ETHERNET SHIELD

HOW TO RESET A PLC USING THE ETHERNET SHIELD

In this post it will be seen how to configure the Ethernet Shield to allow the user sending a reset via Ethernet, instead of pressing the button manually. This configuration is useful in order to upload an sketch using the Ethernet shield instead of the USB. Tipically the upload is made via USB, in this case the Arduino IDE sends an order to the Arduino shield to reset it. When it is via Ethernet this is not possible by default. I mean that you have to send a command which the Ethernet shield will accept in order to reset. This is why it has to be configured. 

This configuration is made using the own software of the sketch. This means that in the sketch you need to add some configuration telling that when you talk with the PLC via Ethernet using a certain port, it will reset automatically.

Let’s see how it is done this configuration in the software:

#include <avr/wdt.h;                                              //library to enable the remote reset
#include <Ethernet2.h;                                            //library to configure the Ethernet Shield

uint8_t mac[] = {0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed};             //mac name
uint8_t ip[] = {192, 168, 1, 211};                                //ip name

EthernetServer server(2000);                                      //port for the communication

void setup() {
    wdt_disable();                                               //disabled remote reset in the setup
    Serial.begin(9600L); 
    Serial.println("remote-reset started");
    Ethernet.begin(mac, ip);                                     //configure the ethernet shield with mac,ip name
    server.begin();                                              //enable the server communication
}

void loop() {
    wdt_reset();                                                 //reset the library to prepare the remote reset
    EthernetClient client = server.available();                  //looks if there is something on port 2000
    
    if (client) {
        wdt_enable(WDTO_4S);                                     //force the reset
        while (true);
   }
   //Code for the Arduino 
}

Using this sketch we will be configuring the shield to give it a name in order to talk to the PLC using Ethernet. Now the PLC is able to reset by the time you send a single character (“a”) after stablishing conexion using the IP 192.168.1.211 and the port 2000.  

 

SEE ALSO: TCP CLIENT ON ARDUINO BASED PLCTCP SERVER ON TOUCHBERRY PI 3 WITH NODE.JS

Comments are closed.