OPC UA Integration - Berufskolleg-Meschede/MESchede GitHub Wiki

OPC UA Integration

The backend communicates with the Siemens S7 PLC using OPC UA. The detailed, current protocol and offline test guide is maintained in docs/opc-ua-integration.md; consult it before changing the handshake or testing against equipment.

Order handshake

Production and delivery use the same order worker and handshake implementation. The configured order nodes contain a header, product queue, and feedback. In the current interface, Feedback.StatusMES values 0, 1, and 5 represent idle, started, and finished. The MES sends the start command only after writing and checking the order data. It cleans its input fields and acknowledges completion after finished feedback is observed.

The worker does not automatically repeat an uncertain start write. It reconnects and observes state, and it reconciles persisted active work after a backend restart. Both order types share a FIFO, so only one order is sent at a time.

Node browse names can be updated from /settings/. Only configured names are variable; node structure and field names remain defined by the PLC contract.

Product catalog

The application reads the PLC catalog from DB_MES_Schnittstelle.Produktspezifikation (singular; the former plural spelling is retained as a compatibility alias). It skips the empty catalog index zero and uses actual product IDs and descriptions. A complete catalog snapshot is stored in PostgreSQL. The worker refreshes it periodically; a stale or unavailable catalog blocks admission of a new order until a valid snapshot is available.

GET /orders/input-context reads the stored catalog. POST /orders/catalog/sync explicitly refreshes it from the PLC and does not submit an order or write PLC nodes. A one-off import without starting the order worker is documented in the repository integration guide.

Live inventory

GET /plc-storage/ reads the housing, lid magazine, and high-rack nodes directly from the PLC using a connection separate from order dispatch. The frontend /inventory page polls this endpoint. A PLC error is returned as 503; it is not silently replaced with RabbitMQ or stale database values.

Result certainty and equipment testing

A completed handshake is not by itself proof of a good unit count. Configure OPC_UA_PRODUCT_RESULTS only for result codes confirmed by the controls team and enable the corresponding verified-contract setting only after that confirmation. Unknown results are not measured quality. Do not infer production quantities from the requested queue.

Use the Backend (FastAPI, PLC debugging) launch profile without auto-reload for equipment-connected sessions. Use the simulated PLC tests for offline development. The integration guide records known limits and the steps for controlled testing.