Add credentials and secure port to motor server.
This commit is contained in:
@@ -57,11 +57,20 @@ class MotorServicer(motorService_pb2_grpc.CarControlServicer):
|
|||||||
def start_server(self):
|
def start_server(self):
|
||||||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=8))
|
server = grpc.server(futures.ThreadPoolExecutor(max_workers=8))
|
||||||
motorService_pb2_grpc.add_CarControlServicer_to_server(self, server)
|
motorService_pb2_grpc.add_CarControlServicer_to_server(self, server)
|
||||||
server.add_insecure_port('[::]:50051')
|
server.add_secure_port('[::]:50051', self.create_credentials())
|
||||||
server.start()
|
server.start()
|
||||||
while True:
|
while True:
|
||||||
time.sleep(60*60)
|
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()
|
motor = Motor()
|
||||||
servo = Servo(servo_pin)
|
servo = Servo(servo_pin)
|
||||||
servicer = MotorServicer(motor, servo)
|
servicer = MotorServicer(motor, servo)
|
||||||
|
|||||||
Reference in New Issue
Block a user