Pyscada Documentation: Release 0.6.17B2
Pyscada Documentation: Release 0.6.17B2
Pyscada Documentation: Release 0.6.17B2
Release 0.6.17b2
Martin Schröder
1 Installation 3
1.1 Add a new system-user for Pyscada (optional) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Install Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Create a MySql Database (optional) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4 Create a new Django Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 Initialize Database And Copy Static Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.6 Add a Admin User To Your Django Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.7 Setup of Nginx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.8 Add Init.d Scripts for SysV-Init (optional) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.9 Add Init.d Scripts for systemd (optional) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.10 Start the Django Development Server on Windows (optional) . . . . . . . . . . . . . . . . . . . . . 7
1.11 Add/Start the PyScada Services on Windows (optional) . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Django Settings 9
2.1 urls.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 settings.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3 Nginx Setup 13
3.1 nginx configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4 Command-line 15
4.1 Start the PyScada Daemons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.2 Start Gunicorn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.3 Get Installed PyScada Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.4 Export Database Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5 Features 17
6 Dependencies 19
7 Contribute 21
8 License 23
i
ii
PyScada Documentation, Release 0.6.17b2
A Open Source SCADA System with HTML5 HMI, build using the Django framework. If you like to setup your own
_SCADA_ system head over to the Installation section.
• Using the Frontend
• backend-docs
Installation
The installation of PyScada 0.6.x on Debian based Linux systems using MySQL as Database, Gunicorn as WSGI
HTTP Server and nginx as HTTP Server.
The installation of PyScada 0.6.x on Fedora 22/23 based Linux systems using MySQL as Database, Gunicorn as WSGI
HTTP Server and nginx as HTTP Server.
The installation of PyScada 0.6.x on Raspbian Linux systems using SQLite as Database, Gunicorn as WSGI HTTP
Server and nginx as HTTP Server.
The installation of PyScada 0.6.x on Microsoft Windows systems using SQLite as Database and the the Django De-
velopment Server as HTTP/WSGI Server.
Add a dedicated user for pyscada and add the home directory for static/media files and setup a virtual environemt.
sudo -i
useradd -r pyscada
mkdir -p /var/www/pyscada/http
chown -R pyscada:pyscada /var/www/pyscada
mkdir -p /home/pyscada
chown -R pyscada:pyscada /home/pyscada
ln -s /var/www/pyscada/ ~/www_pyscada
cd ~/
#virtualenv -p /usr/bin/python2.7 venv
#source venv/bin/activate
1.2.1 Debian 7
3
PyScada Documentation, Release 0.6.17b2
1.2.2 Debian 8
# as root
sudo dnf install libjpeg-turbo-devel-1.4.1-2.fc23 nginx mysql-server mysql-devel
#
sudo pip install cython
sudo pip install numpy
sudo pip install h5py
sudo pip install git+https://github.com/trombastic/PyScada.git@dev/0.6.x
sudo pip install gunicorn
sudo pip install MySQL-python
1.2.5 Windows
4 Chapter 1. Installation
PyScada Documentation, Release 0.6.17b2
Create the Database and grand the nessesery permission. Replace PyScada_db, PyScada-user and PyScada-user-
password.
mysql -uroot -p -e "CREATE DATABASE PyScada_db CHARACTER SET utf8;"
mysql -uroot -p -e "GRANT ALL PRIVILEGES ON PyScada_db.* TO 'PyScada-user'@'localhost' IDENTIFIED BY
To start the Dataaquasition daemon(s) and guinicorn, there are two example scripts in the git repository. Copy them to
the init.d path of your machine and make them executible.
Fill in the full path to the django project dir (were the manage.py is located). Replace the four spaces between the
daemon (modbus) and the path with a tab.
#!/bin/sh
#/etc/default/pyscada_daemon
DAEMONS=(
'modbus /var/www/pyscada/PyScadaServer/'
)
RUN_AS='pyscada'
Also fill in the path to your django project dir and replace the four spaces between the django projectname
(PyScadaserver) the project path and the number of workers (10) with tabs.
#!/bin/sh
#/etc/default/gunicorn_django
SERVERS=(
'PyScadaServer /var/www/pyscada/PyScadaServer 5'
)
RUN_AS='pyscada'
6 Chapter 1. Installation
PyScada Documentation, Release 0.6.17b2
Open a Windows Command-line (cmd.exe) and start the Django Development Server.
cd C:/Users/_YOUR_USERNAME_/www/PyScadaServer # Windows
python manage.py runserver --insecure
Using pyscada background daemons in Windows is currently not supported, to start the daemons in foreground open
a Windows Command-line (cmd.exe) for every daemon and start it with the following command.
cd C:/Users/_YOUR_USERNAME_/www/PyScadaServer
python manage.py PyScadaWindowsDaemonHandler daemon_name
It is also posible to register the modbus daemon as an windows service, to do this download the from registratioen skript
from https://raw.githubusercontent.com/trombastic/PyScada/dev/0.6.x/extras/service/windows/register_windows_service_modbus.py
and copy it to the project root folder.
cd C:/Users/_YOUR_USERNAME_/www/PyScadaServer
python register_windows_service_modbus.py
8 Chapter 1. Installation
CHAPTER 2
Django Settings
2.1 urls.py
Open the urls configuration file and add the nesseary rewrite rule to the django URL dispatcher.
nano /var/www/pyscada/PyScadaServer/PyScadaServer/urls.py
...
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('pyscada.hmi.urls')),
...
2.2 settings.py
Open the django settings file and make the following modifications. See also the django documentation for more
Information.
nano /var/www/pyscada/PyScadaServer/PyScadaServer/settings.py
First deaktivate the debuging, if debuging is active django will keep all SQL queries in the ram, the dataaquasition
runs many queries so your system will run fast out of memory. Keep in mind to restart guinicorn and all dataaquasion
daemons after you change the debuging state.
DEBUG = False
TEMPLATE_DEBUG = DEBUG
Add the host/domain of your machine, is this case every url that point to a ip of the machine is allowed.
ALLOWED_HOSTS = ['*']
Add the PyScada and the subapps to the installed apps list.
INSTALLED_APPS = (
...
'pyscada',
'pyscada.modbus',
'pyscada.hmi',
'pyscada.systemstat',
'pyscada.export'
)
To use the MySQL Database, fill in the database, the user and password as selected in the create Database section.
9
PyScada Documentation, Release 0.6.17b2
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'PyScada_db',
'USER': 'PyScada-user',
'PASSWORD': 'PyScada-user-password'
}
}
STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/pyscada/http/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = '/var/www/pyscada/http/media/'
Add all PyScada specific settings, keep in mind to set the file right source file encoding in the settings.py file header
(see also https://www.python.org/dev/peps/pep-0263/).
#!/usr/bin/python
# -*- coding: <encoding name> -*-
# PyScada settings
# https://github.com/trombastic/PyScada
# email settings
DEFAULT_FROM_EMAIL = 'example@host.com'
EMAIL_HOST = 'mail.host.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'pyscada@host.com'
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_HOST_PASSWORD = 'password'
EMAIL_SUBJECT_PREFIX = 'PREFIX' # Mail subject will be "PREFIX subjecttext"
# global
PYSCADA = {
'mail_count_limit': 20, # number of mails per emailadress per day
}
# meta informations
#
PYSCADA_META = {
'name':'A SHORT NAME',
'description':'A SHORT DESCRIPTION',
}
# export properties
#
PYSCADA_EXPORT = {
'file_prefix':'PREFIX_',
'output_folder':'~/measurement_data_dumps',
}
PYSCADA_MODBUS = {
'polling_interval':5,
'recording_interval':5,
}
PYSCADA_SYSTEMSTAT = {
'polling_interval':5,
'recording_interval':5,
}
2.2. settings.py 11
PyScada Documentation, Release 0.6.17b2
Nginx Setup
after editing, enable the configuration and restart nginx, optionaly remove the default configuration
# debian
sudo ln -s /etc/nginx/sites-available/pyscada.conf /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
for Fedora you have to allow nginx to serve the static and media folder.
sudo chcon -Rt httpd_sys_content_t /var/www/pyscada/http/
13
PyScada Documentation, Release 0.6.17b2
Command-line
systemd:
systemctl start pyscada_daemon_name.service
systemd:
systemctl start gunicorn.service
15
PyScada Documentation, Release 0.6.17b2
16 Chapter 4. Command-line
CHAPTER 5
Features
17
PyScada Documentation, Release 0.6.17b2
18 Chapter 5. Features
CHAPTER 6
Dependencies
• core/HMI
– python 2.7
– django>=1.7
– numpy>=1.6.0
– pillow
– python-daemon
• ModbusMaster
– pymodbus>=1.2
• HDF5Export
– h5py>=2.1.1
• SystemStatistics
– psutil
• BACNet/IP
– bacpypes
19
PyScada Documentation, Release 0.6.17b2
20 Chapter 6. Dependencies
CHAPTER 7
Contribute
21
PyScada Documentation, Release 0.6.17b2
22 Chapter 7. Contribute
CHAPTER 8
License
The project is licensed under the _GNU General Public License v3 (GPLv3)_.
23