def main(): print("Calling gRPC Service") #need to download .crt from browser, every connection is forced to be secure by protocol, with open("localhost.pem", "rb") as file: cert = file.read() credentials = grpc.ssl_channel_credentials(cert) channel = grpc.secure_channel("localhost:5001", credentials) stub = MeterReaderService.MeterReadingServiceStub(channel) request = MeterReader.ReadingPacket(successful = Enum.ReadingStatus.Success) now = Timestamp() now.GetCurrentTime() x = random.randint(1,10000) reading = MeterReader.ReadingMessage(customerId = x, readingValue = 1, readingTime = now) request.readings.append(reading) result = stub.AddReading(request) if (result.success == Enum.ReadingStatus.Success): print("Success") else: print("Failure")
def main(): with open("localhost.cer", "rb") as certFile: cert = certFile.read() credentials = grpc.ssl_channel_credentials(cert) channel = grpc.secure_channel("localhost:5001", credentials) stub = MeterReaderService.MeterReadingServiceStub(channel) now = Timestamp() now.GetCurrentTime() request = MeterReader.ReadingPacketMessage(successful=Enums.SUCCESS) reading = MeterReader.MeterReadingMessage(customerId=1, readingValue=1, readingTime=now) request.readings.append(reading) result = stub.AddReading(request) if (result.success == Enums.SUCCESS): print("Success") else: print("Failure")