You can use Sensor Server app from Github, which streams live sensor data to WebSocket clients.
To receive live sensor data from Android , you simply need to connect to the app using following URL
ws://ip:port/sensor/connect?type=<sensor-type>
where <sensor-type>
is the type of sensor you are connecting to. For example
For Accelerometer : /sensor/connect?type=android.sensor.accelerometer
For orientation : /sensor/connect?type=android.sensor.orientation
For gyroscope : /sensor/connect?type=android.sensor.gyroscope
and so on...
Almost every language provides implementation of Websocket protocol. To receive live data in Python script you can use WebSocket client for Python
import websocket
def on_message(ws, message):
print(message) # sensor data here in JSON format
def on_error(ws, error):
print("### error ###")
print(error)
def on_close(ws, close_code, reason):
print("### closed ###")
print("close code : ", close_code)
print("reason : ", reason )
def on_open(ws):
print("connection opened")
if __name__ == "__main__":
ws = websocket.WebSocketApp("ws://192.168.0.102:8082/sensor/connect?type=android.sensor.accelerometer",
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.run_forever()
Sensor Server app and Websocket client must be connected to the same network