问题
Reading the documentation and examples of the OPC-UA foundation, the variables nodes are always added before the statement to start run the server. Is it possible to add them after the server has been started? If I change the order of the statements that doesn't work.
Think with me the following situation: I need to do some HTTP requests as soon we start running the application/software (not the server) asynchronously. Then the server starts, after my HTTP request is done, I added variable nodes based on the information returned from the web.
The variables are added by file .json, "https" will send data by HTML form. My server will analyse and add them to the .json file. Then I need the server to add that.
OPCUA_SERVER.js
app.js
appconfig.json
for (let i = 0; i < appConfig2.SimulationData.length; i++)
{
let nameDevice = appConfig2.SimulationData[i].deviceName;
opcuaAddDevice(nameDevice, appConfig2.SimulationData[i], moduleData.uaNodeList, addressSpace, namespace);
}
// Start the server
try
{
await (opcuaStartAsync(moduleData.serveropc));
}
catch (e)
{
console.log("OPCUA Server start failed : " + e);
}
console.log("OPCUA Server started.");
//store some values from server and make the magic..
moduleData.connected = true;
let port = moduleData.serveropc.endpoints[0].port;
moduleData.endpointUrl = moduleData.serveropc.endpoints[0].endpointDescriptions()[0].endpointUrl;
console.log("OPCUA Server is now listening on port", port,"(press CTRL+C to stop Server).");
return moduleData;
});
来源:https://stackoverflow.com/questions/60183273/node-opcua-nodejs-express-add-variable-nodes-dynamically-after-run-the-opcuas