# Connect Heidenhain CNC with OPC UA Support

This tutorial walks you through the process in a step by step fashion. We will connect a modern TNC7 based machine. The described steps however are also valid for any other version that supports the OPC UA connectivity.

Let's get started!

### Step 1 - Allow SSH access via password

On your CNC machine you have to temporarily enable password-based access via SSH.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2F0rIoNQusTi3Di4tNkQPL%2FScreenshot%20(2).png?alt=media&#x26;token=93844e12-b914-4910-a51c-d11527c843f1" alt=""><figcaption></figcaption></figure>

For that go to "Einstellungen".

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FdkYgLiObaIdIE6mTGceE%2FScreenshot%20(3).png?alt=media&#x26;token=06c707ee-120a-415b-97e0-578d2aa5a1a5" alt=""><figcaption></figcaption></figure>

In "Betriebssystem" select "Current User" and click "Öffnen".

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2F8G0sCqJHI2CRsr2axvbL%2FScreenshot%20(4).png?alt=media&#x26;token=d63d4e76-7f8c-4a9d-ac50-608f573ec32a" alt=""><figcaption></figcaption></figure>

In the popup select "Zertifikate und Schlüssel".

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FqIIa0d8F7da3xa4uXxIw%2FScreenshot%20(5).png?alt=media&#x26;token=5b8ea108-cea6-465e-bdbe-3c3b33a7112f" alt=""><figcaption></figcaption></figure>

Check the "Erlaube Authentifizierung mit Passwort".

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FvUAbs56TDWs7eyka4qGv%2FScreenshot%20(6).png?alt=media&#x26;token=710cb795-9cb0-48b2-9497-33dbdf727624" alt=""><figcaption></figcaption></figure>

And then restart the internal SSH server by clicking "Speichern & Server neu starten".

That's all for now on the machine.

### Step 2 - Download and start an Edge Connector

Open the App Builder using a computer that has access to the CNC machine(s).

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FVFdXURuydWZFjk7p7qTc%2FScreenshot%20(7).png?alt=media&#x26;token=8de4dda6-bf94-4cd5-98cd-aa99e36d40be" alt=""><figcaption></figcaption></figure>

Start configuring an Edge Connector by clicking the cloud icon in the "Functionality" panel.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2Ftyo5pBjNb2F7F1exPmyM%2FScreenshot%20(8).png?alt=media&#x26;token=11ada8b9-7d2d-4266-ad7e-154ff8a57c35" alt=""><figcaption></figcaption></figure>

Check both the OPC UA Client and the Heidenhain OPC UA connector. Use a prefix that for example identifies your company and click "Submit".

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FJg2fGPibiSuz4UlImYa8%2FScreenshot%20(10).png?alt=media&#x26;token=a2c0558b-9f3d-4f0e-916c-37c7eae7e5a5" alt=""><figcaption></figcaption></figure>

As the Edge Connector is freshly compiled (to embed all security aspects of your account/workspace) this may take some time - typically not more than 2 minutes.

Please wait patiently until a download dialogue opens (on some browsers the download will start automatically).

{% hint style="info" %}
You can always find the Edge Connector executable in the "Resources" panel under the "Edge Connectors" folder and download them again from there.
{% endhint %}

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FGSg2rJPsl1DE6MPkJlvD%2FScreenshot%20(11).png?alt=media&#x26;token=1033d1e1-2076-498b-a06c-3f8ec5b1b15d" alt=""><figcaption></figcaption></figure>

On your local file system create a new folder, e.g. "Heisenware" and place the Edge Connector in there.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FG87t6OURGrWmXbJTDHVs%2FScreenshot%20(12).png?alt=media&#x26;token=873ac816-ad90-4c61-bc65-fdd365a9c9a7" alt=""><figcaption></figcaption></figure>

Start the Edge Connector by double-clicking and allow Windows to execute it by clicking "Weitere Informationen".

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FU1MujQHBElBELqjJXw64%2FScreenshot%20(13).png?alt=media&#x26;token=af3987c1-de3d-4b42-a1f4-64d32023e23d" alt=""><figcaption></figcaption></figure>

Finally click on "Trotzdem ausführen".

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FExYgCVMnhoHUTw5swB03%2FScreenshot%20(14).png?alt=media&#x26;token=09bf849d-34e1-4cd5-8023-6a3702c44686" alt=""><figcaption></figcaption></figure>

If everything worked a terminal window should open, saying the connection to the broker is `[OK]` and at the same time the Edge Connector should appear in the "Functionality" panel of the App Builder.

{% hint style="info" %}
In case the Edge Connector does not connect, but tries re-connecting all the time, make sure your firewall allows to dial out on port 8883 for establishing a secure MQTTS connection.
{% endhint %}

### Step 3 - Setup certificates for the OPC UA connection

In order to connect to the Heidenhain OPC UA server a functioning PKI infrastructure has to be in place and four types of certificates must be exchanged:

From machine to host:

1. CA certificate and revocation list
2. Server certificate

From host to machine:

3. Client certificate
4. User certificate

This is a very complex and sensitive process, fortunately you have to do this only once per machine and our Edge Connector is helping you in getting this right.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FZSSihS9XY0yuWFrhH5IQ%2FScreenshot%20(16).png?alt=media&#x26;token=5f876dba-770e-46ae-a801-9211055b84be" alt=""><figcaption></figcaption></figure>

Drag the "create" function of the Heidenhain module to a section of the logic board.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FDxy6phIyaqaeGspCLipc%2FScreenshot%20(21).png?alt=media&#x26;token=b9dfe796-7a2f-43d2-8bc8-aafe5d9fce60" alt=""><figcaption></figcaption></figure>

