NickM-27 / swatch

Color detection in images to capture presense of known objects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Support]: Trouble Getting Into WebUI - 502 Bad Gateway error

ssryan9 opened this issue · comments

Describe the problem you are having

Can't access WebUI - 502 bad gateway error

Repository has been added, and add-on installed. I have also installed the HACS integration. I tried to setup the normal integration (which is now showing up) but wasn't sure if I'm pointing to the right URL as I'm getting an error back on that.

Bigger issue seems to be with getting into the WebUI

Version

3.0.2

Swatch config file

# REQUIRED: Define a list of objects that are expected to be seen. These can be specific
# to one camera or common between many / all cameras
objects:
  # REQUIRED: Name of the object
  trash_can:
    # REQUIRED: the list of color variants that this object can be detected as. Useful for
    # different lighting conditions
    color_variants:
      # REQUIRED: the name of the color variant
      default:
        # REQUIRED: the lower R, G, B values that are considered a potential match for the
        # color variant of the object.
        color_lower: 70, 70, 0
        # REQUIRED: the upper R, G, B values that are considered a potential match for the
        # color variant of the object.
        color_upper: 110, 100, 50
        # OPTIONAL: the time range for when this color variant is allowed
        # NOTE: make sure that /etc/localtime is passed to the container so it has valid time
        time_range:
          # OPTIONAL: Color variant is valid if current time is > this 24H time (Default: shown below).
          after: "00:00"
          # OPTIONAL: Color variant is valid if current time is < this 24H time (Default: shown below).
          before: "24:00"
    # OPTIONAL: the min number of pixels with R, G, B values within the bounds to be
    # considered a true positive. This is recommended to be set as a super small amount
    # could be a false positive. (Default: shown below)
    min_area: 1000
    # OPTIONAL: the max number of pixels with R, G, B values within the bounds to be
    # considered a true positive (Default: shown below).
    max_area: 100000
    
# REQUIRED: Define list of cameras that will be used for color detection.
cameras:
  # REQUIRED: Name of the camera
  GR:
    # OPTIONAL: Frequency in seconds to run detection on the camera.
    # a value of 0 disables auto detection (Default: shown below).
    auto_detect: 0
    # OPTIONAL: Configure the url and retention of snapshots. (Default: Shown Below)
    snapshot_config:
        # OPTIONAL: but highly recommended, setting the default url for a snapshot to be
        # processed by this camera. This is required for auto detection (Default: none).
        url: "http://ip.ad.dr.ess/jpg"
        # OPTIONAL: Whether or not to draw bounding boxes for confirmed objects in the snapshots (Default: shown below).
        bounding_box: true
        # OPTIONAL: Whether or not to save a clean png of the snapshot along with the annotated jpg (Default: shown below).
        clean_snapshot: true
        # OPTIONAL: Whether or not to save the snapshots of confirmed detections (Default: shown below).
        save_detections: true
        # OPTIONAL: Whether or not to save the snapshots of missed detections (Default: shown below).
        save_misses: false
        # OPTIONAL: Variations of snapshots to keep. Options are all, mask, crop (Default: shown below).
        mode: "all"
        # OPTIONAL: Number of days of snapshots to keep (Default: shown below).
        retain_days: 7
    # REQUIRED: Zones are cropped areas where the object can be expected to be.
    # This makes searching / matches for efficient and more predictable than searching
    # the entire image.
    zones:
      # REQUIRED: Name of the zone.
      street:
        # REQUIRED: Coordinates to crop the zone by.
        # NOTE: The order of the coordinates are: x, y, x+w, y+h starting in the top left corner as 0, 0.
        coordinates: 225, 540, 350, 620
        # REQUIRED: List of objects that may be in this zone. These correspond to
        # the objects list defined previously and are matched by name.
        objects:
          - trash_can

Relevant log output

