-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (38 loc) · 1.35 KB
/
main.py
File metadata and controls
57 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import logging
import json
from threading import Thread
from time import sleep
from flask import Flask, render_template
from scripts.logger import MyHandler
from scripts.YuboxInfluxDb import YuboxInfluxDb
from scripts.YuboxChirpStack import getGatewayChirpStack
from scripts.YuboxMapLora import createHtmlMapLora
# Configuro el logger
log = logging.getLogger('root')
log.setLevel('DEBUG')
log.addHandler(MyHandler())
app = Flask(__name__)
@app.route("/")
def home_map():
return render_template("mapa.html")
def ThreadUpdateMap(InfluxDb,gateways):
while(True):
print("Actualizando Mapa")
createHtmlMapLora(InfluxDb, gateways)
sleep(60)
if __name__ == "__main__":
# Cargo el archivo Json
jsonConfig = json.load(open("scripts/setup.json"))
# Creo la base de Datos
jsonInfluxDb = jsonConfig["InfluxDb"]
urlInfluxDb = jsonInfluxDb["url"]
tokenInfluxDb = jsonInfluxDb["token"]
InfluxDb = YuboxInfluxDb(url=urlInfluxDb, jsonToken = tokenInfluxDb)
# Obtengo los gateways
jsonChirpStack = jsonConfig["ChirpStack"]
urlChirpStack = jsonChirpStack["url"]
tokenChirpStack = jsonChirpStack["token"]
gateways = getGatewayChirpStack(url = urlChirpStack, token = tokenChirpStack)
Thread(target=ThreadUpdateMap, daemon=True, args=(InfluxDb,gateways,)).start()
# Inicio el APP
app.run()