23 Commits

Author SHA1 Message Date
Kristjan Komlosi
ec8d3ca94c rename init to app change camel case to snake case, added __name__ conditional 2020-08-27 14:22:35 +02:00
Kristjan Komlosi
88687124f2 fixing packaging #1 2020-08-27 13:52:24 +02:00
Kristjan Komlosi
97233f27c3 fixing packaging #1 2020-08-27 11:14:01 +02:00
Kristjan Komlosi
b35aacad3f add travis config 2020-07-22 11:54:46 +02:00
Kristjan Komlosi
2136406a28 changed JS to match 1c49490 2020-07-14 11:12:43 +02:00
Kristjan Komlosi
ff13d8eeeb Add a semistandard badge to readme 2020-07-14 10:54:06 +02:00
Kristjan Komlosi
fece181c6f added an ESLint config file 2020-07-14 10:38:17 +02:00
Kristjan Komlosi
85d7be4117 refactor updateData to use simpler $.get method 2020-07-14 10:37:57 +02:00
Kristjan Komlosi
56e8282a82 specter --> spectrum 2020-07-14 10:02:18 +02:00
Kristjan Komlosi
1c4949020b change element IDs for irradiance values and table rows 2020-07-14 10:01:13 +02:00
Kristjan Komlosi
a71d8565c4 Change HTML indent to 4 2020-07-14 09:59:04 +02:00
Kristjan Komlosi
7e09a1e51f modify index.html into Jinja2 rendering template 2020-07-13 14:28:09 +02:00
Kristjan Komlosi
92fac02a9e formatting 2020-07-13 14:01:19 +02:00
Kristjan Komlosi
320bcae78e Merge branch 'development' of github.com:cls-02/TeraHz into developmen 2020-07-13 13:56:30 +02:00
Kristjan Komlosi
d6a0efd69b Merge branch 'development' of github.com:cls-02/TeraHz into development 2020-07-13 13:55:44 +02:00
Kristjan Komlosi
40a79af9af moved static files to conform with Flask 2020-07-13 13:54:30 +02:00
Kristjan Komlosi
229719cc5c moved static files to conform with Flask 2020-07-13 13:47:13 +02:00
Kristjan Komlosi
ac6345c5b5 modify gitignore 2020-07-13 13:42:08 +02:00
Kristjan Komlosi
7773788e20 Merge branch 'development' of github.com:cls-02/TeraHz into development 2020-07-13 13:28:36 +02:00
Kristjan Komlosi
ac154e6770 moved templates 2020-07-13 13:28:32 +02:00
Kristjan Komlosi
a4ec93f412 moved templates 2020-07-13 13:23:24 +02:00
Kristjan Komlosi
16d7624154 update copyright and add a root route 2020-07-13 13:13:01 +02:00
Kristjan Komlosi
54b93cb05c cleaning up 2020-07-13 13:11:10 +02:00
56 changed files with 387 additions and 276 deletions

5
.eslintrc Normal file
View File

@@ -0,0 +1,5 @@
parserOptions:
ecmaVersion: 2019
env:
browser: true
jquery: true

4
.gitignore vendored
View File

@@ -128,5 +128,5 @@ dmypy.json
# Pyre type checker # Pyre type checker
.pyre/ .pyre/
# Include frontend libraries though # Include frontend ibraries though
!/frontend/lib !terahz/templates/lib

1
.travis.yml Normal file
View File

@@ -0,0 +1 @@
language: python

15
Pipfile Normal file
View File

@@ -0,0 +1,15 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
flask = "*"
smbus2 = "*"
pyserial = "*"
pandas = "*"
[requires]
python_version = "3.8"

184
Pipfile.lock generated Normal file
View File

