node-opcua, nodejs, express: Add Variable nodes dynamically after run the OPCUAserver

南楼画角 提交于 2020-05-15 19:55:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!