Skip to content

Commit

Permalink
refactor: linting
Browse files Browse the repository at this point in the history
Signed-off-by: Goetz Goerisch <[email protected]>
  • Loading branch information
GoetzGoerisch committed Nov 28, 2024
1 parent 852b2c5 commit 154f7b9
Show file tree
Hide file tree
Showing 38 changed files with 4,547 additions and 3,516 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,50 @@
[![Node.js CI](https://github.com/AndreasHeine/SampleServer-node-opcua/actions/workflows/node.js.yml/badge.svg)](https://github.com/AndreasHeine/SampleServer-node-opcua/actions/workflows/node.js.yml)
[![CodeQL](https://github.com/AndreasHeine/SampleServer-node-opcua/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/AndreasHeine/SampleServer-node-opcua/actions/workflows/codeql-analysis.yml)
[![Lint Code Base](https://github.com/AndreasHeine/SampleServer-node-opcua/actions/workflows/linter.yml/badge.svg)](https://github.com/AndreasHeine/SampleServer-node-opcua/actions/workflows/linter.yml)
[![Container Build](https://github.com/AndreasHeine/SampleServer-node-opcua/actions/workflows/container_build.yml/badge.svg)](https://github.com/AndreasHeine/SampleServer-node-opcua/actions/workflows/container_build.yml)
[![Container Build](https://github.com/AndreasHeine/SampleServer-node-opcua/actions/workflows/container_build.yml/badge.svg)](https://github.com/AndreasHeine/SampleServer-node-opcua/actions/workflows/container_build.yml)

OPC UA Sample Server based on [node-opcua](https://github.com/node-opcua/node-opcua)
the official book node-opcua: [node-opcua by example](https://leanpub.com/node-opcuabyexample-edition2024) by [Sterfive](https://www.sterfive.com)
API Docs: [2.32.0](https://node-opcua.github.io/api_doc/2.32.0/index.html)
API Docs: [2.32.0](https://node-opcua.github.io/api_doc/2.32.0/index.html)

## Usage

- `download and unpack`
- `open folder in VS Code (or in terminal)`
- `npm install`
- `download and unpack`
- `open folder in VS Code (or in terminal)`
- `npm install`
- `npm run start`

## Example Users

User: `admin` Password: `pw1`
User: `operator` Password: `pw2`
User: `guest` Password: `pw3`
User: `guest` Password: `pw3`

## Ephemeral Dev Environment

- [Click](https://gitpod.io/#https://github.com/AndreasHeine/SampleServer-node-opcua)
- `npm run start`
- split terminal: `opcua-commander -e opc.tcp://localhost:4840/UA` to have a local OPC UA client
## Docker

## Docker

Set "IP" and "PORT" in env:

- `docker run -it -p 4840:4840 -e PORT=4840 -e IP=127.0.0.1 --name sampleserver-node-opcua ghcr.io/andreasheine/sampleserver-node-opcua:main`

## Online Server Instance
- `docker run -it -p 4840:4840 -e PORT=4840 -e IP=127.0.0.1 --name sampleserver-node-opcua ghcr.io/andreasheine/sampleserver-node-opcua:main`

## Online Server Instance

- `opc.tcp://opcua.umati.app:4843`

- `opc.tcp://opcua.umati.app:4843`

## Implementations of OPC UA Companion Specifications

![image](./img/addressspace.PNG)

## OPC UA Pub/Sub over MQTT
## OPC UA Pub/Sub over MQTT

MQTT-Broker: `mqtt://broker.hivemq.com:1883`
MQTT-Topic: `umati/#`
MQTT-Topic: `umati/#`

## License

![GitHub](https://img.shields.io/github/license/AndreasHeine/SampleServer-node-opcua)
Expand Down
128 changes: 72 additions & 56 deletions src/LocalDiscoveryServer/local-discovery-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,76 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {
OPCUADiscoveryServer,
OPCUAServerEndPoint,
ServerSecureChannelLayer,
OPCUACertificateManager,
} from 'node-opcua'
import {
OPCUADiscoveryServerOptions
} from 'node-opcua-server-discovery'

import { green, yellow, red } from './../utils/log'

(async () => {
try {
const config: OPCUADiscoveryServerOptions = {
port: 4840,
serverCertificateManager: new OPCUACertificateManager({
automaticallyAcceptUnknownCertificate: true,
name: 'discovery_pki',
rootFolder: 'discovery_pki',
}),
serverInfo: {
applicationName: {
text: 'SampleDiscoveryServer-applicationName',
locale: 'en' ,
},
applicationUri: 'urn:SampleDiscoveryServer',
productUri: 'SampleDiscoveryServer-productUri',
}
}
const lds = new OPCUADiscoveryServer(config)
.on('newChannel', (channel: ServerSecureChannelLayer, endpoint: OPCUAServerEndPoint) => {
green(` DiscoveryServer: newChannel! ChannelId:${channel.channelId} - ${channel.remoteAddress}:${channel.remotePort} `)
})
.on('closeChannel', (channel: ServerSecureChannelLayer, endpoint: OPCUAServerEndPoint) => {
green(` DiscoveryServer: closeChannel! ChannelId:${channel.channelId} - ${channel.remoteAddress}:${channel.remotePort} `)
})
.on('connectionRefused', (socketData: any, endpoint: OPCUAServerEndPoint) => {
red(` DiscoveryServer: connectionRefused! \n ${endpoint.serverInfo}`)
})
.on('openSecureChannelFailure', (socketData: any, channelData: any, endpoint: OPCUAServerEndPoint) => {
red(` DiscoveryServer: openSecureChannelFailure! \n ${channelData} \n ${endpoint.serverInfo}`)
})
.on('error', (e) => {
red(` DiscoveryServer: ${e} `)
})
.on('debug', (e) => {
yellow(` DiscoveryServer: ${e} `)
import {
OPCUADiscoveryServer,
OPCUAServerEndPoint,
ServerSecureChannelLayer,
OPCUACertificateManager,
} from "node-opcua";
import { OPCUADiscoveryServerOptions } from "node-opcua-server-discovery";

import { green, yellow, red } from "./../utils/log";

(async () => {
try {
const config: OPCUADiscoveryServerOptions = {
port: 4840,
serverCertificateManager: new OPCUACertificateManager({
automaticallyAcceptUnknownCertificate: true,
name: "discovery_pki",
rootFolder: "discovery_pki",
}),
serverInfo: {
applicationName: {
text: "SampleDiscoveryServer-applicationName",
locale: "en",
},
applicationUri: "urn:SampleDiscoveryServer",
productUri: "SampleDiscoveryServer-productUri",
},
};
const lds = new OPCUADiscoveryServer(config)
.on(
"newChannel",
(channel: ServerSecureChannelLayer, endpoint: OPCUAServerEndPoint) => {
green(
` DiscoveryServer: newChannel! ChannelId:${channel.channelId} - ${channel.remoteAddress}:${channel.remotePort} `,
);
},
)
.on(
"closeChannel",
(channel: ServerSecureChannelLayer, endpoint: OPCUAServerEndPoint) => {
green(
` DiscoveryServer: closeChannel! ChannelId:${channel.channelId} - ${channel.remoteAddress}:${channel.remotePort} `,
);
},
)
.on(
"connectionRefused",
(socketData: any, endpoint: OPCUAServerEndPoint) => {
red(` DiscoveryServer: connectionRefused! \n ${endpoint.serverInfo}`);
},
)
.on(
"openSecureChannelFailure",
(socketData: any, channelData: any, endpoint: OPCUAServerEndPoint) => {
red(
` DiscoveryServer: openSecureChannelFailure! \n ${channelData} \n ${endpoint.serverInfo}`,
);
},
)
.on("error", (e) => {
red(` DiscoveryServer: ${e} `);
})
yellow(' DiscoveryServer: starting server... ')
await lds.start()
green(' DiscoveryServer: is running! ')
} catch (error) {
red(` DiscoveryServer error: ${error}`)
process.exit(-1)
}
})()
.on("debug", (e) => {
yellow(` DiscoveryServer: ${e} `);
});
yellow(" DiscoveryServer: starting server... ");
await lds.start();
green(" DiscoveryServer: is running! ");
} catch (error) {
red(` DiscoveryServer error: ${error}`);
process.exit(-1);
}
})();
6 changes: 3 additions & 3 deletions src/addressspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export const createAddressSpace = async (
green(" Creating AddressSpace done! ");
})
.catch((error: Error) => {
red(` Creating AddressSpace failed!`)
console.log(error)
throw error
red(` Creating AddressSpace failed!`);
console.log(error);
throw error;
})
: () => {
throw new Error(
Expand Down
Loading

0 comments on commit 154f7b9

Please sign in to comment.