Skip to content

Instantly share code, notes, and snippets.

@lucabelluccini
Created January 4, 2017 18:47
Show Gist options
  • Select an option

  • Save lucabelluccini/c57051db06cdc9d3d16a8780fedc5e8e to your computer and use it in GitHub Desktop.

Select an option

Save lucabelluccini/c57051db06cdc9d3d16a8780fedc5e8e to your computer and use it in GitHub Desktop.
HyperIMU UDP Receiver
# Tested on Python 3.5
# Requires https://play.google.com/store/apps/details?id=com.ianovir.hyper_imu
# A stripped down version of https://github.com/ianovir/HIMUServer
import socketserver
import datetime
class TheUDPHandler(socketserver.BaseRequestHandler):
def _handle_data(self, client_address, data):
print("{} wrote: {}".format(client_address, data))
def handle(self):
data = self.request[0].strip()
self._handle_data(data, self.client_address[0])
class HyperIMUHandler(TheUDPHandler):
def _handle_data(self, data, client_address):
timestamp, acc_x, acc_y, acc_z, gyr_x, gyr_y, gyr_z, mag_x, mag_y, mag_z = eval(data[:-1])
print( datetime.datetime.fromtimestamp(
timestamp/1000.0
).strftime('%Y-%m-%d %H:%M:%S.%f'), acc_x, acc_y, acc_z, gyr_x, gyr_y, gyr_z, mag_x, mag_y, mag_z)
if __name__ == "__main__":
HOST, PORT = "0.0.0.0", 5555
server = socketserver.UDPServer((HOST, PORT), HyperIMUHandler)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment