def keepChecking(stub): config = loadConfiguration() PATH = config["images_path"] while True: try: DATE_FOLDER = datetime.today().strftime("%Y-%m-%d") + "/" onlyfiles = [ f for f in listdir(PATH + DATE_FOLDER) if isfile(join(PATH + DATE_FOLDER, f)) ] if len(onlyfiles) > 0: for file in onlyfiles: file_path = "{}{}{}".format(PATH, DATE_FOLDER, file) imageString = processImage(file_path) response = uploadFile(message=imageString, stub=stub) logging.info("Processed file " + file + " " + str(response)) os.remove(file_path) time.sleep(config["frequency_sleep_sec"]) except Exception as e: logging.error(e)
def main(): config = loadConfiguration() server_addr = config["server_ip"] grpc_port = config["grpc_port"] channel = grpc.insecure_channel(server_addr + ":" + grpc_port) stub = fileupload_pb2_grpc.FileUploadStub(channel=channel) keepChecking(stub)
def main(): config = loadConfiguration() # create a grpc server server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) fileupload_pb2_grpc.add_FileUploadServicer_to_server( FileUploadServicer(), server) server.add_insecure_port("[::]:" + config["grpc_port"]) print("Server started") logging.info("Server started") server.start() server.wait_for_termination()
def __init__(self): self.count = 0 self.serverImagePath = loadConfiguration()["server_images_path"]
Call parse() for each sensor Generate a complete JSON packet with all the sensor data, device ID and timestamp information Send data to REST API If not successful: If size of queue, exceeds max size: Drop first messages Add json pack to queue ''' if len(sys.argv) < 2: fail("Error: Manifest file path required") # manifest_file_path = "../manifests/device-13.yaml" manifest_file_path = sys.argv[1] param_device_name, param_hardware_type, param_queue_size, param_sensors, param_events, param_output = \ loadConfiguration(config_file_path = manifest_file_path, \ params = ["device-name", "hardware-type", 'queue-size', "sensors", "events", "output"]) # Dynamically load the compute class compute_class = importClassDynamically(param_hardware_type) ''' For each sensor: create a sensor object of the right class pass name, data, events, connections run configure() copy everything up to this point and put in validate and expose a function Every N seconds: For each sensor: read() generateOutput()