Skip to content

Device Discovery Using Network Service Discovery (NSD)

Network Service Discovery (NSD) is a technology that enables devices to discover services on a local network without requiring manual configuration. It is part of the broader Zero Configuration Networking (ZeroConf) suite, designed to simplify network service configuration.

Relation to Bonjour and ZeroConf

  • ZeroConf: A set of technologies that facilitate automatic configuration of network services without user intervention. It includes components like address assignment, name resolution, and service discovery.
  • Bonjour: Apple's implementation of ZeroConf, widely used for service discovery in macOS and iOS environments. It uses the multicast DNS (mDNS) protocol to advertise and resolve service information.
  • NSD in Synqpay: Synqpay implements service discovery via mDNS, compatible with tools and libraries like Bonjour and Python's zeroconf package.

Using NSD, Synqpay devices advertise their API endpoints, enabling client applications to discover and connect without requiring IP addresses or URLs to be preconfigured.


NSD Implementation in Synqpay Devices

  • Service Name: The device's serial number.
  • Service Type: _synqpay._tcp (for all supported transport layers).
  • Service Properties:
  • transport: Specifies the transport layer used by the device API.
    • ws for WebSocket.
    • tcp for TCP.
    • http for HTTP.
  • name: The device name, as configured in the Device Management System (DMS).

  • Enabling NSD:
    NSD functionality must be enabled in the device settings screen for the device to advertise its presence.


Code Example: Discovering Synqpay Devices

Below is an example using the Python zeroconf library to discover Synqpay devices advertising the _synqpay._tcp.local. service:

from zeroconf import ServiceBrowser, Zeroconf, ServiceListener
import ipaddress


class MyListener(ServiceListener):
    def update_service(self, zc: Zeroconf, type_: str, name: str) -> None:
        print(f"Service {name} updated")

    def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None:
        print(f"Service {name} removed")

    def add_service(self, zc: Zeroconf, type_: str, name: str) -> None:
        info = zc.get_service_info(type_, name)
        if info:
            ip_addr = ipaddress.IPv4Address(info.addresses[0])
            print(f"Service {name} added on {ip_addr}:{info.port} properties: {info.properties}")


def main():
    zeroconf = Zeroconf()
    listener = MyListener()
    browser = ServiceBrowser(zeroconf, "_synqpay._tcp.local.", listener)
    try:
        input("Press enter to exit...\n\n")
    finally:
        zeroconf.close()


if __name__ == '__main__':
    main()

Result

service found: 244RKR528387._synqpay._tcp.local. on 10.100.102.141:8000 properties: {b'name': b'Ido RX5K Home', b'transport': b'ws'}

Setup

  1. Install the zeroconf (link) package via pip:
    pip install zeroconf
    
  2. Run the script in a Python environment with network access.