How to set the server configuration of open62541

1,896 views
Skip to first unread message

h1598...@gmail.com

unread,
Aug 13, 2018, 11:09:18 PM8/13/18
to open62541
I want to set the OPC UA address to IP address plus port number, how should I modify the sample code?

Best wishes!
xiaohe

matteo.b...@gmail.com

unread,
Aug 28, 2018, 10:18:42 AM8/28/18
to open62541
Hi, maybe I am a bit late, however this is what I found.

    // argv[1] contains your ip address
    // personalize server configuration
    UA_ServerConfig *config = UA_ServerConfig_new_minimal(4840, NULL); // set the port
   
    // set hostname to ip address
    UA_String name;
    UA_String_init(&name);

    name.length = strlen(argv[1]);
    name.data = (UA_Byte *) argv[1];
    UA_ServerConfig_set_customHostname(config, name);
   
    // create server
    UA_Server *server = UA_Server_new(config);
   
    // some code to build your information model
    // ...
   
    // run server
    UA_StatusCode retval = UA_Server_run(server, &running);

UA_ServerConfig_set_customHostname modifies the standard configuration using the IP contained in 'name', instead of  'localhost'. I found it looking at the source code so I don't know if it is the best solution, but it works (with uaexpert client I am able to connect to ocp.tcp://<my-ip>:4840/).

Hope this helps,
Matteo

Kjeld Flarup

unread,
Nov 19, 2019, 4:54:23 PM11/19/19
to open62541
UA_ServerConfig_new_minimal does not exist in version 1.0, what is the replacement, if any?

  Kjeld Flarup

Alberto Milla

unread,
Nov 24, 2019, 2:52:24 PM11/24/19
to open62541
Hi Kjeld,

try with:

    UA_Server *server = UA_Server_new();
    UA_ServerConfig_setMinimal(UA_Server_getConfig(server), _portNumber, nullptr);

Regards,
Alberto

Reply all
Reply to author
Forward
0 new messages