Compare commits
No commits in common. "a67b3ef441c8486f194270b887f9bf63e8e043fd" and "b0ae19db23a2e1f8f86e3115cc06e206f401feb6" have entirely different histories.
a67b3ef441
...
b0ae19db23
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,5 +2,4 @@ venv
|
||||||
.idea
|
.idea
|
||||||
/test/clients.json
|
/test/clients.json
|
||||||
*.pyc
|
*.pyc
|
||||||
*.egg-info
|
*.egg-info
|
||||||
*.json
|
|
|
@ -1,9 +1,2 @@
|
||||||
paho-mqtt~=1.5.1
|
paho-mqtt~=1.5.1
|
||||||
setuptools~=50.3.1
|
setuptools~=50.3.1
|
||||||
pip~=20.2.3
|
|
||||||
Jinja2~=2.11.2
|
|
||||||
Werkzeug~=1.0.1
|
|
||||||
itsdangerous~=1.1.0
|
|
||||||
click~=7.1.2
|
|
||||||
MarkupSafe~=1.1.1
|
|
||||||
Flask~=1.1.2
|
|
11
setup.cfg
11
setup.cfg
|
@ -10,16 +10,7 @@ classifiers =
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
packages = find:
|
packages = find:
|
||||||
install_requires =
|
install_requires = paho-mqtt~=1.5.1
|
||||||
paho-mqtt~=1.5.1
|
|
||||||
setuptools~=50.3.1
|
|
||||||
pip~=20.2.3
|
|
||||||
Jinja2~=2.11.2
|
|
||||||
Werkzeug~=1.0.1
|
|
||||||
itsdangerous~=1.1.0
|
|
||||||
click~=7.1.2
|
|
||||||
MarkupSafe~=1.1.1
|
|
||||||
Flask~=1.1.2
|
|
||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts = torch-sub=torchsub.torch_sub:main
|
console_scripts = torch-sub=torchsub.torch_sub:main
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
##############################################################################
|
|
||||||
# Sample torch-sub.conf file
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
[mqtt]
|
|
||||||
#Topic is required
|
|
||||||
Topic=torch/+/wake
|
|
||||||
|
|
||||||
[database]
|
|
||||||
#Filename is optional and defaults to 'clients.json'
|
|
||||||
Filename=torch_clients.json
|
|
||||||
|
|
||||||
[web]
|
|
||||||
#Port is optional and defaults to 8080
|
|
||||||
Port=3434
|
|
|
@ -7,8 +7,6 @@ import threading
|
||||||
|
|
||||||
import paho.mqtt.subscribe as mqtt
|
import paho.mqtt.subscribe as mqtt
|
||||||
|
|
||||||
from torchsub import torch_sub_webserver
|
|
||||||
|
|
||||||
database_filename = "clients.json"
|
database_filename = "clients.json"
|
||||||
database_lock = threading.Lock()
|
database_lock = threading.Lock()
|
||||||
|
|
||||||
|
@ -17,6 +15,10 @@ database_lock = threading.Lock()
|
||||||
def update_client_record(client, userdata, message):
|
def update_client_record(client, userdata, message):
|
||||||
database_lock.acquire()
|
database_lock.acquire()
|
||||||
|
|
||||||
|
if not os.path.exists(database_filename):
|
||||||
|
with open(database_filename, 'w') as database_blank:
|
||||||
|
json.dump({}, database_blank)
|
||||||
|
|
||||||
with open(database_filename, 'r') as infile:
|
with open(database_filename, 'r') as infile:
|
||||||
database = json.load(infile)
|
database = json.load(infile)
|
||||||
|
|
||||||
|
@ -45,8 +47,6 @@ class Config:
|
||||||
self.broker_port = None
|
self.broker_port = None
|
||||||
self.topic = None
|
self.topic = None
|
||||||
self.tls = None
|
self.tls = None
|
||||||
self.database_file = database_filename
|
|
||||||
self.web_port = 8080
|
|
||||||
parser = self.do_cli_argument_parsing()
|
parser = self.do_cli_argument_parsing()
|
||||||
(config_path, config_filename) = self.get_config_path(parser.parse_args())
|
(config_path, config_filename) = self.get_config_path(parser.parse_args())
|
||||||
print("Using torch configuration path: " + config_path)
|
print("Using torch configuration path: " + config_path)
|
||||||
|
@ -98,26 +98,10 @@ class Config:
|
||||||
'certfile': cert_file,
|
'certfile': cert_file,
|
||||||
'keyfile': key_file
|
'keyfile': key_file
|
||||||
}
|
}
|
||||||
if config.has_section('database'):
|
|
||||||
self.database_file = config['database'].get('Filename', fallback=database_filename)
|
|
||||||
if config.has_section('web'):
|
|
||||||
self.web_port = config['web'].getint('Port', fallback=self.web_port)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
config = Config()
|
config = Config()
|
||||||
|
|
||||||
global database_filename
|
|
||||||
database_filename = config.database_file
|
|
||||||
|
|
||||||
if not os.path.exists(database_filename):
|
|
||||||
with open(database_filename, 'w') as database_blank:
|
|
||||||
json.dump({}, database_blank)
|
|
||||||
|
|
||||||
threading.Thread(target=torch_sub_webserver.app.run,
|
|
||||||
args=("localhost", config.web_port),
|
|
||||||
daemon=True).start()
|
|
||||||
|
|
||||||
subscribe(config.broker_hostname,
|
subscribe(config.broker_hostname,
|
||||||
config.broker_port,
|
config.broker_port,
|
||||||
config.topic,
|
config.topic,
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
from flask import Flask
|
|
||||||
|
|
||||||
from torchsub import torch_sub
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/clients', methods=['GET'])
|
|
||||||
def clients():
|
|
||||||
with open(torch_sub.database_filename, 'r') as database:
|
|
||||||
return app.response_class(
|
|
||||||
response=database.read(),
|
|
||||||
status=200,
|
|
||||||
mimetype='application/json'
|
|
||||||
)
|
|
Loading…
Reference in New Issue
Block a user