• SDK and flashing standalone application

I'm trying to flash my application to work in standalone mode on an OAK-D S2 PoE.

I'm able to flash any application which is based on the API.

However, I am not able to flash an application which is based on the SDK. If I use:

with OakCamera() as oak:

then later in the with block, I get:

    bootloader = dai.DeviceBootloader(bl)
RuntimeError: Device not in UNBOOTED, BOOTLOADER or FLASH_BOOTED state
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): sentry.luxonis.com:443
Sentry is attempting to send 2 pending error messages
Waiting up to 2 seconds
Press Ctrl-C to quit
DEBUG:urllib3.connectionpool:https://sentry.luxonis.com:443 "POST /api/3/envelope/ HTTP/1.1" 200 41

So, I tried calling DeviceBootloader before calling OakCamera but I get:

    with OakCamera() as oakc:
  File "(......)/.venv/lib/python3.10/site-packages/depthai_sdk/oak_camera.py", line 95, in __init__
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): sentry.luxonis.com:443
    self._init_device(config, device)
  File "(......)/.venv/lib/python3.10/site-packages/depthai_sdk/oak_camera.py", line 378, in _init_device
    self._oak.device = dai.Device(
RuntimeError: Failed to connect to device, error message: X_LINK_DEVICE_NOT_FOUND
Sentry is attempting to send 2 pending error messages
Waiting up to 2 seconds
Press Ctrl-C to quit
DEBUG:urllib3.connectionpool:https://sentry.luxonis.com:443 "POST /api/3/envelope/ HTTP/1.1" 200 41

So, how do I use the SDK and flash my standalone application?

    Hi Craftonix
    Never thought about flashing an SDK app; but I think it could be done if correctly set up. One of the problems is definitely the visualization part -- this has to be removed. Then build the pipeline with pipeline = oak.build() and proceed as per usual.
    While standalone is not currently possible through SDK, it might be doable due to its interoperability with the API.
    I'll see if I can make a tutorial when I have some time.

    Thoughts?
    Jaka

    Hi Jaka,

    I definitely removed all visualizations and I don't have any XLinkOut setup using the SDK to API interoperability.

    I also tried adding a 60 second sleep in both code examples above but I still got the same errors.

    A 60 second sleep is more than enough because when powering on the device in standalone mode and waiting for it to start sending messages, I timed it manually and it takes about 50 seconds.

    Although a tutorial would be appreciated, all I'm asking for is some tips or a small code snippet that I can try. Currently, I am at a deadend and the SDK approach is not feasible, since we need standalone mode.

    Thanks

      Hi Craftonix
      Could you paste the code you are currently using so we can debug this easier?

      Thanks,
      Jaka

      Hi Craftonix
      After many failed attempts, I managed to make it work in a really stupid way. The problem with SDK is that it immediately boots the device, before creating a pipeline. This way, the bootloader worn be able to flash the app no matter what you do (except change the core SDK functionality).
      The way I did it is I connected to the device, built the pipeline, disconnected, then waited the device to reboot and flashed the previously saved pipeline.

      A problem you might run into is not having enough flash storage on the device. In that case, you can also use emmc storage if your device has it.

      #!/usr/bin/env python3
      
      # SDK version
      
      STAND_ALONE = True
      
      
      from depthai_sdk import OakCamera
      import depthai as dai
      import time
      
      with OakCamera("169.254.1.222") as oak:
          color = oak.create_camera('color')
          # nn = oak.create_nn('mobilenet-ssd', color)
          # oak.visualize([nn.out.passthrough, nn], fps=True)
      
          # Build the pipeline, connect to the oak, update components. Place interop logic AFTER oak.build()
          pipeline = oak.build()
      
          # nn.node.setNumInferenceThreads(2) # Configure components' nodes
      
          # features = pipeline.create(dai.node.FeatureTracker) # Create new pipeline nodes
          # color.node.video.link(features.inputImage)
      
          # out = pipeline.create(dai.node.XLinkOut)
          # out.setStreamName('features')
          # features.outputFeatures.link(out.input)
      
      
      # # Flash the pipeline
      
      print("sleeping")
      time.sleep(20)
      
      (f, bl) = dai.DeviceBootloader.getFirstAvailableDevice()
      bootloader = dai.DeviceBootloader(bl)
      print(f"Flashing {bl} bootloader...")
      startTime = time.monotonic()
      progress = lambda p : print(f'Flashing progress: {p*100:.1f}%')
      (r, errmsg) = bootloader.flash(progress, pipeline, compress=True)
      if r: 
          print("Flash OK")
      elif errmsg:
          print(errmsg)

      Thanks,
      Jaka

      Thanks Jaka,

      I tried it and it worked well so far. It flashed much faster than previously. I don't know if it is because I am now using the Series 1 device (vs previously the Series 2).

      Why are you saying I might run out of flash?

      How would I use the eMMC to store the application? Please provide a code snippet.

      If I use the flash, wouldn't this destroy my data that I have on the eMMC? The whole reason for switching back to the Series 1 device is beause you guys sold us the Series 2 WITHOUT eMMC!

        Hi Craftonix
        Some devices (mainly non pro ones) have low amounts of flash memory. I checked one OAK-D-W and it only had about 16MB of flash. When flashing an application to the device you will have to first flash the firmware and only then the application. Both of these will take up some storage and 16mb is a little low for that.
        That is why I suggested you use the EMMC if flash wouldn't work.

        https://docs.luxonis.com/projects/api/en/latest/samples/Script/script_emmc_access/ check the bootloader if you have emmc. Then I believe all you have to do to flash to emmc is to change the memory type when flashing.

        Thanks,
        Jaka