예제 #1
0
    parser.add_argument(
        "-i",
        "--initial_value",
        help="If False (the default), the device will be off initially. " +
        "If None, the device will be left in whatever state the pin is found "
        + "in when configured for output (warning: this can be on). " +
        "If True, the device will be switched on initially.",
        type=bool,
        default=False)
    args = parser.parse_args()

    logging.basicConfig(filename=awsiot.LOG_FILE,
                        level=args.log_level,
                        format=awsiot.LOG_FORMAT)

    subscriber = awsiot.MQTT(args.endpoint, args.rootCA, args.cert, args.key)

    output = OutputDevice(args.pin, args.active_high, args.initial_value)

    if args.topic is not None and len(args.topic) > 0:
        for t in args.topic:
            subscriber.subscribe('{}/#'.format(t.split('/').pop(0)), callback)
            time.sleep(2)  # pause

    # Loop forever
    try:
        while True:
            time.sleep(0.5)  # sleep needed because CPU race
    except (KeyboardInterrupt, SystemExit):
        sys.exit()
예제 #2
0
파일: pir_pub.py 프로젝트: stevewoolley/iot
                        help="The length of the queue used to store values read from the sensor. (1 = disabled)",
                        type=int, default=1)
    parser.add_argument("-w", "--sample_rate",
                        help="The number of values to read from the device " +
                             "(and append to the internal queue) per second",
                        type=float, default=100)
    parser.add_argument("-x", "--threshold",
                        help="When the mean of all values in the internal queue rises above this value, " +
                             "the sensor will be considered active by the is_active property, " +
                             "and all appropriate events will be fired",
                        type=float, default=0.5)
    parser.add_argument("-s", "--shadow_var", help="Shadow variable", required=True)
    parser.add_argument("-y", "--high_value", help="high value", default=1)
    parser.add_argument("-z", "--low_value", help="low value", default=0)
    parser.add_argument("-o", "--low_topic", nargs='*', help="Low topic")
    args = parser.parse_args()

    logging.basicConfig(filename=awsiot.LOG_FILE, level=args.log_level, format=awsiot.LOG_FORMAT)

    publisher = awsiot.MQTT(args.endpoint, args.rootCA, args.cert, args.key)

    pir = MotionSensor(args.pin,
                       queue_len=args.queue_len,
                       sample_rate=args.sample_rate,
                       threshold=args.threshold)

    pir.when_motion = motion
    pir.when_no_motion = no_motion

    pause()
예제 #3
0
                except Exception as err:
                    logging.error("supervisor stopProcess {} failed {}".format(arg, err))
            else:
                logging.error('No argument: {}'.format(cmd, arg))
        else:
            logging.warning('Unrecognized command: {}'.format(cmd))


if __name__ == "__main__":
    parser = awsiot.iot_arg_parser()
    parser.add_argument("--socket_path", help="socket path", default='/var/run/supervisor.sock')
    args = parser.parse_args()

    logging.basicConfig(filename=awsiot.LOG_FILE, level=args.log_level, format=awsiot.LOG_FORMAT)

    mqtt = awsiot.MQTT(args.endpoint, args.rootCA, args.cert, args.key)

    proxy = xmlrpclib.ServerProxy(
        'http://127.0.0.1', transport=supervisor.xmlrpc.SupervisorTransport(
            None, None, serverurl='unix://{}'.format(args.socket_path)))

    if args.topic is not None and len(args.topic) > 0:
        for t in args.topic:
            mqtt.subscribe('{}/#'.format(t.split('/').pop(0)), callback)
            time.sleep(2)  # pause

    # Loop forever
    try:
        while True:
            time.sleep(0.5)  # sleep needed because CPU race
    except (KeyboardInterrupt, SystemExit):