【发布时间】:2021-07-24 11:34:53
【问题描述】:
我正在安装在 Ubuntu hyper-v VM 上的 Azure IoT Edge 运行时上实现 API。 我在 Ubuntu vm 的边缘运行时中实现并运行了一个烧瓶 API 模块。 所以我需要从主机访问这个 API,这是我在 Windows 10 上运行的本地机器。运行的 API 模块的 IP 地址是http://172.20.36.197:5000/predict。
这适用于来宾(Ubuntu hyper-v VM)机器,但每次我尝试在主机中调用此调用时请求都会超时。我什至禁用了主机 VM 的防火墙。但没有运气。看来我必须从我的主机访问在 Ubuntu VM 上运行的 IoT Edge 运行时。
我只是在 docker 容器中运行相同的烧瓶 API,而不是在 IoT 边缘运行时作为边缘模块,而是在 Ubuntu Hyper-v VM 内的 docker 中运行,我可以从主机访问该 API,没有任何问题。以下是我在物联网边缘运行时运行的烧瓶 API 边缘模块的代码
import os
from azure.iot.device.aio import IoTHubModuleClient
from flask import Flask
port =int(os.environ.get("port",5000))
print("port is ",port)
# Initialize flask app
app = Flask(__name__)
# Create an endpoint
@app.route('/predict')
def predict_chiller_condition():
print("api func called")
predictedVal=3
return 'predicted value is '+str(predictedVal)
if __name__ == "__main__":
app.run(host='0.0.0.0',port=port)
【问题讨论】:
标签: python azure-iot-hub azure-iot-edge