Compare commits
4 Commits
master
...
POCONSOLE-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf49309391 | ||
|
|
b0b964c45a | ||
|
|
5de541fc59 | ||
|
|
43f9ed378b |
1
.gitignore
vendored
@@ -5,3 +5,4 @@ sails/.tmp
|
||||
.remote-sync.json
|
||||
database.db
|
||||
venv/
|
||||
Henry_Pump_WebServer.egg-info/
|
||||
|
||||
37
README.md
@@ -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
|
||||
```
|
||||
@@ -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
@@ -0,0 +1 @@
|
||||
print("MAIN IN hp_datalogger")
|
||||
1
hp_webserver/datalogger/__main__.py
Normal file
@@ -0,0 +1 @@
|
||||
print("THIS IS THE MAIN FROM datalogger")
|
||||
@@ -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():
|
||||
@@ -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')
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 357 KiB After Width: | Height: | Size: 357 KiB |
0
app/static/images/icons/_blank.png → hp_webserver/static/images/icons/_blank.png
Executable file → Normal file
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
0
app/static/images/icons/_page.png → hp_webserver/static/images/icons/_page.png
Executable file → Normal file
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
0
app/static/images/icons/doc.png → hp_webserver/static/images/icons/doc.png
Executable file → Normal file
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
0
app/static/images/icons/gif.png → hp_webserver/static/images/icons/gif.png
Executable file → Normal file
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
0
app/static/images/icons/jpg.png → hp_webserver/static/images/icons/jpg.png
Executable file → Normal file
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
0
app/static/images/icons/pdf.png → hp_webserver/static/images/icons/pdf.png
Executable file → Normal file
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
0
app/static/images/icons/png.png → hp_webserver/static/images/icons/png.png
Executable file → Normal file
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
0
app/static/images/icons/txt.png → hp_webserver/static/images/icons/txt.png
Executable file → Normal file
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.2 KiB |
0
app/static/images/icons/xls.png → hp_webserver/static/images/icons/xls.png
Executable file → Normal file
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
0
app/static/images/icons/xlsx.png → hp_webserver/static/images/icons/xlsx.png
Executable file → Normal file
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
0
app/static/images/icons/zip.png → hp_webserver/static/images/icons/zip.png
Executable file → Normal file
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 130 KiB |
@@ -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);
|
||||
@@ -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
@@ -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
@@ -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',
|
||||
]
|
||||
)
|
||||
16
setupdb.py
@@ -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'")
|
||||
|
||||