Select an instance name (here: "tnc7") and provide the machine IP address to the "machineIpAddress" property. Trigger the function by pressing the return icon on the green trigger item.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2Ff8U2t0AGQnpNP6TcP2P4%2FScreenshot%20(25).png?alt=media&#x26;token=c611d947-0413-40b0-b30d-df280366e62e" alt=""><figcaption></figcaption></figure>

Drag the two functions "prepareOpcUaAssistant" and "finalizeOpcUaAssitant". Trigger the preparation function. If you can see the above return value it worked and you can switch to your machine again.

### Step 4 - Use the OPC UA Assistant on the machine

On your machine open the OPC UA Assistant.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2F5QsPlAdi51T4WeWmDyBu%2FScreenshot%20(26).png?alt=media&#x26;token=08930880-b2e7-4614-a1e0-cfbf262aa640" alt=""><figcaption></figcaption></figure>

On the TNC7 you can find it under "Einstellungen" => "Netzwerk/Fernzugriff" => "OPC UA" => "OPC UA Verbinundungsassistent". On an TNC640 you have to open the heros menu and navigate there.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2Fg01RZLHlPsUaB41zrZYm%2FScreenshot%20(27).png?alt=media&#x26;token=cd0442a8-6a50-47f4-8981-a0e6f32bb36a" alt=""><figcaption></figcaption></figure>

Go step by step through the assistant.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2Fx691K5g9dJxlPwoPpoBr%2FScreenshot%20(28).png?alt=media&#x26;token=cfd926ec-9f2d-4f41-a5b7-0590dca12ae4" alt=""><figcaption></figcaption></figure>

When exporting the server certificates, navigate to the "TNC:" drive, you will find a "heisenware" folder there and inside another "export" folder.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FotW24wWduili2zJGk9zN%2FScreenshot%20(29).png?alt=media&#x26;token=df9fedaf-8557-4819-be33-9e6fccdba933" alt=""><figcaption></figcaption></figure>

Use this to export the all the machine certificates into.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FsHJhSG1wn0WuLxZOTTHj%2FScreenshot%20(31).png?alt=media&#x26;token=007e69c3-a49b-4d66-a4c4-f8135ee24f86" alt=""><figcaption></figcaption></figure>

Click the "Alle Zertifikate exportieren" and move to the next step using "Vorwärts".

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2F1WYlYhQO2dXsz9fh55wx%2FScreenshot%20(33).png?alt=media&#x26;token=2a4af38c-46fa-4ef3-8234-b8a9ca21d889" alt=""><figcaption></figcaption></figure>

During this step the assitant wants to import the client certificate, again navigate to the "heisenware" folder but this time use the "import" folder.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FbtIzYkdPGj4mfT8jhFpc%2FScreenshot%20(34).png?alt=media&#x26;token=3a79a1ef-d896-4ee9-9603-70d0fd4f9235" alt=""><figcaption></figcaption></figure>

Select the "heisenware\_opcua\_client.der" certificate and finalize the import.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2Fl6kJyxD6S4J0hNENSv1i%2FScreenshot%20(36).png?alt=media&#x26;token=a59266d4-54f8-427c-912b-38b539408879" alt=""><figcaption></figcaption></figure>

During the next step you have to activate the OPC UA connection, for that check the corresponding checkbox and click "Anwenden". Then go to the next step.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2F0caYiAVr5Q713M26MHqC%2FScreenshot%20(38).png?alt=media&#x26;token=9ee3e890-bf7b-46dd-855a-055142ddee09" alt=""><figcaption></figcaption></figure>

Now its time to import the user certificate. Again use "heisenware/import" but this time select the "heisenware\_opcua\_user.der" certificate.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FKT6oDNa1rXuJSpTPqS0B%2FScreenshot%20(40).png?alt=media&#x26;token=1cc5efd8-a3ff-487e-9a79-d0aec8b37930" alt=""><figcaption></figcaption></figure>

Finally, I you haven't done it already, allow the firewall to accept OPC UA traffic.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FPAua2MIioLj0YK9RNe4h%2FScreenshot%20(41).png?alt=media&#x26;token=2e627931-84d1-4820-9785-72b3b8bd08f6" alt=""><figcaption></figcaption></figure>

Change the OPC UA "Methode" by double-clicking and selecting the "Allen erlauben" option. Afterwards reload the firewall configuration using "Firewall-Konfiguration neu laden".

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FDYlr49PnWE4eNyC8yejL%2FScreenshot%20(43).png?alt=media&#x26;token=b782c6fe-14d5-466b-a1d0-d2a169599876" alt=""><figcaption></figcaption></figure>

Things should look like this. You can simply go forward or even finish the assistent now. That's all you had to do.

### Step 5 - Connect to the OPC UA server

Back in your App Builder (which now can run on any other browser) finalize the setup.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FRKxri4Py0h4rufIOYs0k%2FScreenshot%20(45).png?alt=media&#x26;token=1760958e-b93c-4729-94c9-fbcd5bdf2864" alt=""><figcaption></figcaption></figure>

Click the "finalizeOpcUaAssistant" and you should see a success message.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FalK2oTOwipas6hpJzoTp%2FScreenshot%20(46).png?alt=media&#x26;token=1c76e56b-cc52-496b-976e-e307a8da9087" alt=""><figcaption></figcaption></figure>

You can now drag the "connect" function and simply execute it. If you see a "true" you made it!

The rest follows our regular App Builder methodology, so enjoy working with your machine and crafting great Apps!

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FncZ8Z3j190SC07T0mVpY%2FScreenshot%20(48).png?alt=media&#x26;token=9b8a6a8a-7628-4201-b7b1-ad27579a392a" alt=""><figcaption></figcaption></figure>
