Skip to content

Commit

Permalink
Merge pull request #44 from clavay/master
Browse files Browse the repository at this point in the history
Update to Django 3
  • Loading branch information
clavay committed May 9, 2022
2 parents 16c7c01 + 5632f6c commit a01ff35
Show file tree
Hide file tree
Showing 286 changed files with 16,717 additions and 3,429 deletions.
40 changes: 40 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,43 @@
- fixed re-login after logout (#22)
- added LINK_TARGET option to change the default behaviour of links in view overview (#23)
- Catching exceptions if DB close while pyscada is running

0.7.0rc17, 0.7.0rc18
- add pre_delete signals to stop the background process before deleting a device
- move widget post_save signal to the model to remove the global receiver (not filtering by sender)
- move device handlers to core
- add stop in DAQ Process restart
- move the device and variable protocol specific configuration to core
- add protocol name in device __str__ for the variable js admin file
- add complex events

0.7.0rc19
- add fk_name in admin for bacnet device with 2 ForeignKey to Device model

0.7.0rc20
- add django channels to send informations between processes

0.7.0rc21
- Update docker config file
- Add optional PID_FILE_NAME to settings to allow multiple instances
- Add custom periodic auto caltulated variable

0.7.0rc22
- Add choose_login.html to have multiple login ways
- Add circular gauge to display control items
- Add silent delete option in admin for VariableState and Device to delete a lot of data
- Add grafana doc and config file to use Grafana to display data from a PyScada instance
- Add dictionaries to store string with a key. Allows to store strings for Variables

0.7.0rc23
- Add svg to render ProcessFlowDiagram. Allows to resize to fit the window size
- Add OPC-UA protocol
- close DB connection in scheduler to allow multiple instance on the same DB to run
- Add INT8 and UINT8 variable value class
- change the date range picker JS library
- Add logrotate config file
- Add a slider to change the refresh rate value of data handling

0.7.1rc1
- Update to Django 3
- Update docker config and doc to use pyscada repository
16 changes: 9 additions & 7 deletions docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ http {
}

# configuration of the server
server {
listen 80;
listen [::]:80;
server_name _; # substitute your machine's IP address or FQDN
return 301 https://$host$request_uri;
}
#server {
# listen 80;
# listen [::]:80;
# server_name _; # substitute your machine's IP address or FQDN
# return 301 https://$host$request_uri;
#}

server {
listen 443 default_server ssl;
listen 80 default_server;
listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;

server_name _; # substitute your machine's IP address or FQDN
Expand Down
2 changes: 1 addition & 1 deletion docker/pyscada/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WORKDIR /src/pyscada

RUN pip3 install gunicorn
RUN pip3 install mysqlclient
RUN pip3 install https://github.com/trombastic/PyScada/archive/dev/0.7.x.zip
RUN pip3 install https://github.com/pyscada/PyScada/tarball/master
RUN django-admin startproject PyScadaServer /src/pyscada/ --template /src/pyscada/project_template.zip
RUN chmod +x /src/pyscada/pyscada
RUN chmod +x /src/pyscada/pyscada_init
Expand Down
18 changes: 16 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
# import sys
# sys.path.insert(0, os.path.abspath('.'))

# Django setup
import os
import sys
import django
sys.path.insert(0, os.path.abspath('..'))
sys.path.append("/var/www/pyscada/PyScadaServer/PyScadaServer/")
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
django.setup()


# -- Project information -----------------------------------------------------

Expand All @@ -26,7 +35,7 @@
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '0.7.0rc16'
release = '0.7.1rc1'


# -- General configuration ---------------------------------------------------
Expand All @@ -39,8 +48,13 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx_js',
]

# Set JavaScript source paths
js_source_path = '../pyscada/hmi/static/pyscada/js/pyscada'

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

Expand Down Expand Up @@ -85,7 +99,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
#html_static_path = ['_static']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand Down
13 changes: 8 additions & 5 deletions docs/device_protokol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ Device Protocol IDs
- 1: Reserved (Scheduler)
- 2: SystemStat
- 3: Modbus
- 4: BACNet
- 4: `BACNet <https://github.com/pyscada/PyScada-BACNet>`_
- 5: VISA
- 6: 1-Wire
- 7: Phant
- 8: SMBus
- 9: Reserved (Jofra350)
- 10: GPIO
- 11: PT104
- 13: `SML (Smart Meter Language) <https://github.com/gkend/PyScada-SML>`_
- 10: `GPIO <https://github.com/pyscada/PyScada-GPIO>`_
- 11: `Reserved (PT104) <https://github.com/pyscada/PyScada-PT104>`_
- 12: `OPC-UA <https://github.com/clavay/PyScada-OPCUA>`_
- 13: `SML (Smart Meter Language) <https://github.com/gkend/PyScada-SML>`_
- 8X: Custom Worker
- 95: Reserved (Scripting)
- 93 `Reserved (Serial) <https://github.com/clavay/PyScada-Serial>`_
- 94 `Reserved (WebService) <https://github.com/clavay/PyScada-WebService>`_
- 95: `Reserved (Scripting) <https://github.com/pyscada/PyScada-Scripting>`_
- 96: Reserved (Event)
- 97: Reserved (Mail)
- 98: Reserved (Report)
Expand Down
16 changes: 12 additions & 4 deletions docs/docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Using Git.

::

git clone https://github.com/trombastic/PyScada.git
git clone https://github.com/pyscada/PyScada.git
cd PyScada/docker

Using wget.

::

wget -qO- -O tmp.zip https://github.com/trombastic/PyScada/archive/dev/0.7.x.zip && unzip tmp.zip && rm tmp.zip
cd PyScada-dev-0.7.x/docker
wget -qO- -O tmp.zip https://github.com/pyscada/PyScada/archive/refs/heads/master.zip && unzip tmp.zip && rm tmp.zip
cd PyScada-master/docker


Generating SSL Certificates
Expand All @@ -34,6 +34,7 @@ Generate ssl certificates for using ssl.

::

mkdir nginx/ssl
cd nginx/ssl
openssl req -x509 -nodes -days 1780 -newkey rsa:2048 -keyout ./pyscada_server.key -out ./pyscada_server.crt

Expand All @@ -60,4 +61,11 @@ The last step is to start the Container.

::

sudo docker-compose up -d
sudo docker-compose up -d

If you have an error or a command is stuck, run :

::

sudo docker-compose down
sudo docker system prune --force --volumes
86 changes: 86 additions & 0 deletions docs/grafana.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
Use Grafana
===========

Mysql
-----
Add user and give SELECT rights : sudo mysql -uroot -p -e "GRANT SELECT ON PyScada_db.* TO 'Grafana-user'@'localhost' IDENTIFIED BY 'Grafana-user-password';"

Nginx
-----
Add in /etc/nginx/nginx.conf after http { ... } :
::
include /etc/nginx/grafana-access.conf;
Create /etc/nginx/grafana-access.conf with :
::
stream {
# MySQL server
server {
listen 3305;
proxy_pass 127.0.0.1:3306;
proxy_timeout 60s;
proxy_connect_timeout 30s;
}
}
Restart Nginx :
::
sudo systemctl restart nginx

Grafana
-------
Add DB :
- Host :
- Local : /run/mysqld/mysqld.sock
- Remote : remote_ip:3305
- Database : PyScada_db
- User : Grafana-user
- Password : Grafana-user-password

Import the exported dashboard (json file in extras directory).

Or for example, add theses variables : set refresh on dashboard load, multi-value and all option :
- Add mysql datasource variable (type Datasource).
- Add variables with type query using $Datasource :
- Protocols : SELECT protocol AS __text, id AS __value FROM pyscada_deviceprotocol
- Devices : SELECT d.short_name AS __text, d.id AS __value FROM pyscada_device d WHERE d.protocol_id IN (${Protocols}) AND d.active = 1
- Units : SELECT u.unit AS __text, u.id AS __value FROM pyscada_unit u
- Variables : SELECT v.name AS __text, v.id AS __value FROM pyscada_variable v WHERE v.device_id IN (${Devices}) AND v.unit_id IN (${Units}) AND v.active = 1
- Time group (type Interval) : 1s,10s,1m,10m,30m,1h,6h,12h,1d,7d,14d,30d,1M
- Null as (type custom) : 0, NULL, previous

Example query :
::
SELECT
$__timeGroupAlias(r.date_saved,$time_group),
avg(IFNULL(r.value_float64, 0.0) + IFNULL(r.value_int64, 0.0) + IFNULL(r.value_int32, 0.0) + IFNULL(r.value_int16, 0.0) + IFNULL(r.value_boolean, 0.0)),
v.name AS metric
FROM pyscada_recordeddata as r
JOIN pyscada_variable v ON r.variable_id = v.id
WHERE
$__timeFilter(r.date_saved) AND
r.variable_id IN (${Variables})
GROUP BY time, metric
ORDER BY $__timeGroup(r.date_saved,$time_group,$null_as)

Embed in pyscada HMI
--------------------
Edit Grafana config file:
::
sudo nano /etc/grafana/grafana.ini

Find and set :
- allow_embedding = true
- For localhost grafana : root_url = http://localhost:3000/grafana/

For localhost grafana add in /etc/nginx/sites-enabled/pyscada.conf :
::
location /grafana/ {
proxy_pass http://127.0.0.1:3000/;
}
Restart Grafana server:
::
sudo systemctl restart grafana-server.service
Create a custom html panel with the code from a dashboard or a panel from sharing options in grafana

Other
-----
use ssl : http://www.turbogeek.co.uk/2020/09/30/grafana-how-to-configure-ssl-https-in-grafana/
5 changes: 4 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ A Open Source SCADA System with HTML5 HMI, build using the Django framework. If
frontend
backend
phant

device_protokol
grafana
raspberryPiOS
visa



Expand Down
17 changes: 14 additions & 3 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@
Installation
============

This installation guide covers the installation of PyScada for `Debian 7/8/9 <https://www.debian.org/>`_ ,
`Raspbian <https://www.raspbian.org/>`_, `Fedora 22/23 <https://www.fedoraproject.org/>`_ based Linux systems
This installation guide covers the installation of PyScada for `Debian 10/11 <https://www.debian.org/>`_ ,
`Raspberry Pi OS <https://www.raspberrypi.com/software/>`_, `Fedora 22/23 <https://www.fedoraproject.org/>`_ based Linux systems
using `MySQL <https://www.mysql.com/>`_ / `MariaDB <https://mariadb.com/>`_ or `SQLite <https://www.sqlite.org/>`_ as Database,
`Gunicorn <http://gunicorn.org/>`_ as WSGI HTTP Server and `nginx <http://nginx.org/>`_ as HTTP Server.

Automatic installation using a script
-------------------------------------

On the Raspberry Pi with internet connection run :

::

wget https://raw.githubusercontent.com/clavay/PyScada-Laborem/master/extras/install.sh -O install.sh
sudo chmod a+x install.sh
sudo ./install.sh


Dependencies
------------


Debian 9, Raspbian
^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^

::

Expand Down
4 changes: 2 additions & 2 deletions docs/phant.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Installation
============
Phant Installation
==================

add the following line to the urls.py:

Expand Down
10 changes: 10 additions & 0 deletions docs/raspberryPiOS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Raspberry Pi OS Installation
============================

Download last Lite image from `here <https://www.raspberrypi.com/software/operating-systems/>`__

Copy the image on the SD card using (change the name of the zip file and the path to the sd card)::

unzip -p the_zip_file.zip | sudo dd of=/dev/sdX bs=4M conv=fsync

More informations `here <https://www.raspberrypi.com/documentation/computers/getting-started.html>`__
13 changes: 13 additions & 0 deletions docs/visa.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Discover VISA devices
=====================

To discover GPIB/USB(/LXI?) devices run:

::

sudo python3
import pyvisa
rm=pyvisa.ResourceManager('@py')
rm.list_resources() # example : ('ASRL/dev/ttyAMA0::INSTR', 'USB0::1689::1032::C023569::0::INSTR', 'USB0::1689::851::1525638::0::INSTR')
inst=rm.open_resource('USB0::1689::851::1525638::0::INSTR'')
inst.query('*IDN?') # example : 'TEKTRONIX,AFG1022,1525638,SCPI:99.0 FV:V1.1.2\n'

0 comments on commit a01ff35

Please sign in to comment.