web_relais.ino

Arduino Opta (micro PLC, STM32H747) · File : web_relais.ino · Language : Arduino · Use case : Commander la PLC depuis une page web embarquée

A web page served by the Opta itself: relay states and analog input displayed, control buttons as plain HTTP links. Remote machine troubleshooting without opening the cabinet, with zero software dependencies.

Hardware

An STMicroelectronics Opta PLC (real-time STM32H747 + secure i.MX RT1052 companion) programmed with the Arduino PLC environment, 24 V DIN-rail supply. Opta on the network; any browser (shop PC or phone on the workshop Wi-Fi).

Wiring

RJ45 cable; write down the static IP from the setup on the cabinet door. Never expose this server to the Internet without a VPN.

How it works

The server parses the GET line: /relais?n=&etat= applies the relay command then returns the HTML page with live state.

Running it

Install the Arduino PLC boards manager, select “Opta PLC”, wire USB/DFU and upload. The sketch runs on the real-time STM32H747 side.

Variants

Add a token in the URL to restrict access, an auto refresh (meta refresh), or a priority emergency-stop button.

web_relais.ino

// Opta PLC : mini serveur web embarqué — page de commande des relais.
// GET /            -> page HTML   GET /relais?n=1&etat=on -> commande
#include "PLCContainer.h"
#include <Ethernet.h>

PLCContainer PLC;
EthernetServer serveur(80);

void page(EthernetClient &c) {
  c.println("HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n"
            "Connection: close\r\n\r\n"
            "<h2>Opta PLC</h2><ul>");
  for (int i = 0; i < 2; i++) {
    c.print("<li>RO"); c.print(i + 1);
    c.print(PLC.Relay[i].state() ? " : <b>ON</b> " : " : OFF ");
    c.print("<a href=\"/relais?n="); c.print(i);
    c.println(PLC.Relay[i].state() ? "&etat=off\">couper</a></li>"
                                   : "&etat=on\">activer</a></li>");
  }
  c.print("</ul>AI1 = "); c.print(PLC.AnalogIn.read(OPTA_AI_1));
  c.println(" mV"); c.stop();
}

void setup() {
  PLC.begin();
  byte mac[] = { 0x00, 0x80, 0xE1, 0x14, 0x22, 0x35 };
  PLC.Eth.begin(mac, IPAddress(192, 168, 1, 62), IPAddress(192, 168, 1, 1));
  serveur.begin();
}

void loop() {
  EthernetClient c = serveur.available();
  if (!c) return;
  String req = c.readStringUntil('\n');       // ligne GET /...
  if (req.startsWith("GET /relais")) {
    int n = req.substring(req.indexOf("n=") + 2).toInt();
    bool on = req.indexOf("etat=on") > 0;
    if (n >= 0 && n < 2) PLC.Relay[n].write(on);
  }
  page(c);
  delay(5); c.stop();
}

← Back to the board