├── Sending data to server.ipynb └── djangoRT ├── db.sqlite3 ├── djangoRT ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-36.pyc │ ├── routing.cpython-36.pyc │ ├── settings.cpython-36.pyc │ ├── urls.cpython-36.pyc │ └── wsgi.cpython-36.pyc ├── routing.py ├── settings.py ├── urls.py └── wsgi.py ├── firstPage ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-36.pyc │ ├── admin.cpython-36.pyc │ ├── consumer.cpython-36.pyc │ ├── models.cpython-36.pyc │ └── views.cpython-36.pyc ├── admin.py ├── apps.py ├── consumer.py ├── migrations │ ├── __init__.py │ └── __pycache__ │ │ └── __init__.cpython-36.pyc ├── models.py ├── tests.py └── views.py ├── manage.py └── template └── index.html /Sending data to server.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Using WebSocket Client" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import json\n", 17 | "import requests\n", 18 | "import redis\n", 19 | "import websocket" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 2, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "ws=websocket.WebSocket()" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 3, 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "import random,time" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 18, 43 | "metadata": {}, 44 | "outputs": [], 45 | "source": [ 46 | "ws.connect('ws://localhost:8000/ws/polData/')" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "metadata": { 53 | "scrolled": true 54 | }, 55 | "outputs": [], 56 | "source": [ 57 | "for i in range(1000):\n", 58 | " time.sleep(3)\n", 59 | " ws.send(json.dumps({'value':random.randint(1,100)}))" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 33, 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [] 68 | } 69 | ], 70 | "metadata": { 71 | "kernelspec": { 72 | "display_name": "Python 3", 73 | "language": "python", 74 | "name": "python3" 75 | }, 76 | "language_info": { 77 | "codemirror_mode": { 78 | "name": "ipython", 79 | "version": 3 80 | }, 81 | "file_extension": ".py", 82 | "mimetype": "text/x-python", 83 | "name": "python", 84 | "nbconvert_exporter": "python", 85 | "pygments_lexer": "ipython3", 86 | "version": "3.6.8" 87 | } 88 | }, 89 | "nbformat": 4, 90 | "nbformat_minor": 2 91 | } 92 | -------------------------------------------------------------------------------- /djangoRT/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/db.sqlite3 -------------------------------------------------------------------------------- /djangoRT/djangoRT/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/djangoRT/__init__.py -------------------------------------------------------------------------------- /djangoRT/djangoRT/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/djangoRT/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /djangoRT/djangoRT/__pycache__/routing.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/djangoRT/__pycache__/routing.cpython-36.pyc -------------------------------------------------------------------------------- /djangoRT/djangoRT/__pycache__/settings.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/djangoRT/__pycache__/settings.cpython-36.pyc -------------------------------------------------------------------------------- /djangoRT/djangoRT/__pycache__/urls.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/djangoRT/__pycache__/urls.cpython-36.pyc -------------------------------------------------------------------------------- /djangoRT/djangoRT/__pycache__/wsgi.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/djangoRT/__pycache__/wsgi.cpython-36.pyc -------------------------------------------------------------------------------- /djangoRT/djangoRT/routing.py: -------------------------------------------------------------------------------- 1 | from channels.routing import ProtocolTypeRouter,URLRouter 2 | from channels.auth import AuthMiddlewareStack 3 | 4 | from django.urls import path 5 | from firstPage import consumer 6 | 7 | websocket_urlPattern=[ 8 | path('ws/polData/',consumer.DashConsumer), 9 | ] 10 | 11 | application=ProtocolTypeRouter({ 12 | # 'http': 13 | 'websocket':AuthMiddlewareStack(URLRouter(websocket_urlPattern)) 14 | 15 | }) -------------------------------------------------------------------------------- /djangoRT/djangoRT/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for djangoRT project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.2.3. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.2/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'w*r*zi7r@vt#uy@14em)y54rhsnrnt%=fjx+y6&&@9t=yl7u=u' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'channels', 35 | 'django.contrib.admin', 36 | 'django.contrib.auth', 37 | 'django.contrib.contenttypes', 38 | 'django.contrib.sessions', 39 | 'django.contrib.messages', 40 | 'django.contrib.staticfiles', 41 | 'firstPage', 42 | ] 43 | 44 | MIDDLEWARE = [ 45 | 'django.middleware.security.SecurityMiddleware', 46 | 'django.contrib.sessions.middleware.SessionMiddleware', 47 | 'django.middleware.common.CommonMiddleware', 48 | 'django.middleware.csrf.CsrfViewMiddleware', 49 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 50 | 'django.contrib.messages.middleware.MessageMiddleware', 51 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 52 | ] 53 | 54 | ROOT_URLCONF = 'djangoRT.urls' 55 | 56 | TEMPLATES = [ 57 | { 58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 59 | 'DIRS': [ 60 | os.path.join(BASE_DIR,'template') 61 | ], 62 | 'APP_DIRS': True, 63 | 'OPTIONS': { 64 | 'context_processors': [ 65 | 'django.template.context_processors.debug', 66 | 'django.template.context_processors.request', 67 | 'django.contrib.auth.context_processors.auth', 68 | 'django.contrib.messages.context_processors.messages', 69 | ], 70 | }, 71 | }, 72 | ] 73 | 74 | WSGI_APPLICATION = 'djangoRT.wsgi.application' 75 | ASGI_APPLICATION = 'djangoRT.routing.application' 76 | 77 | CHANNEL_LAYERS = { 78 | 'default': { 79 | 'BACKEND': 'channels_redis.core.RedisChannelLayer', 80 | 'CONFIG': { 81 | "hosts": [('127.0.0.1', 6379)], 82 | }, 83 | }, 84 | } 85 | 86 | # CHANNEL_LAYERS = { 87 | # "default": { 88 | # "BACKEND": "channels.layers.InMemoryChannelLayer" 89 | # } 90 | # } 91 | 92 | # Database 93 | # https://docs.djangoproject.com/en/2.2/ref/settings/#databases 94 | 95 | DATABASES = { 96 | 'default': { 97 | 'ENGINE': 'django.db.backends.sqlite3', 98 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 99 | } 100 | } 101 | 102 | 103 | # Password validation 104 | # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators 105 | 106 | AUTH_PASSWORD_VALIDATORS = [ 107 | { 108 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 109 | }, 110 | { 111 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 112 | }, 113 | { 114 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 115 | }, 116 | { 117 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 118 | }, 119 | ] 120 | 121 | 122 | # Internationalization 123 | # https://docs.djangoproject.com/en/2.2/topics/i18n/ 124 | 125 | LANGUAGE_CODE = 'en-us' 126 | 127 | TIME_ZONE = 'UTC' 128 | 129 | USE_I18N = True 130 | 131 | USE_L10N = True 132 | 133 | USE_TZ = True 134 | 135 | 136 | # Static files (CSS, JavaScript, Images) 137 | # https://docs.djangoproject.com/en/2.2/howto/static-files/ 138 | 139 | STATIC_URL = '/static/' 140 | -------------------------------------------------------------------------------- /djangoRT/djangoRT/urls.py: -------------------------------------------------------------------------------- 1 | """djangoRT URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.2/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | from firstPage import views 19 | 20 | urlpatterns = [ 21 | path('admin/', admin.site.urls), 22 | path('',views.index,name='Home'), 23 | ] 24 | -------------------------------------------------------------------------------- /djangoRT/djangoRT/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for djangoRT project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoRT.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /djangoRT/firstPage/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/firstPage/__init__.py -------------------------------------------------------------------------------- /djangoRT/firstPage/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/firstPage/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /djangoRT/firstPage/__pycache__/admin.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/firstPage/__pycache__/admin.cpython-36.pyc -------------------------------------------------------------------------------- /djangoRT/firstPage/__pycache__/consumer.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/firstPage/__pycache__/consumer.cpython-36.pyc -------------------------------------------------------------------------------- /djangoRT/firstPage/__pycache__/models.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/firstPage/__pycache__/models.cpython-36.pyc -------------------------------------------------------------------------------- /djangoRT/firstPage/__pycache__/views.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/firstPage/__pycache__/views.cpython-36.pyc -------------------------------------------------------------------------------- /djangoRT/firstPage/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /djangoRT/firstPage/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class FirstpageConfig(AppConfig): 5 | name = 'firstPage' 6 | -------------------------------------------------------------------------------- /djangoRT/firstPage/consumer.py: -------------------------------------------------------------------------------- 1 | from channels.generic.websocket import AsyncWebsocketConsumer 2 | import json 3 | 4 | class DashConsumer(AsyncWebsocketConsumer): 5 | 6 | async def connect(self): 7 | self.groupname='dashboard' 8 | await self.channel_layer.group_add( 9 | self.groupname, 10 | self.channel_name, 11 | ) 12 | 13 | await self.accept() 14 | 15 | async def disconnect(self,close_code): 16 | 17 | await self.channel_layer.group_discard( 18 | self.groupname, 19 | self.channel_name 20 | ) 21 | 22 | 23 | async def receive(self, text_data): 24 | datapoint = json.loads(text_data) 25 | val =datapoint['value'] 26 | 27 | await self.channel_layer.group_send( 28 | self.groupname, 29 | { 30 | 'type':'deprocessing', 31 | 'value':val 32 | } 33 | ) 34 | 35 | print ('>>>>',text_data) 36 | 37 | # pass 38 | 39 | async def deprocessing(self,event): 40 | valOther=event['value'] 41 | await self.send(text_data=json.dumps({'value':valOther})) 42 | -------------------------------------------------------------------------------- /djangoRT/firstPage/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/firstPage/migrations/__init__.py -------------------------------------------------------------------------------- /djangoRT/firstPage/migrations/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sharmasw/RealTimeDjangoTutorial/b7197ae1cc138bf510c657d0611d75301cc8d713/djangoRT/firstPage/migrations/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /djangoRT/firstPage/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /djangoRT/firstPage/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /djangoRT/firstPage/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | 5 | def index(request): 6 | return render(request,'index.html') 7 | -------------------------------------------------------------------------------- /djangoRT/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoRT.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /djangoRT/template/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 |
29 | 30 |
31 | 32 | 33 | 56 | --------------------------------------------------------------------------------