Skip to content

Notify DAC output#78

Merged
BECATRUE merged 21 commits intodevelopfrom
BECATRUE/76/notify-dac
Feb 26, 2026
Merged

Notify DAC output#78
BECATRUE merged 21 commits intodevelopfrom
BECATRUE/76/notify-dac

Conversation

@BECATRUE
Copy link
Copy Markdown
Member

This resolves #76.

One can receive the DAC outputs of a specific channel in real time using the following code:

import time
import json

import requests
from websockets.sync.client import connect

HTTP_BASE_URL = 'http://localhost:8000'
WS_BASE_URL = 'ws://localhost:8000'
CHANNEL = 5

def build_cookie_header(session: requests.Session) -> str:
    cookies = session.cookies.get_dict()
    return "; ".join(f"{k}={v}" for k, v in cookies.items())


with requests.Session() as session:
    # Sign in
    data = {'username': 'OOOO', 'password': 'OOOO'}
    response = session.post(HTTP_BASE_URL + '/api/user/signin/', json=data)
    response.raise_for_status()

    csrf_token = session.cookies.get('csrftoken')
    headers = {'X-CSRFToken': csrf_token}

    # Receive voltages
    cookies = build_cookie_header(session)
    ws_url = f'{WS_BASE_URL}/ws/pid_setting/dac_output/{CHANNEL}/'
    with connect(
        ws_url,
        origin='http://localhost:3000',
        additional_headers =[
            ('Cookie', cookies),
        ]
    ) as websocket:
        while True:
            message = websocket.recv()
            print(message)  # e.g., {"voltage": 1.0}

@BECATRUE BECATRUE added this to the v1.0.0 milestone Dec 17, 2025
@BECATRUE BECATRUE requested a review from kangz12345 December 17, 2025 07:12
@BECATRUE BECATRUE self-assigned this Dec 17, 2025
@BECATRUE BECATRUE added the enhancement New feature or request label Dec 17, 2025
@BECATRUE BECATRUE removed the request for review from kangz12345 December 26, 2025 09:33
@BECATRUE BECATRUE mentioned this pull request Jan 1, 2026
@BECATRUE BECATRUE force-pushed the BECATRUE/76/notify-dac branch from 0d7a440 to cc9819b Compare January 2, 2026 04:42
@BECATRUE BECATRUE force-pushed the BECATRUE/76/notify-dac branch from cc9819b to 14ebbe5 Compare January 2, 2026 05:38
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jan 2, 2026

@BECATRUE BECATRUE requested a review from kangz12345 February 26, 2026 05:36
@BECATRUE BECATRUE marked this pull request as ready for review February 26, 2026 05:36
@BECATRUE BECATRUE force-pushed the BECATRUE/76/notify-dac branch from d9509d7 to 6727af8 Compare February 26, 2026 05:38
@BECATRUE BECATRUE force-pushed the BECATRUE/76/notify-dac branch from 6727af8 to a4a8e7b Compare February 26, 2026 05:56
@sonarqubecloud
Copy link
Copy Markdown

for lock in locks:
if lock.expires_at > now:
self._channel_to_lock[lock.channel.channel] = lock
self._channel_to_lock[lock.channel.channel] = lock
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this update for?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's from #97.

Copy link
Copy Markdown
Member

@kangz12345 kangz12345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

for lock in locks:
if lock.expires_at > now:
self._channel_to_lock[lock.channel.channel] = lock
self._channel_to_lock[lock.channel.channel] = lock
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's from #97.

@BECATRUE BECATRUE merged commit aa6bb5d into develop Feb 26, 2026
3 checks passed
@BECATRUE BECATRUE deleted the BECATRUE/76/notify-dac branch February 26, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notify DAC output

2 participants