4 Commits

Author SHA1 Message Date
Patrick McDonagh
cf49309391 Moves files around 2016-12-06 17:13:15 -06:00
Patrick McDonagh
b0b964c45a also install hp_webserver.datalogger 2016-12-06 16:39:33 -06:00
Patrick McDonagh
5de541fc59 fix package importing for __init__.py 2016-12-06 16:33:56 -06:00
Patrick McDonagh
43f9ed378b changes app folder to hp_webserver to match package name 2016-12-06 16:26:44 -06:00
103 changed files with 54 additions and 97 deletions

1
.gitignore vendored
View File

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

View File

@@ -1,37 +0,0 @@
# 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,4 +1,5 @@
# app/__init__.py
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
@@ -8,17 +9,17 @@ from flask_sqlalchemy import SQLAlchemy
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'app', 'docs')
app = Flask('app', static_url_path='')
app = Flask('app', static_url_path='', static_folder="hp_webserver/static")
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 datalogger import views
from datalogger import api
from datalogger.models import *
from hp_webserver.datalogger import views
from hp_webserver.datalogger import api
from hp_webserver.datalogger.models import *

1
hp_webserver/__main__.py Normal file
View File

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

View File

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

View File

@@ -2,8 +2,8 @@ from pycomm.ab_comm.clx import Driver as ClxDriver
import traceback
import math
from app.datalogger.models import Device
from app import db
from hp_webserver.datalogger.models import Device
from hp_webserver 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 app import app, db
from app.datalogger.models import *
from app.datalogger.getDailyTotals import getTotals
from hp_webserver import app, db
from hp_webserver.datalogger.models import *
from hp_webserver.datalogger.getDailyTotals import getTotals
from pycomm_helper.utils import readTag, writeTag
from random import random
@@ -52,6 +52,7 @@ 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.datetime = Date.create(v.datetime + "Z", { fromUTC: true });
v.created_on = Date.create(v.created_on + "Z", { fromUTC: true });
return v;
});
deferred.resolve(vals);

View File

@@ -19,7 +19,6 @@ 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 app import app
# import ssl
from hp_webserver import app
import ssl
# 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')
def run_app():
app.run(host="0.0.0.0", debug=True, ssl_context='adhoc')
if __name__ == '__main__':
app.run(host="0.0.0.0", debug=True, ssl_context='adhoc')
run_app()

18
setup.py Normal file
View File

@@ -0,0 +1,18 @@
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,18 +1,20 @@
import sys
# the sqlalchemy db object
from app import db
from hp_webserver 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 app.datalogger.models import *
from hp_webserver.datalogger.models import *
def main():
def setupdb(seed=False):
# 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():
@@ -138,11 +140,15 @@ def seed():
db.session.commit()
if __name__ == '__main__':
main()
try:
if sys.argv[1] == "seed":
seed()
setupdb(seed=True)
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