Hello!
I connect my camera to raspberry with model and use MIKROTIK router like switch (PTP Bridge AP). But every secondary run, get error and cant normally start my python model.
If i connect Lan cable to Raspberry(with out router) all work fine.
I have RB951G-2HnD router.
If some one configurate it, can help to reconfig it? Or u get some idea to FIX it?
Because with Archer(TP-link) similar, didn't have any problem.

    EdmundsJelinskis
    Make sure ports 11490 and 11491 are open and allow traffic. Can you ping the device? Make sure you set your OS to the same subnet as the device.

    Also, seems strange to me (perhaps it's ok), you save set the gateway to 1.254 (I would generally expect the first address to be the gateway - so 1.1).

    Thanks,
    Jaka

      jakaskerl
      I open port but still it didn't help.
      On third script run, model start work, but with out mikrotik, run always.
      (Also, seems strange to me (perhaps it's ok), you save set the gateway to 1.254) - i use different input internet router, but it didn't help.

      BR,
      Edmunds

        EdmundsJelinskis
        If you can't ping it from the PI, it means the routes are not set up. Make sure you set the correct subnet on your PI. Then if you typeip route it should display something similar (last line is important):

        default via 10.12.118.1 dev enp88s0 proto dhcp metric 100 
        default via 10.12.8.1 dev wlo1 proto dhcp metric 600 
        10.12.8.0/22 dev wlo1 proto kernel scope link src 10.12.10.124 metric 600 
        10.12.118.0/24 dev enp88s0 proto kernel scope link src 10.12.118.92 metric 100 
        169.254.0.0/16 dev wlo1 scope link metric 1000 

        Thanks,
        Jaka

          jakaskerl
          I get that info from raspberry

          "pi@pi:~$ ip rout

          default via 192.168.1.254 dev wlan0 proto dhcp metric 600

          default via 169.254.1.1 dev eth0 proto static metric 20100

          169.254.0.0/16 dev eth0 proto kernel scope link src 169.254.1.250 metric 100

          192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.104 metric 600 "

          Can be that problem if i don't have last line?

            EdmundsJelinskis
            Oh OK, that seems a code problem then. Can you attach the code you are using? Please make it as minimal as possible (but reproable).

            Thanks,
            Jaka

              6 days later

              jakaskerl
              Hi, I found one problem, when configuration range 10-100Mb camaera work good. If I put 1Gb, then momentaly get error.
              But 100MB, give only 17 FPS, not 26 FPS in 1Gb mode.

              jakaskerl Test code is not large, put it all.
              currant-yolov8-1107-480.blob - got 1600 picture 5,79 MB file size.
              Also run small *.blob file = 600 picture ~4MB file size, but problem same.

              from pathlib import Path

              import sys

              import cv2

              import depthai as dai

              import numpy as np

              import time

              # Get argument first

              nnBlobPath = str((Path(_file_).parent / Path('/home/pi/Desktop/WEB_weeder/weights/currant_08052024_server.blob')).resolve().absolute())

              if not Path(nnBlobPath).exists():

              raise FileNotFoundError(f'Required file/s not found, please run "{sys.executable} install_requirements.py"')

              # Label texts

              labelMap = ["currant"] # Assuming there is only one class

              syncNN = True

              # Create pipeline

              pipeline = dai.Pipeline()

              # Define sources and outputs

              camRgb = pipeline.create(dai.node.ColorCamera)

              detectionNetwork = pipeline.create(dai.node.YoloDetectionNetwork)

              xoutRgb = pipeline.create(dai.node.XLinkOut)

              xoutNN = pipeline.create(dai.node.XLinkOut)

              #nnNetworkOut = pipeline.create(dai.node.XLinkOut)

              xoutRgb.setStreamName("rgb")

              xoutNN.setStreamName("detections")

              #nnNetworkOut.setStreamName("nnNetwork")

              # Properties

              camRgb.setPreviewSize(448,448)

              camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_720_P)

              #camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P) #Var lietot šo resolution

              camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.BGR)

              camRgb.setFps(30)

              camRgb.setInterleaved(False)

              detectionNetwork.setBlobPath(nnBlobPath)

              detectionNetwork.setConfidenceThreshold(0.8)

              detectionNetwork.input.setBlocking(False)

              detectionNetwork.setNumInferenceThreads(2)

              #detectionNetwork.input.setBlocking(False)

              # Yolo specific parameters

              detectionNetwork.setNumClasses(1)

              detectionNetwork.setCoordinateSize(4)

              #detectionNetwork.setNumInferenceThreads(2)

              #detectionNetwork.setIouThreshold(0.5)

              # Linking

              camRgb.preview.link(detectionNetwork.input)

              #if syncNN:

              detectionNetwork.passthrough.link(xoutRgb.input)

              #else:

              # camRgb.preview.link(xoutRgb.input)

              detectionNetwork.out.link(xoutNN.input)

              #detectionNetwork.outNetwork.link(nnNetworkOut.input)

              print(1)

              # Connect to device and start pipeline

              with dai.Device(pipeline) as device:

              print(2)

              # Output queues will be used to get the rgb frames and nn data from the outputs defined above

              previewQueue = device.getOutputQueue(name="rgb", maxSize=4, blocking=False)

              detectionNNQueue = device.getOutputQueue(name="detections", maxSize=4, blocking=False)

              #networkQueue = device.getOutputQueue(name="nnNetwork", maxSize=4, blocking=False)

              startTime = time.monotonic()

              counter = 0

              fps = 0

              color = (0, 150, 255)

              #printOutputLayersOnce = True

              while True:

              print("loop")

              inPreview = previewQueue.get()

              inDet = detectionNNQueue.get()

              #inNN = networkQueue.get()

              #if printOutputLayersOnce:

              # toPrint = 'Output layer names:'

              # for ten in inNN.getAllLayerNames():

              # toPrint = f'{toPrint} {ten},'

              # print(toPrint)

              # printOutputLayersOnce = False

              frame = inPreview.getCvFrame()

              counter += 1

              current_time = time.monotonic()

              if (current_time - startTime) > 1:

              fps = counter / (current_time - startTime)

              counter = 0

              startTime = current_time

              detections = inDet.detections

              # If the frame is available, draw bounding boxes on it and show the frame

              height, width = frame.shape[:2]

              for detection in detections:

              # Denormalize bounding box

              x1 = int(detection.xmin * width)

              x2 = int(detection.xmax * width)

              y1 = int(detection.ymin * height)

              y2 = int(detection.ymax * height)

              try:

              label = labelMap[detection.label]

              except IndexError:

              label = f'Label {detection.label}'

              cv2.putText(frame, label, (x1 + 10, y1 + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color)

              cv2.putText(frame, f"{detection.confidence*100:.2f}%", (x1 + 10, y1 + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color)

              cv2.rectangle(frame, (x1, y1), (x2, y2), color, 2)

              cv2.putText(frame, f"NN fps: {fps:.2f}", (2, height - 4), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color)

              cv2.imshow("rgb", frame)

              if cv2.waitKey(1) == ord('q'):

              break

              cv2.destroyAllWindows()

              time.sleep(0.01)

                EdmundsJelinskis
                Ok, code is fine, it's the tcp connections that fails. Very difficult to debug without access to hardware. I see this mikrotik router is rather old - perhaps it doesn't handle gbit very well. From their website:

                You'd need to inspect the packets to see where the issue comes from. I'd use wireshark to check. Also have you tried adding half-duplex for 10/100/1000 and/or disabling auto negotiation.

                Thanks,
                Jaka

                  jakaskerl
                  Router is 5-10 y/o, maybe it get some problem with connection.
                  Ok, i try use wireshark and check where is packet loss.
                  Yes I add half half-duplex for 10/100/1000, same problem, when disable auto negotation, camera lose ping and any connections is not available.