-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Django 2 #1
base: master
Are you sure you want to change the base?
Changes from all commits
b275d7f
f691b57
ff5fd86
de2f9f9
fc9bf19
8944870
9d895c8
6bbc79b
c355ca2
ff45daa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Installation guide | ||
This guide is written to be used with a raspbian. | ||
|
||
## Setup network | ||
Set a static IP adress in '/etc/dhcpcd.conf' | ||
|
||
``` | ||
sudo -i | ||
echo "interface eth0" >> /etc/dhcpcd.conf | ||
echo "static ip_address=10.2.3.4/24" >> /etc/dhcpcd.conf | ||
echo "static routers=10.2.3.1" >> /etc/dhcpcd.conf | ||
echo "static domain_name_server=10.2.3.2 10.2.3.3" >> /etc/dhcpcd.conf | ||
reboot | ||
``` | ||
|
||
## Setup SSH(optional, but handy) | ||
Edit /etc/ssh/sshd_config to fit your needs | ||
``` | ||
sudo vim /etc/ssh/sshd_config | ||
``` | ||
Start and enable ssh | ||
``` | ||
sudo systemctl enable --now ssh | ||
``` | ||
## Install oversight | ||
Install poetry | ||
``` | ||
sudo pip3 install poetry | ||
``` | ||
Create a user | ||
``` | ||
sudo adduser --system oversight | ||
``` | ||
Change to the overside user | ||
``` | ||
sudo su - oversight -s /bin/bash | ||
``` | ||
Go to the home directory | ||
``` | ||
cd /home/oversight | ||
``` | ||
Clone the oversight git repo | ||
``` | ||
git clone https://github.com/feanor12/oversight.git | ||
``` | ||
Change working directory to the cloned repository | ||
``` | ||
cd oversight | ||
``` | ||
Checkout the django2 branch | ||
``` | ||
git checkout django2 | ||
``` | ||
Install dependencies | ||
``` | ||
poetry install | ||
``` | ||
Prepare config file | ||
``` | ||
cp -r example/ config | ||
vim config/settings.py | ||
``` | ||
Generate Database, Superuser and static files | ||
``` | ||
poetry shell | ||
env PYTHONPATH="./config" ./manage.py migrate –settings="settings" | ||
env PYTHONPATH="./config" ./manage.py collectstatic –settings="settings" | ||
env PYTHONPATH="./config" ./manage.py createsuperuser –settings="settings" | ||
``` | ||
Test server | ||
``` | ||
env PYTHONPATH=“./config” ./manage.py runserver –settings="settings" | ||
firefox http://127.0.0.1:8000 | ||
``` | ||
|
||
## Install Proxy | ||
Install nginx | ||
``` | ||
sudo apt install nginx | ||
``` | ||
Copy template from oversight | ||
``` | ||
sudo cp /home/oversight/oversight/ansible/roles/nginx/templates/nginx.conf /etc/nginx/nginx.conf | ||
``` | ||
Replace the placeholders in the template and remove template if-lines | ||
``` | ||
sudo sed -i -e "s/inventory_hostname/my.domain.com/g" /etc/nginx/nginx.conf | ||
sudo sed -i -e "s/{{ 443 if nginx_no_ssl is undefined else 80 }}/443/g" /etc/nginx/nginx.conf | ||
sudo sed -i -e "/{%.*%}/d" /etc/nginx/nginx.conf | ||
``` | ||
Copy ssl certificates | ||
``` | ||
sudo mkdir /etc/nginx/ssl | ||
sudo cp server.crt server.key dhparams.pem /etc/nginx/etc | ||
``` | ||
|
||
TODO | ||
- fix server.py | ||
- start services | ||
- copy systemd unit files | ||
- start services(systemctl) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
pyserial = "*" | ||
minimalmodbus = "*" | ||
django = "*" | ||
cherrypy = "*" | ||
requests = "*" | ||
cheroot = "*" | ||
|
||
[dev-packages] | ||
|
||
[requires] | ||
python_version = "3.7" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# oversight | ||
|
||
Django based web application for data logging. | ||
|
||
# Features | ||
* Overview of the latest sensor values | ||
* Detailed view with the latest values and a diagram showing the history | ||
* Compare multiple sensors using a diagram | ||
* Add sensor with the Django admin web interface | ||
* API to set and get sensor data | ||
* Logging daemon and web application are run in parallel | ||
* Ansible scripts for easier setup on Raspberry Pi | ||
* Easy to include new sensors | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import logging | ||
import threading | ||
import Queue | ||
from SimpleXMLRPCServer import SimpleXMLRPCServer | ||
from multiprocessing import Queue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. das direkte äquivalent zu There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wird in dem Fall queue.task_done() überhaupt benötigt? Ich sehe kein queue.join, oder ähnliches. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stimmt wahrscheinlich; ich würde es allerdings lassen fallst den code mal umbaust (sauberer ist es auf jeden fall einen task zu quittieren) |
||
from xmlrpc.server import SimpleXMLRPCServer | ||
|
||
from django.conf import settings | ||
from django.core.management.base import NoArgsCommand | ||
from django.core.management.base import BaseCommand | ||
|
||
import requests | ||
|
||
|
@@ -87,12 +87,12 @@ def worker(queue, tasks): | |
tasks[item[0]](*item[1:]) | ||
except Exception as e: | ||
logger.error("Task failed: ", exc_info=e) | ||
queue.task_done() | ||
#queue.task_done() | ||
|
||
|
||
class Command(NoArgsCommand): | ||
class Command(BaseCommand): | ||
def handle(self, **options): | ||
queue = Queue.Queue() | ||
queue = Queue() | ||
server = SimpleXMLRPCServer(("localhost", 12345)) | ||
sensor_manager = SensorManager() | ||
server.register_instance(sensor_manager) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,50 @@ | ||
# encoding: utf8 | ||
from django.db import models, migrations | ||
# Generated by Django 2.1.1 on 2018-09-12 10:53 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='LogEntry', | ||
fields=[ | ||
(u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)), | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('datetime', models.DateTimeField(default=django.utils.timezone.now)), | ||
('value', models.CharField(max_length=255)), | ||
], | ||
options={ | ||
}, | ||
bases=(models.Model,), | ||
), | ||
migrations.CreateModel( | ||
name='Sensor', | ||
fields=[ | ||
(u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)), | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255)), | ||
('api_endpoint', models.SlugField()), | ||
('api_endpoint', models.SlugField(unique=True)), | ||
('unit', models.CharField(max_length=255)), | ||
('sensor_class', models.CharField(max_length=255)), | ||
('params', models.TextField()), | ||
('current_log', models.ForeignKey(to='oversight.LogEntry', to_field=u'id', null=True)), | ||
('log_plot', models.BooleanField(default=False)), | ||
('logging_enabled', models.BooleanField(default=True)), | ||
('alarm_below', models.CharField(blank=True, max_length=255)), | ||
('alarm_above', models.CharField(blank=True, max_length=255)), | ||
('alarm_acked', models.BooleanField(default=True)), | ||
('current_log', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='oversight.LogEntry')), | ||
], | ||
options={ | ||
}, | ||
bases=(models.Model,), | ||
), | ||
migrations.AddField( | ||
model_name='logentry', | ||
name='sensor', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='oversight.Sensor'), | ||
), | ||
migrations.AlterIndexTogether( | ||
name='logentry', | ||
index_together={('sensor', 'datetime')}, | ||
), | ||
] |
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ich verwende inzwischen poetry; bei pipenv wird für mich zu wenig wert auf backward-compat und so gelegt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dann leg ich noch ein poetry file an.