[2022-06-08 14:13:47,455]: INFO - Starting SwatchApp
[2022-06-08 14:13:47,464]: INFO - Importing SwatchApp Config
[2022-06-08 14:13:47,464]: INFO - Verified SwatchApp Config
Starting migrations
[2022-06-08 14:13:47,480]: INFO - Starting migrations
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3113, in connect
    self._state.set_connection(self._connect())
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3453, in _connect
    conn = sqlite3.connect(self.database, timeout=self._timeout,
sqlite3.OperationalError: unable to open database file
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3175, in execute_sql
    cursor = self.cursor(commit)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3159, in cursor
    self.connect()
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3112, in connect
    with __exception_wrapper__:
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 2950, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 191, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3113, in connect
    self._state.set_connection(self._connect())
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3453, in _connect
    conn = sqlite3.connect(self.database, timeout=self._timeout,
peewee.OperationalError: unable to open database file
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/opt/swatch/swatch/__main__.py", line 14, in <module>
    swatch_app = SwatchApp()
  File "/opt/swatch/swatch/app.py", line 44, in __init__
    self.__init_db__()
  File "/opt/swatch/swatch/app.py", line 74, in __init_db__
    router.run()
  File "/usr/local/lib/python3.10/site-packages/peewee_migrate/router.py", line 201, in run
    diff = self.diff
  File "/usr/local/lib/python3.10/site-packages/peewee_migrate/router.py", line 75, in diff
    done = set(self.done)
  File "/usr/local/lib/python3.10/site-packages/peewee_migrate/router.py", line 70, in done
    return [mm.name for mm in self.model.select().order_by(self.model.id)]
  File "/usr/local/lib/python3.10/functools.py", line 981, in __get__
    val = self.func(instance)
  File "/usr/local/lib/python3.10/site-packages/peewee_migrate/router.py", line 59, in model
    MigrateHistory.create_table(True)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 6758, in create_table
    cls._schema.create_all(safe, **options)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 5861, in create_all
    self.create_table(safe, **table_options)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 5716, in create_table
    self.database.execute(self._create_table(safe=safe, **options))
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3190, in execute
    return self.execute_sql(sql, params, commit=commit)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3174, in execute_sql
    with __exception_wrapper__:
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 2950, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 191, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3175, in execute_sql
    cursor = self.cursor(commit)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3159, in cursor
    self.connect()
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3112, in connect
    with __exception_wrapper__:
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 2950, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 191, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3113, in connect
    self._state.set_connection(self._connect())
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3453, in _connect
    conn = sqlite3.connect(self.database, timeout=self._timeout,
peewee.OperationalError: unable to open database file

Any other information that may be helpful

No response

The 502 is occurring because swatch is not started. I need to add a warning, but the config there is for reference and not to be copied as it is not compatible with all installs and doesn't have valid values anyway.

A good starting point should be:

objects:
  trash_can:
    color_variants:
      default:
        color_lower: 70, 70, 0
        color_upper: 110, 100, 50
    
cameras:
  GR:
    zones:
      street:
        coordinates: 225, 540, 350, 620
        objects:
          - trash_can

it won't fit your setup but swatch should start so you can get started

I updated the config file to the above and I'm seeing the same error in the logs. I rebuilt the HACS add-on, as well as re-starting it. Same error in the logs

Thanks, that is interesting, seems the database logic isn't working right. Can you please try manually creating a /swatch folder inside /media (so it looks like /media/swatch/ and that should fix that.

I didn't have a /media folder, but I created one and then created a swatch folder inside of it. Still no luck. Rebuilt the add on and restarted it - same error

What kind of install are you running? The /media folder should come for free and by default with the HomeAssistant OS install

(to be clear this is outside of /config so it is NOT /config/media/swatch/).

Ah thanks for the clarification - just located the media folder and there is already a swatch folder created...

Inside of that folder is a swatch.db folder with nothing in it.

Oh, I see, that's me being dumb then. Please delete the swatch.db folder and it should work

Should be a file, not a folder so my logic was a little off

Deleted the swatch.db folder and it recreates itself every time I restart or rebuild Swatch in my add-ons section. Still getting the same errors

Thanks, I'll get an update out to address this

This should be fixed with latest version (out now)

That moved the needle! The logs are much cleaner now, but I'm still not getting anything when I click into the WebUI. I've reinstalled, updated to the newest version you just released, as well as restarted my HASS instance.

Edit: I'm no longer getting the bad gateway error, just a blank screen

Logs
[2022-06-08 17:17:00,829]: INFO - Starting SwatchApp [2022-06-08 17:17:00,838]: INFO - Importing SwatchApp Config [2022-06-08 17:17:00,838]: INFO - Verified SwatchApp Config Starting migrations [2022-06-08 17:17:00,842]: INFO - Starting migrations There is nothing to migrate [2022-06-08 17:17:00,849]: INFO - There is nothing to migrate [2022-06-08 17:17:00,851]: INFO - Starting snapshot cleanup [2022-06-08 17:17:00,852]: INFO - Starting Detection Cleanup

What address comes up when trying to view? What happens if you view http://{ha ip address}:4500

That did the trick!

The address that it's pointing to is http://[ha ip]/69755fa6_swatch/dashboard but if i go to the address above it works.

I really appreciate all the help. Not a big deal to just navigate to this URL. Now that I'm in the UI, is the URL it's asking for for the camera just the RTSP url?

It's trying to do the ingress so I probably should disable that as I don't care to support that until I understand it more.

And the url in the config would be a snapshot url (some cameras natively support it some don't)

I might be able to get snapshot from rtsp stream but currently it needs to give a jpg

Going to go ahead and close this. If you have any issues with setting up config feel free to create a new issue