Closed proffalken closed 9 months ago
I’m just heading to bed, and can take a proper look tomorrow, but from memory it was a specific decision that doors had to be added before they could connect. In the interest of security and not having random doors connecting etc. to your instance, the web socket API will only allow the connection if the door exists and the serial number (ie MAC address, but could be any fixed identifier) matches. Ideally we’d have some sort of discovery / approval queue but that was more work I didn’t have time for. ;)
you can see the logic here: https://github.com/membermatters/MemberMatters/blob/b1c363e00e39dc338c74a77df704c643904f2bfd/memberportal/api_access/consumers.py#L49
tl;dr If you add the door to MM first, and make sure the serial number matches, it should allow the door to connect. If you think this behaviour should be changed, happy to have a discussion. :)
The logic is sound, the problem is that I get the same error when I try and add a door via the admin interface and I can't see a button for it on the "main" interface.
I'll have another look and see, thanks :)
Ohh I see. Sorry thought it was just on websocket connect. I’ll take a look tomorrow some time. :)
For tomorrow, can you post the stack trace from the request when you try to add a new door? I suspect it’s something from here , but the stacktrace error from that specific request will help narrow it down.
Sure, same error:
Environment:
Request Method: POST
Request URL: https://members.makemonmouth.co.uk/admin/access/doors/add/
Django Version: 3.2.20
Python Version: 3.10.13
Installed Applications:
['constance',
'constance.backends.database',
'django_prometheus',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'oidc_provider',
'channels',
'profile',
'access',
'group',
'memberbucks',
'api_spacedirectory',
'api_general',
'api_access',
'api_meeting',
'api_admin_tools',
'api_billing',
'corsheaders',
'rest_framework',
'django_celery_results',
'django_celery_beat']
Installed Middleware:
['django_prometheus.middleware.PrometheusBeforeMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'membermatters.middleware.Sentry',
'membermatters.middleware.ForceCsrfCookieMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware']
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 38, in inner
response = await get_response(request)
File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 233, in _get_response_async
response = await wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/options.py", line 616, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/sites.py", line 232, in inner
return view(request, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1657, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "/usr/local/lib/python3.10/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1540, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1586, in _changeform_view
self.save_model(request, new_object, form, not add)
File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1099, in save_model
obj.save()
File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 739, in save
self.save_base(using=using, force_insert=force_insert,
File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 763, in save_base
pre_save.send(
File "/usr/local/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 180, in send
return [
File "/usr/local/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 181, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named))
File "/usr/src/app/memberportal/api_access/signals.py", line 24, in save_or_create_door
door = Doors.objects.get(pk=instance.id)
File "/usr/local/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 435, in get
raise self.model.DoesNotExist(
Exception Type: DoesNotExist at /admin/access/doors/add/
Exception Value: Doors matching query does not exist.
POST data:
csrfmiddlewaretoken | <REDACTED>
-- | --
name | 'test'
description | 'test'
ip_address | ''
serial_number | '123456'
last_seen_0 | '05/09/2023'
last_seen_1 | '01:49:25'
all_members | 'on'
post_to_discord | 'on'
report_online_status | 'on'
_save | 'Save'
Thanks in advance!
Forgot to mention this should be fixed now. I went to review your PR (thanks for that!) and realised my original code was using the wrong signal so made some other changes to hopefully fix it "properly".
Describe the bug
When trying to use the firmware from https://github.com/membermatters/mainboard-firmware, the platform errors with the following in the MemberMatters log:
I get the same error when I try to create the door/interlock via the admin UI as well, so this seems to be an issue with MemberMatters rather than with the mainboard firmware.
To Reproduce Steps to reproduce the behavior:
Expected behavior
The
Door
object is created if it does not already exist, and the mainboard is registered with the platform.Additional context
I suspect this is due to Doors inheriting from AccessControlDevice but for some reason it's trying to look up its own ID which doesn't exist and then fails.