@@ -0,0 +1,184 @@
{
"_meta": {
"hash": {
"sha256": "7fb3ae0afbe0d0c2af92f618aa1c54442566daeb561480eee2c2a299f1c2bee7"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.8"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"click": {
"hashes": [
"sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a",
"sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"
],
"version": "==7.1.2"
},
"flask": {
"hashes": [
"sha256:4efa1ae2d7c9865af48986de8aeb8504bf32c7f3d6fdc9353d34b21f4b127060",
"sha256:8a4fdd8936eba2512e9c85df320a37e694c93945b33ef33c89946a340a238557"
],
"index": "pypi",
"version": "==1.1.2"
},
"itsdangerous": {
"hashes": [
"sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19",
"sha256:b12271b2047cb23eeb98c8b5622e2e5c5e9abd9784a153e9d8ef9cb4dd09d749"
],
"version": "==1.1.0"
},
"jinja2": {
"hashes": [
"sha256:89aab215427ef59c34ad58735269eb58b1a5808103067f7bb9d5836c651b3bb0",
"sha256:f0a4641d3cf955324a89c04f3d94663aa4d638abe8f733ecd3582848e1c37035"
],
"version": "==2.11.2"
},
"markupsafe": {
"hashes": [
"sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473",
"sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161",
"sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235",
"sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5",
"sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42",
"sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff",
"sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b",
"sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1",
"sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e",
"sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183",
"sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66",
"sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b",
"sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1",
"sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15",
"sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1",
"sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e",
"sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b",
"sha256:7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905",
"sha256:88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735",
"sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d",
"sha256:98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e",
"sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d",
"sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c",
"sha256:ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21",
"sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2",
"sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5",
"sha256:b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b",
"sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6",
"sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f",
"sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f",
"sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2",
"sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7",
"sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be"
],
"version": "==1.1.1"
},
"numpy": {
"hashes": [
"sha256:082f8d4dd69b6b688f64f509b91d482362124986d98dc7dc5f5e9f9b9c3bb983",
"sha256:1bc0145999e8cb8aed9d4e65dd8b139adf1919e521177f198529687dbf613065",
"sha256:309cbcfaa103fc9a33ec16d2d62569d541b79f828c382556ff072442226d1968",
"sha256:3673c8b2b29077f1b7b3a848794f8e11f401ba0b71c49fbd26fb40b71788b132",
"sha256:480fdd4dbda4dd6b638d3863da3be82873bba6d32d1fc12ea1b8486ac7b8d129",
"sha256:56ef7f56470c24bb67fb43dae442e946a6ce172f97c69f8d067ff8550cf782ff",
"sha256:5a936fd51049541d86ccdeef2833cc89a18e4d3808fe58a8abeb802665c5af93",
"sha256:5b6885c12784a27e957294b60f97e8b5b4174c7504665333c5e94fbf41ae5d6a",
"sha256:667c07063940e934287993366ad5f56766bc009017b4a0fe91dbd07960d0aba7",
"sha256:7ed448ff4eaffeb01094959b19cbaf998ecdee9ef9932381420d514e446601cd",
"sha256:8343bf67c72e09cfabfab55ad4a43ce3f6bf6e6ced7acf70f45ded9ebb425055",
"sha256:92feb989b47f83ebef246adabc7ff3b9a59ac30601c3f6819f8913458610bdcc",
"sha256:935c27ae2760c21cd7354402546f6be21d3d0c806fffe967f745d5f2de5005a7",
"sha256:aaf42a04b472d12515debc621c31cf16c215e332242e7a9f56403d814c744624",
"sha256:b12e639378c741add21fbffd16ba5ad25c0a1a17cf2b6fe4288feeb65144f35b",
"sha256:b1cca51512299841bf69add3b75361779962f9cee7d9ee3bb446d5982e925b69",
"sha256:b8456987b637232602ceb4d663cb34106f7eb780e247d51a260b84760fd8f491",
"sha256:b9792b0ac0130b277536ab8944e7b754c69560dac0415dd4b2dbd16b902c8954",
"sha256:c9591886fc9cbe5532d5df85cb8e0cc3b44ba8ce4367bd4cf1b93dc19713da72",
"sha256:cf1347450c0b7644ea142712619533553f02ef23f92f781312f6a3553d031fc7",
"sha256:de8b4a9b56255797cbddb93281ed92acbc510fb7b15df3f01bd28f46ebc4edae",
"sha256:e1b1dc0372f530f26a03578ac75d5e51b3868b9b76cd2facba4c9ee0eb252ab1",
"sha256:e45f8e981a0ab47103181773cc0a54e650b2aef8c7b6cd07405d0fa8d869444a",
"sha256:e4f6d3c53911a9d103d8ec9518190e52a8b945bab021745af4939cfc7c0d4a9e",
"sha256:ed8a311493cf5480a2ebc597d1e177231984c818a86875126cfd004241a73c3e",
"sha256:ef71a1d4fd4858596ae80ad1ec76404ad29701f8ca7cdcebc50300178db14dfc"
],
"version": "==1.19.1"
},
"pandas": {
"hashes": [
"sha256:01b1e536eb960822c5e6b58357cad8c4b492a336f4a5630bf0b598566462a578",
"sha256:0246c67cbaaaac8d25fed8d4cf2d8897bd858f0e540e8528a75281cee9ac516d",
"sha256:0366150fe8ee37ef89a45d3093e05026b5f895e42bbce3902ce3b6427f1b8471",
"sha256:16ae070c47474008769fc443ac765ffd88c3506b4a82966e7a605592978896f9",
"sha256:1acc2bd7fc95e5408a4456897c2c2a1ae7c6acefe108d90479ab6d98d34fcc3d",
"sha256:391db82ebeb886143b96b9c6c6166686c9a272d00020e4e39ad63b792542d9e2",
"sha256:41675323d4fcdd15abde068607cad150dfe17f7d32290ee128e5fea98442bd09",
"sha256:53328284a7bb046e2e885fd1b8c078bd896d7fc4575b915d4936f54984a2ba67",
"sha256:57c5f6be49259cde8e6f71c2bf240a26b071569cabc04c751358495d09419e56",
"sha256:84c101d0f7bbf0d9f1be9a2f29f6fcc12415442558d067164e50a56edfb732b4",
"sha256:88930c74f69e97b17703600233c0eaf1f4f4dd10c14633d522724c5c1b963ec4",
"sha256:8c9ec12c480c4d915e23ee9c8a2d8eba8509986f35f307771045c1294a2e5b73",
"sha256:a81c4bf9c59010aa3efddbb6b9fc84a9b76dc0b4da2c2c2d50f06a9ef6ac0004",
"sha256:d9644ac996149b2a51325d48d77e25c911e01aa6d39dc1b64be679cd71f683ec",
"sha256:e4b6c98f45695799990da328e6fd7d6187be32752ed64c2f22326ad66762d179",
"sha256:fe6f1623376b616e03d51f0dd95afd862cf9a33c18cf55ce0ed4bbe1c4444391"
],
"index": "pypi",
"version": "==1.1.1"
},
"pyserial": {
"hashes": [
"sha256:6e2d401fdee0eab996cf734e67773a0143b932772ca8b42451440cfed942c627",
"sha256:e0770fadba80c31013896c7e6ef703f72e7834965954a78e71a3049488d4d7d8"
],
"index": "pypi",
"version": "==3.4"
},
"python-dateutil": {
"hashes": [
"sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c",
"sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"
],
"version": "==2.8.1"
},
"pytz": {
"hashes": [
"sha256:a494d53b6d39c3c6e44c3bec237336e14305e4f29bbf800b599253057fbb79ed",
"sha256:c35965d010ce31b23eeb663ed3cc8c906275d6be1a34393a1d73a41febf4a048"
],
"version": "==2020.1"
},
"six": {
"hashes": [
"sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259",
"sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"
],
"version": "==1.15.0"
},
"smbus2": {
"hashes": [
"sha256:210e66eebe4d0b1fe836b3ec2751841942e1c4918c0b429b20a0e20a222228b4"
],
"index": "pypi",
"version": "==0.3.0"
},
"werkzeug": {
"hashes": [
"sha256:2de2a5db0baeae7b2d2664949077c2ac63fbd16d98da0ff71837f7d1dea3fd43",
"sha256:6c80b1e5ad3665290ea39320b91e1be1e0d5f60652b964a3070216de83d2e47c"
],
"version": "==1.0.1"
}
},
"develop": {}
}

