Spremembe narejene na zadnji delavnici.
14 files added
9 files modified
New file |
| | |
| | | |
| | | void setup() { |
| | | Serial.begin(9600); |
| | | } |
| | | long randNo; |
| | | // the loop routine runs over and over again forever: |
| | | void loop() { |
| | | randNo=random(10,40); |
| | | Serial.println(randNo); |
| | | delay(1000); // delay in between reads for stability |
| | | } |
| | | |
| | | |
| | | |
New file |
| | |
| | | import serial |
| | | import io |
| | | |
| | | ser=serial.Serial('/dev/ttyUSB0',9600,timeout=10) |
| | | while True: |
| | | ret=ser.readline() |
| | | print(ret.decode('ascii').strip()) |
| | | |
| | | ser.close() |
| | |
| | | |
| | | [packages] |
| | | django = "*" |
| | | djangorestframework = "*" |
| | | mysqlclient = "*" |
| | | |
| | | [dev-packages] |
| | | |
New file |
| | |
| | | from django.contrib import admin |
| | | |
| | | # Register your models here. |
New file |
| | |
| | | from django.apps import AppConfig |
| | | |
| | | |
| | | class CalculatorConfig(AppConfig): |
| | | name = 'calculator' |
New file |
| | |
| | | from django import forms |
| | | |
| | | class Stevila(forms.Form): |
| | | a=forms.FloatField() |
| | | b=forms.FloatField() |
New file |
| | |
| | | from django.db import models |
| | | |
| | | # Create your models here. |
New file |
| | |
| | | <!DOCTYPE html> |
| | | <html lang="en"> |
| | | <head> |
| | | <meta charset="UTF-8"> |
| | | <title>Sestej stevili</title> |
| | | </head> |
| | | <body> |
| | | <p>Sestej stevili</p> |
| | | |
| | | <form method="POST"> |
| | | {{ formular.as_p }} |
| | | {% csrf_token %} |
| | | <button type="submit">Poslji</button> |
| | | </form> |
| | | <hr /> |
| | | <p>Vsota je: {{ vsota }}</p> |
| | | </body> |
| | | </html> |
New file |
| | |
| | | from django.test import TestCase |
| | | |
| | | # Create your tests here. |
New file |
| | |
| | | from django.urls import path |
| | | from . import views |
| | | urlpatterns = [ |
| | | path('sestej', views.sestej, name='sestej'), |
| | | ] |
New file |
| | |
| | | from django.shortcuts import render |
| | | from django.http import HttpResponse |
| | | |
| | | from .forms import Stevila |
| | | |
| | | # Create your views here. |
| | | |
| | | |
| | | def sestej(request): |
| | | |
| | | form=Stevila() |
| | | vsota="NaN" |
| | | |
| | | if request.method == "POST": |
| | | print(request.POST['a']) |
| | | form=Stevila(request.POST) |
| | | |
| | | if form.is_valid(): |
| | | vsota=float(form.data['a'])+float(form.data['b']) |
| | | |
| | | print(form.data) |
| | | #form=Stevila() |
| | | return render(request, 'calculator/sestej.html', context={'formular':form, 'vsota':vsota}) |
| | | |
| | |
| | | # SECURITY WARNING: don't run with debug turned on in production! |
| | | DEBUG = True |
| | | |
| | | ALLOWED_HOSTS = [] |
| | | ALLOWED_HOSTS = ['localhost', 'moja.domena.si'] |
| | | |
| | | |
| | | # Application definition |
| | |
| | | 'django.contrib.sessions', |
| | | 'django.contrib.messages', |
| | | 'django.contrib.staticfiles', |
| | | 'sensorui.apps' |
| | | 'sensorui', |
| | | 'calculator', |
| | | 'rest_framework' |
| | | ] |
| | | |
| | | MIDDLEWARE = [ |
| | |
| | | |
| | | DATABASES = { |
| | | 'default': { |
| | | 'ENGINE': 'django.db.backends.sqlite3', |
| | | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), |
| | | # 'ENGINE': 'django.db.backends.sqlite3', |
| | | # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), |
| | | 'ENGINE': 'django.db.backends.mysql', |
| | | 'NAME': 'samo', |
| | | 'USER': 'samo', |
| | | 'PASSWORD': 'samo', |
| | | 'HOST': 'localhost', # Or an IP Address that your DB is hosted on |
| | | 'PORT': '3306', |
| | | } |
| | | } |
| | | |
| | |
| | | # https://docs.djangoproject.com/en/2.1/howto/static-files/ |
| | | |
| | | STATIC_URL = '/static/' |
| | | STATIC_ROOT = os.path.join(BASE_DIR, 'static/') |
| | |
| | | |
| | | urlpatterns = [ |
| | | path('admin/', admin.site.urls), |
| | | path('sensorui/', include('sensorui.urls')) |
| | | path('sensorui/', include('sensorui.urls')), |
| | | path('calculator/', include('calculator.urls')) |
| | | ] |
| | |
| | | from django.contrib import admin |
| | | |
| | | # Register your models here. |
| | | from .models import * |
| | | |
| | | admin.site.register(Measurement) |
| | | admin.site.register(Sensor) |
| | | admin.site.register(SensorType) |
| | | |
| | | |
| | | |
New file |
| | |
| | | # Generated by Django 2.1.7 on 2019-03-25 17:17 |
| | | |
| | | from django.db import migrations, models |
| | | import django.db.models.deletion |
| | | |
| | | |
| | | class Migration(migrations.Migration): |
| | | |
| | | initial = True |
| | | |
| | | dependencies = [ |
| | | ] |
| | | |
| | | operations = [ |
| | | migrations.CreateModel( |
| | | name='Measurement', |
| | | fields=[ |
| | | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
| | | ('value', models.FloatField()), |
| | | ('timestamp', models.DateTimeField(auto_now_add=True)), |
| | | ], |
| | | ), |
| | | migrations.CreateModel( |
| | | name='Sensor', |
| | | fields=[ |
| | | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
| | | ('name', models.CharField(max_length=30)), |
| | | ], |
| | | ), |
| | | migrations.CreateModel( |
| | | name='SensorType', |
| | | fields=[ |
| | | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
| | | ('name', models.CharField(max_length=30)), |
| | | ('unit', models.CharField(max_length=10)), |
| | | ], |
| | | ), |
| | | migrations.AddField( |
| | | model_name='sensor', |
| | | name='sensor_type', |
| | | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='sensorui.SensorType'), |
| | | ), |
| | | migrations.AddField( |
| | | model_name='measurement', |
| | | name='sensor_id', |
| | | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='sensorui.Sensor'), |
| | | ), |
| | | ] |
| | |
| | | from django.db import models |
| | | |
| | | |
| | | # Create your models here. |
| | | |
| | | |
| | | class SensorType(models.Model): |
| | | name = models.CharField(max_length=30) |
| | | unit = models.CharField(max_length=10) |
| | | |
| | | def __str__(self): |
| | | return self.name |
| | | |
| | | |
| | | class Sensor(models.Model): |
| | | sensor_type = models.ForeignKey(SensorType, on_delete=models.CASCADE) |
| | | name = models.CharField(max_length=30) |
| | | |
| | | def __str__(self): |
| | | return self.name |
| | | |
| | | |
| | | class Measurement(models.Model): |
| | | sensor_id = models.ForeignKey(Sensor, on_delete=models.CASCADE) |
| | | value = models.FloatField() |
| | | timestamp = models.DateTimeField(auto_now_add=True) |
| | | |
| | | def __str__(self): |
| | | return "{} {} {} {}".format(self.sensor_id, self.value, self.sensor_id.sensor_type.unit, self.timestamp) |
| | |
| | | {% load static %} |
| | | |
| | | <!DOCTYPE html> |
| | | <html lang="en"> |
| | | <head> |
| | | <meta charset="UTF-8"> |
| | | <title>Hello world stran</title> |
| | | <script> |
| | | function myFunction(){ |
| | | var xhttp = new XMLHttpRequest(); |
| | | xhttp.open("GET","my-ajax-test/", true); |
| | | xhttp.send(); |
| | | } |
| | | |
| | | </script> |
| | | |
| | | </head> |
| | | <body> |
| | | <h1>hello world</h1> |
| | | <img src='{% static "sensorui/muca.jpg" %}'> |
| | | <button onclick="myFunction()">Vzgi lucko</button> |
| | | sin(pi/2)={{ sinpi2 }} |
| | | <hr /> |
| | | Zahtevek podal: {{ moje_ime }} |
| | |
| | | </tr> |
| | | {% for row in data_table %} |
| | | <tr> |
| | | <td>{{ row.sensor_id }}</td> |
| | | <td>{{ row.data }}</td> |
| | | <td>{{ row.date }}</td> |
| | | <td>{{ row.sensor_id.pk }}</td> |
| | | <td>{{ row.value }}{{ row.sensor_id.sensor_type.unit }}</td> |
| | | <td>{{ row.timestamp }}</td> |
| | | </tr> |
| | | {% endfor %} |
| | | </table> |
| | |
| | | from django.urls import path |
| | | from . import views |
| | | urlpatterns = [ |
| | | path('', views.index, name='index'), |
| | | path('<int:pk>', views.index, name='index'), |
| | | path('api/measurement', views.SensorData.as_view(), name='measurement'), |
| | | path('my-ajax-test/', views.myajaxtestview, name='ajax-test-view'), |
| | | ] |
| | |
| | | from django.shortcuts import render |
| | | |
| | | from .models import * |
| | | from django.http.response import HttpResponse |
| | | # Create your views here. |
| | | |
| | | from math import pi, sin |
| | | from rest_framework.views import APIView |
| | | from rest_framework.response import Response |
| | | |
| | | def index(request): |
| | | |
| | | class SensorData(APIView): |
| | | def post(self, request): |
| | | data=request.data |
| | | m=Measurement(sensor_id=Sensor.objects.get(pk=data['sensor_id']), value=data['value']) |
| | | m.save() |
| | | return Response(None) |
| | | |
| | | |
| | | |
| | | |
| | | def index(request, pk): |
| | | |
| | | sinpi2=sin(pi/2) |
| | | intlist=list(range(1,11)) |
| | | |
| | | moj_template='sensorui/index.html' |
| | | |
| | | data_table=[] |
| | | measurements=Measurement.objects.filter(sensor_id=pk).all() |
| | | |
| | | data_table.append({'sensor_id':1, |
| | | 'data': 10.0, |
| | | 'date': '10.10.1010' |
| | | }) |
| | | |
| | | data_table.append({'sensor_id':1, |
| | | 'data': 8.0, |
| | | 'date': '11.10.1010' |
| | | }) |
| | | |
| | | data_table.append({'sensor_id':1, |
| | | 'data': 12.0, |
| | | 'date': '11.11.1010' |
| | | }) |
| | | context={ |
| | | 'sinpi2':sinpi2, |
| | | 'moje_ime': "Samo Penic", |
| | | 'intlist': intlist, |
| | | 'data_table': data_table, |
| | | 'data_table': measurements, |
| | | } |
| | | return render(request, moj_template, context) |
| | | |
| | | |
| | | def myajaxtestview(request): |
| | | print("AJAX REQUEST") |
| | | rezultat=(int(request.GET['a'])+int(request.GET['b'])) |
| | | return HttpResponse(rezultat) |