6 Commits

Author SHA1 Message Date
Patrick McDonagh
c8c7e4d59c Adds Webserver service 2017-05-25 15:05:28 -05:00
Patrick McDonagh
4a8d440bae Adds more detail to README, adds service_identity module to pip requirements 2017-02-09 16:38:39 -06:00
Patrick McDonagh
18bc2937b5 README.md edited online with Bitbucket 2017-02-07 20:02:33 +00:00
Patrick McDonagh
aef753a3e8 README.md edited online with Bitbucket 2017-02-07 20:01:19 +00:00
Patrick McDonagh
e751540ee6 Final fix for POCONSOLE-78 2016-12-06 17:34:52 -06:00
Patrick McDonagh
4305685acb force adding /root/www to python path before running 2016-12-06 17:15:41 -06:00
103 changed files with 97 additions and 54 deletions

1
.gitignore vendored
View File

@@ -5,4 +5,3 @@ sails/.tmp
.remote-sync.json
database.db
venv/
Henry_Pump_WebServer.egg-info/

37
README.md Normal file
View File

@@ -0,0 +1,37 @@
# Henry Pump Datalogger Website #
## Installation ##
### Prerequisites ###
- Set the FQDN for your device in /etc/hosts
```
127.0.0.1 device.company.poconsole.net device
```
```
#!bash
sudo apt-get install build-essential python-dev libssl-dev libffi-dev python-pip
pip install -r requirements.txt
```
- Install the [pycomm](https://github.com/ruscito/pycomm) module for python
- Install the [pycomm-helper](https://github.com/Henry-Pump/Pycomm-Helper) module for python
### DataLogger Website ###
```
#!bash
chmod +x start.sh webserver.sh renew_certs.sh
sudo cp webserver.sh /etc/init.d/webserver
sudo update-rc.d webserver defaults
```
### Database Setup ###
To set up the database and seed the POC tag data into the database run:
```
#!bash
python setupdb.py seed
```

View File

@@ -1,5 +1,4 @@
# app/__init__.py
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
@@ -9,17 +8,17 @@ from flask_sqlalchemy import SQLAlchemy
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'app', 'docs')
app = Flask('app', static_url_path='', static_folder="hp_webserver/static")
app = Flask('app', static_url_path='')
app.config.update(
DEBUG=True,
# SQLALCHEMY_DATABASE_URI='mysql+mysqlconnector://website:henrypump@127.0.0.1/poconsole'
SQLALCHEMY_DATABASE_URI='sqlite:///./database.db',
SQLALCHEMY_DATABASE_URI='sqlite:///../database.db',
)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
app.secret_key = 'henry_pump'
db = SQLAlchemy(app)
from hp_webserver.datalogger import views
from hp_webserver.datalogger import api
from hp_webserver.datalogger.models import *
from datalogger import views
from datalogger import api
from datalogger.models import *

View File

@@ -2,8 +2,8 @@ from pycomm.ab_comm.clx import Driver as ClxDriver
import traceback
import math
from hp_webserver.datalogger.models import Device
from hp_webserver import db
from app.datalogger.models import Device
from app import db
def getMainPLC():

View File

@@ -7,9 +7,9 @@ from sqlalchemy import and_, desc
from sqlalchemy.sql import func
from datetime import datetime
from hp_webserver import app, db
from hp_webserver.datalogger.models import *
from hp_webserver.datalogger.getDailyTotals import getTotals
from app import app, db
from app.datalogger.models import *
from app.datalogger.getDailyTotals import getTotals
from pycomm_helper.utils import readTag, writeTag
from random import random
@@ -52,7 +52,6 @@ def tagsattime_to_obj(tup):
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
print("caught something!")
return app.send_static_file('index.html')

View File

Before

Width:  |  Height:  |  Size: 357 KiB

After

Width:  |  Height:  |  Size: 357 KiB

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 130 KiB

View File

@@ -53,7 +53,7 @@ poconsole.factory('Tag',function($q, $http, $log, dateConversion){
var deferred = $q.defer();
$http.get('/api/latest').success(function(data) {
var vals = data.map(function(v){
v.created_on = Date.create(v.created_on + "Z", { fromUTC: true });
v.datetime = Date.create(v.datetime + "Z", { fromUTC: true });
return v;
});
deferred.resolve(vals);

View File

@@ -1 +0,0 @@
print("MAIN IN hp_datalogger")

View File

@@ -1 +0,0 @@
print("THIS IS THE MAIN FROM datalogger")

View File

@@ -19,6 +19,7 @@ pyOpenSSL==16.2.0
python-dateutil==2.6.0
python-mimeparse==1.6.0
requests==2.12.1
service_identity=16.0.0
six==1.10.0
SQLAlchemy==1.1.4
Twisted==16.6.0

10
run.py
View File

@@ -1,8 +1,8 @@
from hp_webserver import app
import ssl
from app import app
# import ssl
def run_app():
app.run(host="0.0.0.0", debug=True, ssl_context='adhoc')
# context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2)
# context.load_cert_chain('/Users/patrickjmcd/Henry_Pump/tagserver/web_db/flask/app/hplumberjack.crt', '/Users/patrickjmcd/Henry_Pump/tagserver/web_db/flask/app/hplumberjack.key')
if __name__ == '__main__':
run_app()
app.run(host="0.0.0.0", debug=True, ssl_context='adhoc')

View File

@@ -1,18 +0,0 @@
from setuptools import setup
setup(
name='Henry Pump WebServer',
version='2.0',
long_description=__doc__,
packages=['hp_webserver', 'hp_webserver.datalogger'],
include_package_data=True,
zip_safe=False,
install_requires=[
'Flask>=0.11.1',
'Flask-Restless>=0.17.0',
'Flask-SQLAlchemy>=2.1',
'pyOpenSSL>=16.2.0',
'requests>=2.12.1',
'Twisted>=16.6.0',
]
)

View File

@@ -1,20 +1,18 @@
import sys
# the sqlalchemy db object
from hp_webserver import db
from app import db
# we have to import the models so that sqlalchemy can detect them and create the db
# how else would it know what to create ?
from hp_webserver.datalogger.models import *
from app.datalogger.models import *
def setupdb(seed=False):
def main():
# creates the database
db.create_all()
# after the last command you should now be able to see database.db file
# in the project folder
if seed:
seed()
def seed():
@@ -140,15 +138,11 @@ def seed():
db.session.commit()
if __name__ == '__main__':
main()
try:
if sys.argv[1] == "seed":
setupdb(seed=True)
seed()
print("Created database.db file and seeded data.")
else:
setupdb()
except Exception as e:
setupdb()
print("Created database.db file. To seed data, run 'python setupdb.py seed'")

Some files were not shown because too many files have changed in this diff Show More