Hello gbanuru , I would actually suggest using the API itself (bootloader API), where you can set these configurations eg. ip with the string "123.123.123.123"
, so you don't soft-brick your device. And we apologize that there isn't such an example yet, we will be adding it soon.
How to assign static IPs to POE devices
Hi erik,
Ah wish I saw this sooner. This method setStaticIPv4(std::string ip, std::string mask, std::string gateway) is exactly what I was looking for: https://docs.luxonis.com/projects/api/en/latest/references/python/?highlight=.readConfigData()#depthai.DeviceBootloader.Config.setStaticIPv4.
But now I'm a bit afraid the steps I've described thus far may have soft-bricked the device. Is there a way to reset the OAK-1 POE? I do see a Module Reset Button labelled G here although I'm not sure if it is relevant: "https://docs.luxonis.com/projects/hardware/en/latest/pages/SJ2096POE.html"
Hello gbanuru , I would suggest checking this announcement on how to resolve a soft-bricked device.
- Edited
Hi erik , Running fix_softbrick.py in the linked announcement worked! Now I can connect to my device.
I will wait for an example on how to use the bootloader API for (.setStaticIPv4(ipv4, mask, gateway), .setDynamicIPv4(ipv4, mask, gateway)).
I wrote a script to use the bootloader API which shows that the .getIPv4(), .getIPv4Mask(), .getIPv4Gateway(), .isStaticIPV4() are set, but when I rerun the same script I do not see the changes to the bootloader just made.
# usr/bin/env/python3
import depthai as dai
current_ip = input("Enter IP of POE OAK Device: ").strip() # example: 172.16.15.17
found_poe, poe = dai.DeviceBase.getDeviceByMxId(current_ip)
if not found_poe:
print(f"Did not find {current_ip}, exiting.")
exit(1)
print(f"Found {current_ip}")
poebl = dai.DeviceBootloader(poe)
device_config = poebl.Config()
def see_config():
print("\nCurrent IPv4 Configurations: ")
print(f"IPv4: {device_config.getIPv4()}")
print(f"IPv4 Mask: {device_config.getIPv4Mask()}")
print(f"IPv4 Gateway: {device_config.getIPv4Gateway()}")
print(f"Is IPv4 static: {device_config.isStaticIPV4()}")
def enter_new_config():
print("\nNew IPv4 Configurations: ")
ipv4 = input("Enter IPv4: ").strip()
mask = input("Enter IPv4 Mask: ").strip()
gateway = input("Enter IPv4 Gateway: ").strip()
is_static = True if input("Is this a static IPv4 (sets dynamic IPv4 if no)? (y/n): ").strip() == "y" else False
return ipv4, mask, gateway, is_static
def confirm_new_config(ipv4, mask, gateway, is_static):
print("\nEntered IPv4 Configurations: ")
print(f"New IPv4: {ipv4}")
print(f"New IPv4 Mask: {mask}")
print(f"New IPv4 Gateway: {gateway}")
print(f"Is New IPv4 static: {is_static}")
if is_static:
print("Note: Static IPv4 will not start DHCP client")
else:
print("Note: Dynamic IPv4 will be used (sets IP and starts DHCP client)")
is_confirmed = True if input("\nPlease confirm this Configuration to Set (y/n): ").strip() == "y" else False
if not is_confirmed:
print("New Config is not Confirmed, exiting.")
exit(1)
def perform_config(ipv4, mask, gateway, is_static):
print("Setting New Configurations...")
if is_static:
device_config.setStaticIPv4(ipv4, mask, gateway)
else:
device_config.setDynamicIPv4(ipv4, mask, gateway)
print("Configuration Complete")
def run_config():
see_config()
ipv4, mask, gateway, is_static = enter_new_config()
confirm_new_config(ipv4, mask, gateway, is_static)
perform_config(ipv4, mask, gateway, is_static)
see_config()
if __name__ == "__main__":
run_config()
erik any idea when an example will be added. I'm a newbie on these cameras and any help is appreciated.
gbanuru I was able to run your script, but I'm not seeing the updates when I rerun your script.
Hi gbanuru
Sorry for delay on this.
To read out config from device do the following:
device_config = poebl.readConfig()
Your current code just creates a new empty dai.DeviceBootloader.Config
object.
To flash the config run the following at the end (just editing the dai.DeviceBootloader.Config
object will not "save" the configuration)
poebl.flashConfig(device_config)
Regards, Martin
I just tried the code below and it correctly sets a static IP, which it keeps even after a power reset. Could you try it out? Thanks!
import depthai as dai
(found, info) = dai.DeviceBootloader.getFirstAvailableDevice()
def check_str(s: str):
spl = s.split(".")
if len(spl) != 4:
raise ValueError(f"Entered value {s} doesn't contain 3 dots. Value has to be in the following format: '255.255.255.255'")
for num in spl:
if 255 < int(num):
raise ValueError("Entered values can't be above 255!")
return s
if found:
print(f'Found device with name: {info.desc.name}');
with dai.DeviceBootloader(info) as bl:
conf = dai.DeviceBootloader.Config()
ipv4 = check_str(input("Enter IPv4: ").strip())
mask = check_str(input("Enter IPv4 Mask: ").strip())
gateway = check_str(input("Enter IPv4 Gateway: ").strip())
val = input(f"Flashing static IPv4 {ipv4}, mask {mask}, gateway {gateway} to the POE device. Enter 'y' to confirm. ").strip()
if val != 'y':
raise Exception("Flashing aborted.")
conf.setStaticIPv4(ipv4, mask, gateway)
(success, error) = bl.flashConfig(conf)
if not success:
print(f"Error occured while flashing the boot config: {error}")
else:
print(f"Boot config flashed successfully")
erik , I'm getting the following error:
AttributeError: type object 'depthai.DeviceBootloader' has no attribute 'Config
Cmitchell63 Please update the library to the latest version, python3 -mpip install depthai -U
Thanks, Erik
erik done -- the script runs, showing " Boot config flashed successfully", although the script just hangs after that.