Skip to content
Snippets Groups Projects
Commit 878bcefd authored by Kyrre Ness Sjobaek's avatar Kyrre Ness Sjobaek
Browse files

Adding logging script

parent c2e7e6e8
Branches
No related tags found
No related merge requests found
#! /usr/bin/env python3
#HOW TO USE THIS SCRIPT:
# run "python positionGaugeServer_logging.py ARDUINO_HOSTNAME_OR_IP | tee LOGFILE.TXT"
# This will connect to the given arduino,
# and continiously write a file "LOGFILE.TXT" (pick a sensible name!).
# Due to the use of "tee" it will also show the contents of this file while it is running.
import sys
if not len(sys.argv) == 2:
print ("Usage: ./positionGaugeServer_logging.py Arduino_hostname_or_IP")
exit(1);
IP = sys.argv[1]
import socket
BUFFER_SIZE = 1024
portX = 21
portY = 22
sockX = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockX.connect((IP,portX))
Xdata = None
Xbuff = b""
sockY = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockY.connect((IP,portY))
Ydata = None
Ybuff = b""
import datetime
#We will just assume that unit is in mm
print ("# Date Time X[mm] Y[mm]")
#Loop to recieve data
while True:
Xbuff += sockX.recv(BUFFER_SIZE)
#print("X:", Xbuff)
if Xbuff[-1] == b'\n'[0]:
if len(Xbuff) != 9:
#In the beginning we get two lines in a hurry.
#Skip'em.
Xbuff = b""
else:
#Strip off the \r\n and the unit
Xdata = str(Xbuff[:-4],'ascii')
Xbuff = b""
Ybuff += sockY.recv(BUFFER_SIZE)
#print("Y:", Ybuff)
if Ybuff[-1] == b'\n'[0]:
if len(Ybuff) > 9:
Ybuff = b""
else:
Ydata = str(Ybuff[:-4],'ascii')
Ybuff = b""
if Xdata != None and Ydata != None:
print(datetime.datetime.now(), Xdata, Ydata)
Xdata = None
Ydata = None
sockX.close()
sockY.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment