DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • POE set IP
  • Demo
  • Setup
  • Source code

POE set IP

This script allows you to set static or dynamic IP, or clear bootloader config on your OAK-POE device.

Demo

Example script output:
Command Line
1Found device with name: 192.168.1.136
2    -------------------------------------
3    "1" to set a static IPv4 address
4    "2" to set a dynamic IPv4 address
5    "3" to clear the config
6    1
7    -------------------------------------
8    Enter IPv4: 192.168.1.200
9    Enter IPv4 Mask: 255.255.255.0
10    Enter IPv4 Gateway: 192.168.1.1
11    Flashing static IPv4 192.168.1.200, mask 255.255.255.0, gateway 192.168.1.1 to the POE device. Enter 'y' to confirm. y
12    Flashing successful.
If you run the same example again after 10 seconds, you will see that IP changed to 192.168.1.200:
Command Line
1Found device with name: 192.168.1.200
2    -------------------------------------
3    "1" to set a static IPv4 address
4    "2" to set a dynamic IPv4 address
5    "3" to clear the config
You can also use the device's default IP address, which it will revert to if no DHCP server is detected. For more details on how this works, please refer to the No DHCP section in the Poe Deployment Guide.

Setup

Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the script
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
For additional information, please follow the installation guide.

Source code

Python
C++

Python

Python
GitHub
1import depthai as dai
2
3(found, info) = dai.DeviceBootloader.getFirstAvailableDevice()
4
5def check_str(s: str):
6    spl = s.split(".")
7    if len(spl) != 4:
8        raise ValueError(f"Entered value {s} doesn't contain 3 dots. Value has to be in the following format: '255.255.255.255'")
9    for num in spl:
10        if 255 < int(num):
11            raise ValueError("Entered values can't be above 255!")
12    return s
13
14if found:
15    print(f'Found device with name: {info.name}')
16    print('-------------------------------------')
17    print('"1" to set a static IPv4 address')
18    print('"2" to set a dynamic IPv4 address')
19    print('"3" to clear the config')
20    key = input('Enter the number: ').strip()
21    print('-------------------------------------')
22    if int(key) < 1 or 3 < int(key):
23        raise ValueError("Entered value should either be '1', '2' or '3'!")
24
25    with dai.DeviceBootloader(info) as bl:
26        if key in ['1', '2']:
27            ipv4 = check_str(input("Enter IPv4: ").strip())
28            mask = check_str(input("Enter IPv4 Mask: ").strip())
29            gateway = check_str(input("Enter IPv4 Gateway: ").strip())
30            mode = 'static' if key == '1' else 'dynamic'
31            val = input(f"Flashing {mode} IPv4 {ipv4}, mask {mask}, gateway {gateway} to the POE device. Enter 'y' to confirm. ").strip()
32            if val != 'y':
33                raise Exception("Flashing aborted.")
34
35            conf = dai.DeviceBootloader.Config()
36            if key == '1': conf.setStaticIPv4(ipv4, mask, gateway)
37            elif key == '2': conf.setDynamicIPv4(ipv4, mask, gateway)
38            (success, error) = bl.flashConfig(conf)
39        elif key == '3':
40            (success, error) = bl.flashConfigClear()
41
42        if not success:
43            print(f"Flashing failed: {error}")
44        else:
45            print(f"Flashing successful.")

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.