Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to transmit Android real-time sensor data to computer?

I wish to transmit real-time sensor data collected by Android smartphone to my computer and do the signal process on my computer. How may I achieve that? Any helpful links to tutorials are very well welcomed.

Either by wireless means or USB cables is acceptable.

When the data are transmitted, how may the computer process them?

I am familiar with Python, and so perferrably use Python to deal with the coming data.

Is it possible for Python to continuously accept newly come data and process them?

like image 232
Sibbs Gambling Avatar asked Aug 15 '13 03:08

Sibbs Gambling


4 Answers

Some Android apps allow you to share the sensors via the network:

  • PhonePi (using websockets)
  • Sensor Node (via MQTT)
  • IP Webcam (can be used as a webapi by accessing http://SMARTPHONE_IP:8080/sensors.json)
  • Tasker publisher

You can also read the sensors via ADB!

like image 64
eadmaster Avatar answered Oct 03 '22 08:10

eadmaster


You could use python sockets to recieve the data and process it. Look at: https://docs.python.org/2/howto/sockets.html for some idea of how to setup the server machine.

Android has a compatible socket that you could use to send your data: Look at: http://examples.javacodegeeks.com/android/core/socket-core/android-socket-example/ for some ideas on how to use it.

Edit: This will work for wifi and 3g/4g.

like image 31
Jacob Sundqvist Avatar answered Oct 03 '22 08:10

Jacob Sundqvist


There exist multiple Android apps to transmit sensor data wirelessly. Checkout e.g. "Smartphone IMU GPS" [1], which is open-source [2]. It transmits the data via UDP. A Python code snippet to receive the data stream is given in the app description [1]. Make sure the smartphone as well as the receiving device are connected to the same WiFi network and no firewall blocks the traffic.

[1] https://play.google.com/store/apps/details?id=de.lorenz_fenster.sensorstreamgps
[2] https://sourceforge.net/projects/smartphone-imu/

like image 5
user1225999 Avatar answered Oct 03 '22 09:10

user1225999


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

like image 1
Umer Farooq Avatar answered Oct 03 '22 09:10

Umer Farooq