Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Can hostname be used for an OPC UA Codesys server?

DavidBo
2022-01-05
2022-01-06
  • DavidBo - 2022-01-05

    First to make it work you will need a DNS to resolve hostname to ip addresses. I have done that with dnsmasq on a raspberry pi:

    C:\Users\DavidBo>ping sipylus
    
    Pinging sipylus.local [192.168.1.101] with 32 bytes of data:
    Reply from 192.168.1.101: bytes=32 time<1ms TTL=64
    Reply from 192.168.1.101: bytes=32 time=1ms TTL=64
    Reply from 192.168.1.101: bytes=32 time=1ms TTL=64
    Reply from 192.168.1.101: bytes=32 time=1ms TTL=64
    
    Ping statistics for 192.168.1.101:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 0ms, Maximum = 1ms, Average = 0ms
    
    C:\Users\DavidBo>ping sipylus -6
    
    Pinging sipylus.local [fd51:42f8:caae:d92e::12b] with 32 bytes of data:
    Reply from fd51:42f8:caae:d92e::12b: time=1ms
    Reply from fd51:42f8:caae:d92e::12b: time=1ms
    Reply from fd51:42f8:caae:d92e::12b: time=1ms
    Reply from fd51:42f8:caae:d92e::12b: time=1ms
    
    Ping statistics for fd51:42f8:caae:d92e::12b:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 1ms, Maximum = 1ms, Average = 1ms
    
    C:\Users\DavidBo>nslookup sipylus
    DNS request timed out.
        timeout was 2 seconds.
    Server:  UnKnown
    Address:  fd51:42f8:caae:d92e::ff
    
    Name:    sipylus
    Addresses:  fd51:42f8:caae:d92e::12b
              192.168.1.101
    

    However using UaExpert I get:

    12:04:13.306Z|6|213C* [uastack] OpcUa_SecureConnection_CancelOpenRequests: Canceling 0 open requests at connection 07296958.
    12:04:13.306Z|6|213C* [uastack] OpcUa_SecureConnection_Connect: sync connect for connection 07160880
    12:04:13.306Z|4|2C80* [uastack] NetworkThread: Message Loop started...
    12:04:13.306Z|6|213C* [uastack] OpcUa_P_ParseUrl: Parsing "opc.tcp://sipylus:4840".
    12:04:13.306Z|6|213C* [uastack] OpcUa_P_ParseUrl: Testing for IPv4 address or hostname.
    12:04:13.306Z|6|213C* [uastack] OpcUa_P_ParseUrl: Non-numeric name detected.
    12:04:13.306Z|6|213C* [uastack] OpcUa_P_ParseUrl: Trying to resolve host "sipylus" port "4840" to address family 0.
    12:04:15.574Z|2|213C* [uastack] OpcUa_P_RawSocket_InetAddr: getaddrinfo failed with 11001.
    12:04:15.574Z|2|213C* [uastack] OpcUa_P_ParseUrl: OpcUa_P_RawSocket_InetAddr reports error 0xA0060000.
    12:04:15.574Z|6|213C* [uastack] OpcUa_AsyncCallState_Delete: 04340728
    

    Have any successfully made a connection using a hostname? I think I can use ip addresses if I disable the DNS, but it creates a problem using a DHCP server because how can I know the ip address?

     
  • dFx

    dFx - 2022-01-06

    This won't answer the question but may solve your issue : Use a static IP in the DHCP server, so you can use a predefined static IP in UA expert.

     
  • DavidBo - 2022-01-06

    I have figured out that if I create 2 servers one with an ip address and another one with opc.tcp://sipylus:4840 and I do:
    1)connect with the server with ip address
    2) disconnect
    3) connect with the server sipylus

    Now it works fine, so it seems that UaExpert resolves hostnames in some local cache before it connects to the server, but again it does not solve my problem.

     

Log in to post a comment.