I am getting three types of sensor data from mobile(Accelerometer,Gyroscope and Magnetic field) with the following code (pretty bad as I am just beginning with python, but they are working anyhow :) ).
import socket, traceback
host = ''
port = 5555
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.bind((host, port))
#used for debugging
count=0
print("Success binding")
while count<10:
message, address = s.recvfrom(5555)
messageString = message.decode("utf-8")
print(messageString)
count=count+1
with open('yourfile.csv','a') as f:
f.write(messageString)
f.close()
However the output I am getting in the csv file is like this--
205729.68706, 3, 0.464, -0.425, 9.903, 4, -0.000, 0.001, -0.000, 5, 36.290, 4.707,-24.930205729.88997, 3, 0.443, -0.433, 9.885, 4, -0.000, 0.001, 0.000205730.09288, 3, 0.465, -0.446, 9.894, 4, -0.000, -0.000, -0.000, 5, 37.206, 5.412,-24.298205730.29576, 3, 0.468, -0.432, 9.897, 4, -0.000, -0.000, -0.000, 5, 36.308, 5.411,-25.554205730.49867, 3, 0.442, -0.424, 9.883, 4, 0.000, 0.000, -0.000, 5, 36.868, 4.611,-26.465205730.70155, 3, 0.467, -0.444, 9.888, 4, -0.000, 0.000, -0.000, 5, 37.498, 5.637,-25.841205730.90446, 3, 0.464, -0.435, 9.904, 4, -0.001, 0.000, -0.000, 5, 36.301, 5.049,-24.931205731.10734, 3, 0.440, -0.432, 9.876, 4, -0.000, -0.000, -0.000, 5, 36.308, 5.605,-26.483205731.31026, 3, 0.460, -0.440, 9.906, 4, -0.000, 0.000, 0.000, 5, 35.706, 5.025,-24.944205731.51317, 3, 0.458, -0.434, 9.909, 4, 0.000, 0.000, -0.000, 5, 35.374, 4.218,-26.492
Where the first big number is the timestamp, 3,4,5 are the sensor ids followed by their x,y,z co-ordinate values. Now this raw data need to be grouped in tabular format by their sensor ids for each time stamp. A meaningful column header will be excellent if it does not require complex coding. I am trying to give a sample below--
I have installed veryprettytable from Github but the code or implementation is beyond my python knowledge. Please help. I am using python 3.27 latest (June 2018) on windows 10.