diff --git a/MotorControl/MotorServer.py b/MotorControl/MotorServer.py index c8d8686..c82240a 100755 --- a/MotorControl/MotorServer.py +++ b/MotorControl/MotorServer.py @@ -57,11 +57,20 @@ class MotorServicer(motorService_pb2_grpc.CarControlServicer): def start_server(self): server = grpc.server(futures.ThreadPoolExecutor(max_workers=8)) motorService_pb2_grpc.add_CarControlServicer_to_server(self, server) - server.add_insecure_port('[::]:50051') + server.add_secure_port('[::]:50051', self.create_credentials()) server.start() while True: time.sleep(60*60) + def create_credentials(self): + pvtKeyPath = '/home/pi/tls/device.key' + pvtCertPath = '/home/pi/tls/device.crt' + + pvtKeyBytes = open(pvtKeyPath).read() + pvtCertBytes = open(pvtCertPath).read() + + return grpc.ssl_channel_credentials(pvtCertBytes, pvtKeyBytes) + motor = Motor() servo = Servo(servo_pin) servicer = MotorServicer(motor, servo)