Hi,
Is it possible to send my telemetry data through a TCP/IP port (e.g. 5000). This is my code:
import irsdk
import time
import socket
import json
def main():
ir = irsdk.IRSDK()
# Socket setup
server_address = ('localhost', 5000) # Use 'localhost' for local communication, or replace with actual server IP
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(server_address)
sock.listen(1) # Listen for one connection at a time
print('Waiting for a connection...')
connection, client_address = sock.accept()
print(f'Connection established with {client_address}')
try:
# Keep trying to initialize iRacing SDK
while not ir.is_initialized:
try:
ir.startup()
time.sleep(1) # Wait before retrying if necessary
except ConnectionError as e:
print(f"Connection error: {e}")
time.sleep(5) # Wait before retrying if connection fails
# When connected, continuously read telemetry data and send it via the socket
while ir.is_initialized:
try:
# Collect telemetry data (example: Speed)
telemetry_data = {
'GPS Speed': ir['Speed'],
'gLat_Motec': ir['gLat'],
'gLong_Motec': ir['gLong'],
'steering_wheel_angle': ir['SteeringWheelAngle'],
'RelativeVelocityX': ir['VelocityX'],
'RelativeVelocityY': ir['VelocityY']
}
# Convert telemetry data to JSON and send through the socket
telemetry_json = json.dumps(telemetry_data)
connection.sendall(telemetry_json.encode('utf-8')) # Send data
time.sleep(0.1) # Adjust based on how frequently you want to send data
except Exception as e:
print(f"Error retrieving or sending data: {e}")
ir.shutdown()
time.sleep(5)
ir.startup()
except Exception as e:
print(f"An error occurred: {e}")
finally:
connection.close() # Close the connection when done
sock.close()
if __name__ == "__main__":
main()
I want to send this data so my neural network can process that input, but I get the following problem:
PS C:\AI_ForceFeedback\repos\nx-ai-racing> python .\interface\iRacing_interface_publisher.py
-------------
Telemetry data: {'time_diff': 1979.7833328232373, 'GPS Speed': 4.5618260628543794e-05, 'gLat_Motec': 0.4189244508743286, 'gLong_Motec': 0.31985414028167725, 'steering_wheel_angle': 3.7124199867248535, 'RelativeVelocityY': 1.4244534213503357e-05, 'RelativeVelocityX': 4.333726974437013e-05}
-------------
Telemetry data: {'time_diff': 0.01666666666665151, 'GPS Speed': 3.9262919017346576e-05, 'gLat_Motec': 0.42789262533187866, 'gLong_Motec': 0.3183833360671997, 'steering_wheel_angle': 3.7124199867248535, 'RelativeVelocityY': 1.9296350728836842e-05, 'RelativeVelocityX': 3.4193970350315794e-05}
Error: [WinError 10053] An established connection was aborted by the software in your host machine
Any particular reason?
Hi,
Is it possible to send my telemetry data through a TCP/IP port (e.g. 5000). This is my code:
I want to send this data so my neural network can process that input, but I get the following problem:
Any particular reason?