导入的脚本没有响应

时间:2019-05-21 08:28:16

标签: python python-3.x flask coordinates

所以我有一个最终需要在网站上运行的python脚本,为此使用了flask,但是当我运行flask以查看locahost上的代码时,如果导入脚本则不会响应。

app.py

from flask import Flask
app = Flask(__name__)

import coords.py

@app.route("/")
def hello():
    return "Hello World!"
#this is the code for flask

下面是坐标脚本,需要在烧瓶中运行该脚本才能最终获得给我位置的脚本。但是,当我运行烧瓶时,这似乎不起作用,有人可以帮助我解决这个问题吗?

coords.py

#!/usr/bin/env python3

import time
import ttn
import struct
import binascii
import os

# add credentials here for your TTN app
app_id = "fipy-temp"
access_key = "ttn-account-v2.J8Ss46o2Xx4a7NaRR2flqAPv-y1kYq1HWEMaLoen2Uk"

def uplink_callback(msg, client): # handler for all incoming data
    hexified = binascii.a2b_base64(msg.payload_raw)
    tuplefied = struct.unpack("ii", hexified)
    stringified = [None, None]
    for index, data in enumerate(tuplefied):
        stringified[index] = data / 10000 # conversion from int to float
    print("Received uplink from {}.\n".format(msg.dev_id))
    print("Latitude:  {:<010}".format(stringified[0]))
    print("Longitude: {:<010}".format(stringified[1]))

handler = ttn.HandlerClient(app_id, access_key)

# mqtt client
mqtt_client = handler.data()
mqtt_client.set_uplink_callback(uplink_callback)
while True:
    try:
        mqtt_client.connect()
        time.sleep(30)
        mqtt_client.close()
    except (KeyboardInterrupt, SystemExit):
        print(os.path.basename(__file__), "interrupted, closing MQTT connection.")
        mqtt_client.close()
        break    

#this is the code for my coordinates that should be imported on flask.

然后,如果我使用$ FLASK_APP = coords.py烧瓶运行,则什么也没发生

0 个答案:

没有答案