server
parent
338e76a90b
commit
72fa6974a3
10
config.py
10
config.py
|
@ -0,0 +1,10 @@
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
debug = os.getenv("DEBUG")
|
||||||
|
robot_control_server_url = os.getenv("ROBOT_CONTROL_SERVER_URL")
|
||||||
|
robot_id = os.getenv("ROBOT_ID")
|
||||||
|
robot_type = int(os.getenv("ROBOT_TYPE"))
|
||||||
|
robot_firmware_version = os.getenv("ROBOT_FIRMWARE_VERSION")
|
49
main.py
49
main.py
|
@ -0,0 +1,49 @@
|
||||||
|
import requests
|
||||||
|
import logging
|
||||||
|
from fastapi import FastAPI
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG if config.debug ==
|
||||||
|
"true" else logging.INFO)
|
||||||
|
|
||||||
|
print(config.robot_control_server_url)
|
||||||
|
|
||||||
|
|
||||||
|
def InitRobot():
|
||||||
|
logging.info("InitRobot")
|
||||||
|
|
||||||
|
res = requests.post(config.robot_control_server_url + "/robot", json={
|
||||||
|
"id": config.robot_id,
|
||||||
|
"type": config.robot_type,
|
||||||
|
"firmwareVersion": config.robot_firmware_version
|
||||||
|
})
|
||||||
|
|
||||||
|
logging.info(res.status_code)
|
||||||
|
|
||||||
|
if res.status_code == 403:
|
||||||
|
logging.error("Permit join is disabled")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
async def root():
|
||||||
|
return {"message": "Hello World"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/v1/ping")
|
||||||
|
async def ping():
|
||||||
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
logging.info("main")
|
||||||
|
|
||||||
|
InitRobot()
|
||||||
|
|
||||||
|
uvicorn.run(app, port=5000)
|
Loading…
Reference in New Issue