Package: scadaUtils
ScadaUtils V0.2DESCRIPTIONThis package contains utilities for :comUtils : to standardize the dumping of data from different devices(Modbus,Meteo,OPCUA) with a Streamer, SuperDumper_daily and VisualisationMaster_dailySimulators : to simulate the flow of data from devices(servers) from comUtilsutilsD : convenient plotly,pandas extensions to work fasterversionManagers : to deal with historical data folders and to make them compatible with the daily visualisation master.DASHBOARDfor your dashboard application to work with the standard dashboard template you need :instanciate an Dashboard application as in the example bellow:fromsylfenUtilsimportdashboarddash=dashboard.Dashboard(cfg,LOG_DIR,root_folder)cfg is a standard from ComUtils VisualisationMaster_daily object from comUtils.TUTORIALThere is a jupyter-notebook availablehereto learn how to dump realtime data from different modbus,opcua devices, and how to read them in realtime. A dashboard can also be usedpre-requisitespostgresSQLpostgressql server should be active running on port 5432(user:postgres,password:sylfenbdd) containing ajulesdatabase with arealtimedatatable(default settings).do not forget to cofnigure pg_hba.conf correctly.you change password of user postgres with :alteruser<postgres>password'<newpassword>';DEPLOYMENT AND PRODUCTIONCreate a file.service:[Unit]Description=dumpingdatafrom<my_project>After=network.target[Service]User=<user>Group=<group_user>WorkingDirectory=<your_path_to_job>/job/Environment="PATH=<your_virtual_env_path>/bin"ExecStart=<your_virtual_env_path>/bin/python<your_job>.py[Install]WantedBy=multi-user.targetMake a symbolic link of this file (or copy it) intosystemdfolder:cd /etc/systemd/system/
ln -s <your_service_path>REMARKS:of course the dumper can be manually started withpython job/<your_job>.py.systemctl commandstart :systemctl start <your_job>.servicestatus :systemctl status <your_job>.serviceenable(start at boot):systemctl enable <your_job>.servicestop :systemctl stop <your_job>.serviceServing dashboardTo serve the dashboard(from your virtual environment) just :python dashboard/dashboard_<your_project>.pyDashbaord in production environmment ==> GUNICORNTo serve the dashboard in a production environment(more reliable) you need to start it with gunicorn. The best is to create a file<your_dashboard>.servicewith following content:[Unit]Description=GunicorninstancetoservesmallpowerdashboardAfter=network.target[Service]User=<username>##theuserthatrunsthedashboardGroup=<group>##thegroupthatrunsthedashboardWorkingDirectory=<path>###pathofthedashboardapplicationEnvironment="PATH=<path_to_venv>"## the python environment usedExecStart=<path_gunicorn>-blocalhost:<port_dashboard>-w4dashboard_<your_project>:app## precise the full path where to find gunicorn in your venv and the port of the dashboard. You can also change -w which is the number of clients served simultaneously.[Install]WantedBy=multi-user.targetMake a symbolic link of this file (or copy it) intosystemdfolder:cd /etc/systemd/system/
ln -s <your_service_path><your_project>.serviceYou can start <your_project> service (this is to be done only once).sudo systemctl start <your_project>If you get this errorUnit <your_project>.service could not be found.do :systemctl daemon-reloadEnable the <your_project> dashboard service so that it automatically starts at boot:sudo systemctl enable <your_project>Check status, enabled status, and log activity with respectively:sudo systemctl status <your_project>systemctl list-unit-filesjournalctl | grep <your_project>If there are not any big error but the dashboard is not accessible, it means there is an error in the dashboard_<your_project>.py somewhere. Try to run in with flask : app.run(), check access and then with gunicorn ==><your_env>/gunicorn -b localhost:<port> dashboard_<your_project>:appLink a domain name to the website ==> NGINXIf you want to redirect the name of the url using your domain name you have to do a redirection of the port using nginx. Create a file <url_app>.conf virtual host file with following content:server{listen80;server_name<domainname><your_project>.sylfen.com<domainname>;location/{proxy_passhttp://127.0.0.1:<port_dashboard>;}}Make a symbolic link of this file (or copy it) intosites-availableandsites-enabledfolders:ln -s <your_<your_project>.conf_file> /etc/nginx/sites-available
ln -s <your_<your_project>.conf_file> /etc/nginx/sites-enabledREMARK :On a local network a switch can only redirect the port 80(default port for HTTP) and/or the port 443(default port for HTTPS) to one device on the network. This means that if the port is already forwarded to a machine different from yours, your website won't be accessible.if you still want to make test on your reverse proxy, you can force the redirection by editing/etc/hostsby adding a line  ==>     127.0.0.1   <your_domain_name>. Your browser will directly associate the domain_name to your machine and won't search on the internet.update your configurationTo take the modification of your configuration into account :sudo nginx -s reloadThis will reload all the configuration of the websites insites-available.GOOD PRACTICES :make tests on remote machineIn order no to corrupt and create bugs to a deployed version while trying to make some tests on remote machine, a good way is :to create another usergive him access to the data but make sure it can't modify them. Datafolder should be 775 permissions.clone the git project in a foldercreate a virtual environmment(as always) and install the library. You are ready to make tests safely!!!easy procedure to update the production environmentOnce you are done with you your tests and your are sure that the version is stable and not creating bugs you are ready for release it for users. Thenupdate(stabilize) the version of sylfenUtils and that of <your_project> with the sylfenUtils dependency.git push bothgit pull in the production folderinstall with pip in your .env environment virtual the new version and uninstall if necessary the sylfenUtils dependency before new installation.restart <your_project>.service to see the effect :systemctl restart <your_project>.servicecd <your_project>
git pull
source .env/bin/activate
pip uninstall sylfenUtils
pip install .
systemctl restart <your_project>.service