I have to make a DIY robot. In order to find out orientation of robot I am using my smartphone and PhonePi app. The app is based on Flask server. The code for getting orientation is given below and I named this one as orientation.py
:
from flask import Flask
from flask_sockets import Sockets
app = Flask(__name__)
sockets = Sockets(app)
@sockets.route('/orientation')
def echo_socket(ws):
while True:
message = ws.receive()
raw2 = message.split(',')
global orient1
orient1 = float(raw2[0])
orient2 = float(raw2[1])
orient3 = float(raw2[2])
print('x = ', orient1, "is", type(orient1))
# print('y = ', orient2, "is", type(orient2))
# print('z = ', orient3, "is", type(orient3))
ws.send(message)
@app.route('/')
def hello():
return 'Hello World!'
if __name__ == "__main__":
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
server = pywsgi.WSGIServer(('0.0.0.0', 5000), app, handler_class=WebSocketHandler)
server.serve_forever()
I have to access variable orient1 from another script named robot controller.py
. I tried to access variable several ways like:
from orientation import *
import orientation
from orientation import orient1
How can I access orient1 from other scripts within same folder?