Skip to content

Instantly share code, notes, and snippets.

View johngrantuk's full-sized avatar

John Grant johngrantuk

View GitHub Profile
@johngrantuk
johngrantuk / settings.py
Created March 29, 2016 15:58
Django settings for Channels project
"""
Django settings for sensor project.
Generated by 'django-admin startproject' using Django 1.9.2.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
@johngrantuk
johngrantuk / consumers.py
Created March 29, 2016 15:10
Django Channel ws_connect consumer
from channels import Group
def ws_connect(message):
print("Someone connected.")
path = message['path'] # i.e. /sensor/
if path == b’/sensor/':
print("Adding new user to sensor group")
Group(“sensor").add(message.reply_channel) # Adds user to group for broadcast
message.reply_channel.send({ # Reply to individual directly