Configure the network

This page documents an earlier firmware release. Read this page for the latest release

Read and change the network configuration over the API. In the WebGUI, see Network settings. The examples use the Python library and sign in with an application key. Replace qb2-xxxxxxxxx with the hostname or IP address of your sensor and application-key-for-qb2-xxxxxxxxx with the secret of your key.

Get the network configuration

The method GetConfig returns the network configuration set on the sensor.

import blickfeld_qb2

token_factory = blickfeld_qb2.TokenFactory(application_key_secret="application-key-for-qb2-xxxxxxxxx")

# Open a secure and authenticated connection to the sensor
with blickfeld_qb2.Channel(fqdn_or_ip="qb2-xxxxxxxxx", token=token_factory) as channel:
    service = blickfeld_qb2.system.services.Network(channel)

    response = service.get_config()
    print(response)

Output:

Network()

A sensor on which no network configuration was set returns an empty configuration and uses DHCP and link-local addressing. The method GetStatus returns the configuration in use, with the addresses, in active_config.

Set a static network configuration

In a network without a DHCP server, set the IPv4 address by hand. The example sets two addresses, the gateway and two DNS servers.

After the change, the sensor is only reachable under the new address. If you cannot reach it any more, connect over the fallback IP address 192.168.26.26.

import blickfeld_qb2

# Two addresses, the gateway and two DNS servers
manual = blickfeld_qb2.system.config.NetworkStatic(
    ipv4=blickfeld_qb2.system.config.NetworkStaticIpv4(
        ip=["10.0.2.15/24", "10.0.2.43/24"],
        gateway="10.0.2.2",
        dns_server=["8.8.4.4", "8.8.8.8"],
    )
)

token_factory = blickfeld_qb2.TokenFactory(application_key_secret="application-key-for-qb2-xxxxxxxxx")

# Open a secure and authenticated connection to the sensor
with blickfeld_qb2.Channel(fqdn_or_ip="qb2-xxxxxxxxx", token=token_factory) as channel:
    service = blickfeld_qb2.system.services.Network(channel)

    # Set the configuration
    service.set_config(manual=manual)