View File

@@ -1,4 +1,5 @@
[![Documentation Status](https://readthedocs.org/projects/terahz/badge/?version=latest)](https://terahz.readthedocs.io/en/latest/?badge=latest) [![Documentation Status](https://readthedocs.org/projects/terahz/badge/?version=latest)](https://terahz.readthedocs.io/en/latest/?badge=latest)
[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square)](https://github.com/standard/semistandard)
# <img alt="TeraHz logo" src="docs/imgs/logo-sq.png" width="200px"> TeraHz # <img alt="TeraHz logo" src="docs/imgs/logo-sq.png" width="200px"> TeraHz
*Za slovensko različico se odpravite na <http://git.sckr-lab.tk/kristjank/TeraHz>* *Za slovensko različico se odpravite na <http://git.sckr-lab.tk/kristjank/TeraHz>*

View File

@@ -1,16 +0,0 @@
# app.py - main backend program
'''Main TeraHz backend program'''
# All code in this file is licensed under the ISC license, provided in LICENSE.txt
from flask import Flask, jsonify
import sensors
app = Flask(__name__)
@app.route('/data')
def sendData():
'''Responder function for /data route'''
s = sensors.Spectrometer(path='/dev/serial0')
u = sensors.UVSensor()
l = sensors.LxMeter()
response = jsonify([s.getData(), l.getData(), u.getABI()])
response.headers.add('Access-Control-Allow-Origin', '*')
return response

View File

@@ -1,4 +0,0 @@
#!/bin/bash
# run.sh - run the backend server
cd `dirname $0`
sudo gunicorn app:app -b 0.0.0.0:5000 &

View File

@@ -1,3 +0,0 @@
interface=wlan0
dhcp-range=192.168.1.10,192.168.1.100,255.255.255.0,24h
address=/terahz.site/192.168.1.1

View File

@@ -1,6 +0,0 @@
#!/bin/bash
# edit_ssid.sh - edits hostapd.conf and sets a MAC address-based SSID
cd `dirname $0`
ssid=`ip link | awk '/wlan0/ {getline; print $2}' | awk -v FS=':' '{printf("TeraHz_%s%s%s\n", $4, $5, $6)}'`
sed "/ssid=.*/s/ssid=.*/ssid=$ssid/" hostapd.conf > newconf
mv newconf hostapd.conf

View File

@@ -1,9 +0,0 @@
interface=wlan0
hw_mode=g
channel=8
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=TeraHz
wpa_passphrase=terahertz

View File

@@ -1,23 +0,0 @@
# install.sh - install TeraHz onto a Raspbian Lite instance
cd `dirname $0`
apt -y update
apt -y full-upgrade
apt install -y python3 python3-pip lighttpd dnsmasq hostapd libatlas-base-dev
pip3 install numpy pandas flask smbus2 pyserial gunicorn
cp -R hostapd/* /etc/hostapd/
chmod +rx /etc/hostapd/edit_ssid.sh
cp dnsmasq.conf /etc/
cp rc.local /etc/
chmod +rx /etc/rc.local
cp interfaces-terahz /etc/network/interfaces.d/
cp -R ../frontend/* /var/www/html/
mkdir -p /usr/local/lib/terahz
cp -R ../backend/* /usr/local/lib/terahz
systemctl unmask dnsmasq hostapd lighttpd
systemctl enable dnsmasq hostapd lighttpd

View File

@@ -1,3 +0,0 @@
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0

View File

@@ -1,16 +0,0 @@
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/etc/hostapd/edit_ssid.sh &
/usr/local/lib/terahz/run.sh &
sleep 3
service hostapd restart # restart hostapd to prevent a weird startup race condition

View File

@@ -1,173 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<link rel="stylesheet" href="lib/bootstrap.min.css">
<link rel="stylesheet" href="stylesheet.css">
<title>TeraHz</title>
<script src="lib/bootstrap.bundle.min.js"></script>
<script src="lib/jquery-3.4.1.min.js"></script>
<script src="lib/flot/jquery.flot.js"></script>
<script src="frontend.js"></script>
<script src="lib/flot/jquery.canvaswrapper.js"></script>
<script src="lib/flot/jquery.colorhelpers.js"></script>
<script src="lib/flot/jquery.flot.js"></script>
<script src="lib/flot/jquery.flot.saturated.js"></script>
<script src="lib/flot/jquery.flot.browser.js"></script>
<script src="lib/flot/jquery.flot.drawSeries.js"></script>
<script src="lib/flot/jquery.flot.uiConstants.js"></script>
</head>
<body>
<div class="container text-center">
<h1><img src="lib/logo-sq.png" height="64px">TeraHz</h1>
</div>
<div class="container">
<button id="update" onclick="updateData()" class="btn btn-primary">Get data</button>
<button id="download" class="btn btn-primary">Download</button>
<button id="debug" class="btn btn-danger">DEBUG</button>
</div>
<div class="container">
<div class="row">
<div class="col-sm">
<h4>Spectrogram</h4>
<div id="graph" style="height:480px;width:720px"></div>
</div>
<div class="col-sm">
<h4>Visible+IR spectrum</h4>
<table class="table table-dark table-sm" id="specter">
<thead class="thead-dark">
<tr>
<th>Band</th>
<th>Wavelength [nm]</th>
<th>Irradiance [μW/cm²]</th>
</tr>
</thead>
<tr>
<td>A</td>
<td>410 nm</td>
<td id="A">---</td>
</tr>
<tr>
<td>B</td>
<td>435 nm</td>
<td id="B">---</td>
</tr>
<tr>
<td>C</td>
<td>460 nm</td>
<td id="C">---</td>
</tr>
<tr>
<td>D</td>
<td>485 nm</td>
<td id="D">---</td>
</tr>
<tr>
<td>E</td>
<td>510 nm</td>
<td id="E">---</td>
</tr>
<tr>
<td>F</td>
<td>535 nm</td>
<td id="F">---</td>
</tr>
<tr>
<td>G</td>
<td>560 nm</td>
<td id="G">---</td>
</tr>
<tr>
<td>H</td>
<td>585 nm</td>
<td id="H">---</td>
</tr>
<tr>
<td>R</td>
<td>610 nm</td>
<td id="R">---</td>
</tr>
<tr>
<td>I</td>
<td>645 nm</td>
<td id="I">---</td>
</tr>
<tr>
<td>S</td>
<td>680 nm</td>
<td id="S">---</td>
</tr>
<tr>
<td>J</td>
<td>705 nm</td>
<td id="J">---</td>
</tr>
<tr>
<td>T</td>
<td>730 nm</td>
<td id="T">---</td>
</tr>
<tr>
<td>U</td>
<td>760 nm</td>
<td id="U">---</td>
</tr>
<tr class="table-secondary">
<td>V</td>
<td>810 nm</td>
<td id="V">---</td>
</tr>
<tr class="table-secondary">
<td>W</td>
<td>860 nm</td>
<td id="W">---</td>
</tr>
<tr class="table-secondary">
<td>K</td>
<td>900 nm</td>
<td id="K">---</td>
</tr>
<tr class="table-secondary">
<td>L</td>
<td>940 nm</td>
<td id="L">---</td>
</tr>
</table>
</div>
<div class="col-sm">
<h4>UV+Illuminance</h4>
<table class="table-dark table table-sm" id="luxuv">
<thead class="thead-dark">
<tr>
<th>Parameter</th>
<th>Value</th>
</tr>
</thead>
<tr>
<td>Illuminance [lx]</td>
<td id="lx">---</td>
</tr>
<tr>
<td>UVA irradiance [μW/cm²]</td>
<td id="uva">---</td>
</tr>
<tr>
<td>UVB irradiance [μW/cm²]</td>
<td id="uvb">---</td>
</tr>
<tr>
<td>UVA/UVB average [μW/cm²]</td>
<td id="uvi">---</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

22
setup.py Normal file
View File

@@ -0,0 +1,22 @@
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="terahz", # Replace with your own username
version="1.0.0",
author="Kristjan Komloši",
author_email="kristjan.komlosi@gmail.com",
description="Low cost spectrometry webapp",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/cls-02/TeraHz",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)

46
terahz/app.py Normal file
View File

@@ -0,0 +1,46 @@
# app.py - main backend program
'''Main TeraHz backend program'''
# All code in this file is licensed under the ISC license, provided in LICENSE.txt
from flask import Flask, jsonify, render_template
from . import terahz
def start_flaskapp():
'''Initialize global variables'''
global app, s, u, l
app = Flask(__name__)
s = terahz.Spectrometer(path='/dev/serial0')
u = terahz.UVSensor()
l = terahz.LxMeter()
@app.route('/data')
def sendData():
'''Responder function for /data route'''
response = jsonify([s.getData(), l.getData(), u.getABI()])
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route('/')
def renderTable():
''''Main page renderer'''
wavelengthDict = {
'A': '410 nm',
'B': '435 nm',
'C': '460 nm',
'D': '485 nm',
'E': '510 nm',
'F': '535 nm',
'G': '560 nm',
'H': '585 nm',
'R': '610 nm',
'I': '645 nm',
'S': '680 nm',
'J': '705 nm',
'T': '730 nm',
'U': '760 nm',
'V': '810 nm',
'W': '860 nm',
'K': '900 nm',
'L': '940 nm'}
data = [s.getData(), l.getData(), u.getABI()]
return render_template('index.html', data=data, wavelengths=wavelengthDict)

View File

@@ -3,15 +3,12 @@ $('#update').click(updateData);
// jQuery event binder // jQuery event binder
function updateData () { function updateData () {
const url = 'http://' + window.location.hostname + ':5000/data'; const url = '/data';
$.ajax({ // spawn an AJAX request $.get(url, (data, status) => {
url: url, if (status === '200') {
success: function (data, status) {
console.log(data);
graphSpectralData(data[0], 0); graphSpectralData(data[0], 0);
fillTableData(data); fillTableData(data);
}, } else alert('Data request failed, please refresh page.');
timeout: 2500 // this should be a pretty sane timeout
}); });
} }
@@ -19,12 +16,13 @@ function graphSpectralData (obj, dom) {
// graph spectral data in obj into dom // graph spectral data in obj into dom
var graphPoints = []; var graphPoints = [];
var graphXTicks = []; var graphXTicks = [];
const spectrum = 'ABCDEFGHRISJTUVWKL';
const specter = 'ABCDEFGHRISJTUVWKL'; for (var i = 0; i < spectrum.length; i++) {
for (var i = 0; i < specter.length; i++) { graphPoints.push([i, obj[spectrum[i]]]);
graphPoints.push([i, obj[specter[i]]]); graphXTicks.push([i, spectrum[i]]);
graphXTicks.push([i, specter[i]]);
} }
const options = { const options = {
grid: { color: 'white' }, grid: { color: 'white' },
xaxis: { ticks: graphXTicks } xaxis: { ticks: graphXTicks }
@@ -35,8 +33,8 @@ function graphSpectralData (obj, dom) {
function fillTableData (obj) { function fillTableData (obj) {
// fill the obj data into HTML tables // fill the obj data into HTML tables
Object.keys(obj[0]) Object.keys(obj[0]).forEach((element) =>
.forEach((element) => { $('#' + element).text(obj[0][element]); }); { $('#' + element + '_value').text(obj[0][element]); });
$('#lx').text(obj[1]); $('#lx').text(obj[1]);
$('#uva').text(obj[2][0]); $('#uva').text(obj[2][0]);
$('#uvb').text(obj[2][1]); $('#uvb').text(obj[2][1]);

View File

Before

Width:  |  Height:  |  Size: 136 KiB

After

Width:  |  Height:  |  Size: 136 KiB

View File

@@ -0,0 +1,98 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<link rel="stylesheet" href="static/bootstrap.min.css">
<link rel="stylesheet" href="static/stylesheet.css">
<title>TeraHz</title>
<!-- script imports -->
<script src="static/bootstrap.bundle.min.js"></script>
<script src="static/jquery-3.4.1.min.js"></script>
<script src="static/flot/jquery.flot.js"></script>
<script src="static/frontend.js"></script>
<script src="static/flot/jquery.canvaswrapper.js"></script>
<script src="static/flot/jquery.colorhelpers.js"></script>
<script src="static/flot/jquery.flot.js"></script>
<script src="static/flot/jquery.flot.saturated.js"></script>
<script src="static/flot/jquery.flot.browser.js"></script>
<script src="static/flot/jquery.flot.drawSeries.js"></script>
<script src="static/flot/jquery.flot.uiConstants.js"></script>
</head>
<body>
<div class="container text-center">
<h1><img src="static/logo-sq.png" height="64px">TeraHz</h1>
</div>
<div class="container">
<button id="update" onclick="updateData()" class="btn btn-primary">Get data</button>
<button id="download" class="btn btn-primary">Download</button>
<button id="debug" class="btn btn-danger">DEBUG</button>
</div>
<div class="container">
<div class="row">
<div class="col-sm">
<h4>Spectrogram</h4>
<div id="graph" style="height:480px;width:720px"></div>
</div>
<div class="col-sm">
<h4>Visible+IR spectrum</h4>
<table class="table table-dark table-sm" id="specter">
<thead class="thead-dark">
<tr>
<th>Band</th>
<th>Wavelength [nm]</th>
<th>Irradiance [μW/cm²]</th>
</tr>
</thead>
{% for band, irr in data[0] %}
<tr id="{{band}}">
<td>
{{band}}
</td>
<td>
{{wld[band]}}
</td>
<td id="{{band}}_value">
{{irr}}
</td>
</tr>
{% endfor %}
</table>
</div>
<div class="col-sm">
<h4>UV+Illuminance</h4>
<table class="table-dark table table-sm" id="luxuv">
<thead class="thead-dark">
<tr>
<th>Parameter</th>
<th>Value</th>
</tr>
</thead>
<tr>
<td>Illuminance [lx]</td>
<td id="lx">{{data[1]}}</td>
</tr>
<tr>
<td>UVA irradiance [μW/cm²]</td>
<td id="uva">{{data[2][0]}}</td>
</tr>
<tr>
<td>UVB irradiance [μW/cm²]</td>
<td id="uvb">{{data[2][1]}}</td>
</tr>
<tr>
<td>UVA/UVB average [μW/cm²]</td>
<td id="uvi">{{data[2][2]}}</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>

View File

@@ -1,15 +1,11 @@
# sensors.py - a module for interfacing to the sensors # terahz.py - a module for interfacing to the sensors
'''Module for interfacing with TeraHz sensors''' '''Module for interfacing with TeraHz sensors'''
# Copyright 2019 Kristjan Komloši # Copyright 2019, 2020 Kristjan Komloši
# All code in this file is licensed under the ISC license, provided in LICENSE.txt # All code in this file is licensed under the ISC license, provided in LICENSE.txt
import serial as ser import serial as ser
import pandas as pd import pandas as pd
import smbus2 import smbus2
class Spectrometer: class Spectrometer:
'''Class representing the AS7265X specrometer''' '''Class representing the AS7265X specrometer'''