Skip to content

How to run your code from Docker #52

Closed

Description

@Cram3r95

Hi,

I am trying to run your interface from Docker. iRacing is running in Windows 11.

With this code:

class iRacingPublisher:
    def __init__(self, host='localhost', port=5000):
        """
        Initializes the iRacing telemetry publisher with socket setup and iRacing startup.
        """
        self.host = host
        self.port = port
        self.ir = irsdk.IRSDK()
        self.ir.startup()
        self.last_time = 0

        # # Setup TCP connection
        # self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # self.sock.connect((self.host, self.port))

    def get_telemetry_data(self):
        """
        Retrieves telemetry data from iRacing and calculates necessary fields.
        Returns a dictionary of telemetry data.
        """
        self.ir.freeze_var_buffer_latest()

        telemetry_data = {
            "time_diff": self.ir['SessionTime'] - self.last_time,
            "GPS Speed": self.ir['Speed'],
            "gLat_Motec": self.ir['LatAccel'],
            "gLong_Motec": self.ir['LongAccel'],
            "steering_wheel_angle": self.ir['SteeringWheelAngle'],  # We need the derivative of this variable
            "RelativeVelocityY": self.ir['VelocityY'],              # Derive relative displacement from here
            "RelativeVelocityX": self.ir['VelocityX']
        }
        print("-------------")
        print("Telemetry data: ", telemetry_data)
        self.last_time = self.ir['SessionTime']
        return telemetry_data

    def send_telemetry_data(self, telemetry_data):
        """
        Encodes telemetry data as JSON and sends it through the socket.
        """
        data_to_send = json.dumps(telemetry_data).encode('utf-8')
        self.sock.sendall(data_to_send)

    def run(self):
        """
        Continuously retrieves telemetry data and sends it to the neural network.
        """
        try:
            while True:
                telemetry_data = self.get_telemetry_data()
                # self.send_telemetry_data(telemetry_data)
        except Exception as e:
            print(f"Error: {e}")
        finally:
            self.sock.close()

if __name__ == "__main__":
    # Initialize and run the iRacing publisher
    ir_publisher = iRacingPublisher(host='localhost', port=5000)
    ir_publisher.run()

I can see the data in Windows11, no issues. Nevertheless, is it possible to run the same code in WSL2 -> Docker?.

Activity

  1. Repository owner locked and limited conversation to collaborators on Oct 17, 2024
  2. converted this issue into a discussion #53 on Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions