Пример #1
0
def main(argv):
    # instantiate the MBP client
    mbp = MBPclient()
    # initialize the MBP client
    mbp.connect()

    # parse input arguments
    interval = mbp.get_start_par_value(argv, "interval",
                                       DEFAULT_INTERVAL_FOR_SENDING_DATA)
    adc_channel = mbp.get_start_par_value(argv, "channel", DEFAULT_CHANNEL)

    try:
        # Hardware - init analog input reader
        reader = AnalogInputReader(adc_channel)

        while True:
            # retrieve sensor value
            received_value = reader.read_light()
            # send data to the MBP
            mbp.send_data(float(received_value))
            # waits a time interval before sending new data
            time.sleep(int(interval))
    except:
        error = sys.exc_info()
        print('Error reading sensor value or sending to the MBP:', str(error))

    # terminate the MBP client
    mbp.finalize()
Пример #2
0
def main():

    PersonRecStatusFileManager.save_last_person_rec_status("0.0")

    mqtt_manager = ServerMQTTMessageManager()
    mqtt_client = MBPclient(mqtt_manager.message_handler)
    mqtt_client.connect()

    server = HTTPServer(('', 8081), ImageUploader)
    print("Starting web server on http://localhost:8081/")
    server.serve_forever()
Пример #3
0
def main():

    mqtt_manager = MBPclient()
    mqtt_manager.connect()
    notification_manager = NotificationManager()
    token_validation_manager = TokenValidationManager()

    handler = partial(CommandReceiverServer, mqtt_manager,
                      notification_manager, token_validation_manager)
    server = HTTPServer(('', 8084), handler)
    print("Starting web server on http://localhost:8084/")
    server.serve_forever()
Пример #4
0
def main(argv):
    # instantiate the MBP client
    mbp = MBPclient()

    # initialize the MBP client
    mbp.connect()

    try:
        # This loop ensures your code runs continuously,
        # for example, to read sensor values regularly at a given interval.
        while True:
            #############################
            #### Your code goes here ####
            value = random.choice([
                20.0, 20.5, 21.0, 22.0, 22.5, 25.5, 30.0, 30.1, 31.5, 29.9,
                35.0
            ])
            #############################

            # send data to the MBP, here a object with a single float field (key "value") is sent
            mbp.send_data("{\"value\":" + str(value) + "}")

            # waits a time interval before sending new data
            time.sleep(INTERVAL_BETWEEN_SENDING_DATA)
    except:
        error = sys.exc_info()
        print('Error:', str(error))

    # terminate the MBP client
    mbp.finalize()
Пример #5
0
def main(argv):
    # default interval for sending data (seconds)
    INTERVAL_BETWEEN_SENDING_DATA = 15
    PAR_FIELD_NAME = "name"
    PAR_FIELD_VALUE = "value"
    PAR_FIELD_NAME_INTERVAL = "interval"
    ##### Additional values
    MIFLORA_FIELD_NAME_SENSOR = "sensor"
    MIFLORA_FIELD_NAME_SENSOR_TYPE_TEMPERATURE = "temperature"
    MIFLORA_FIELD_NAME_MAC = "mac"
    targetSensor = MIFLORA_FIELD_NAME_SENSOR_TYPE_TEMPERATURE
    targetSensorMac = ""

    # instantiate the MBP client
    mbp = MBPclient()
    # initialize the MBP client
    mbp.connect()

    #### parse input arguments ######
    paramArray = json.loads(argv[0])
    #print(paramArray)
    for param in paramArray:
        if not (PAR_FIELD_NAME in param and PAR_FIELD_VALUE in param):
            continue
        elif param[PAR_FIELD_NAME].lower() == PAR_FIELD_NAME_INTERVAL.lower():
            INTERVAL_BETWEEN_SENDING_DATA = int(param[PAR_FIELD_VALUE])
        elif param[PAR_FIELD_NAME].lower() == MIFLORA_FIELD_NAME_SENSOR.lower(
        ):
            targetSensor = param[PAR_FIELD_VALUE]
        elif param[PAR_FIELD_NAME].lower() == MIFLORA_FIELD_NAME_MAC.lower():
            targetSensorMac = param[PAR_FIELD_VALUE]
    #################################

    try:
        # instantiate sensor reader of miflora
        poller = MiFloraPoller(targetSensorMac, BluepyBackend)

        # This loop ensures your code runs continuously to read values at a given interval
        while True:
            # retrieve sensor value
            received_value = poller.parameter_value(targetSensor)
            # send data to the MBP
            mbp.send_data(float(received_value))
            # waits a time interval before sending new data
            time.sleep(INTERVAL_BETWEEN_SENDING_DATA)
    except:
        error = sys.exc_info()
        print('Error reading sensor value or sending to the MBP:', str(error))

    # terminate the MBP client
    mbp.finalize()
Пример #6
0
def main(argv):
    mbp = MBPclient()
    mbp.connect()
    try:
        count = 0
        while True:
            count = count + 1
            mbp.send_data(count)
            time.sleep(INTERVAL_BETWEEN_SENDING_DATA)
    except:
        error = sys.exc_info()
        print('Error:', str(error))

    mbp.finalize()
Пример #7
0
def main(argv):
    mbp = MBPclient()
    mbp.connect()
    try:
        print('Subscribing to %s' % mbp.broker_action_topic)
        mbp.subscribe(mbp.broker_action_topic)
        print('Waiting for actions from MBP...')
        while True:
            time.sleep(1)
    except:
        error = sys.exc_info()
        print('Error:', str(error))

    mbp.finalize()
    print('Exiting...')
Пример #8
0
def main():

    camera = picamera.PiCamera(resolution=(CAMERA_WIDTH, CAMERA_HEIGHT),
                               framerate=30)

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--model',
                        help='File path of .tflite file.',
                        required=False,
                        default='detect.tflite')
    parser.add_argument('--threshold',
                        help='Score threshold for detected objects.',
                        required=False,
                        type=float,
                        default=0.4)
    args = parser.parse_args()

    mqtt_client = MBPclient()
    mqtt_client.connect()

    image_rec_manager = ImageRecognitionManager(args.model, args.threshold)
    cs1 = threading.Thread(name='consumer1',
                           target=image_rec_thread_function,
                           args=(image_rec_manager, camera, mqtt_client))
    cs1.daemon = True
    cs1.start()

    streaming_output = StreamingOutput()
    token_validation_manager = TokenValidationManager()
    camera.start_recording(streaming_output, format='mjpeg')
    try:
        handler = partial(StreamingHandler, streaming_output,
                          token_validation_manager)
        server = StreamingServer(('', 8000), handler)
        print("Starting web server on http://localhost:8000/")
        server.serve_forever()
    except:
        error = sys.exc_info()
        print("Ending program. Please wait")
        print('Error:', str(error))
        camera.close()
        time.sleep(2)
        server.shutdown()
        time.sleep(2)
        mqtt_client.finalize()
        time.sleep(2)

        return