本文整理汇总了Python中sensor.Sensor.reading方法的典型用法代码示例。如果您正苦于以下问题:Python Sensor.reading方法的具体用法?Python Sensor.reading怎么用?Python Sensor.reading使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor.Sensor
的用法示例。
在下文中一共展示了Sensor.reading方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pin
# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import reading [as 别名]
parser.add_argument("-s", "--topic_key", help="MQTT topic key", required=True)
parser.add_argument("-w", "--wait", help="time between readings", type=float, default=0.5)
parser.add_argument("-i", "--pin", help="gpio pin (BCM)", type=int, required=True)
parser.add_argument("-y", "--high_value", help="high value", default=Sensor.HIGH)
parser.add_argument("-z", "--low_value", help="low value", default=Sensor.LOW)
parser.add_argument("-g", "--log_level", help="logging level", type=int, default=logging.INFO)
args = parser.parse_args()
# logging setup
logger = set_logger(level=args.log_level)
sensor = Sensor(args.pin)
sensor.start()
last_state = None
status = None
while True:
current_state = sensor.reading()
if current_state != last_state:
last_state = current_state # reset state value
if current_state == Sensor.LOW:
status = args.low_value
else:
status = args.high_value
logger.debug("sensor-monitor: changed %s %s" % (args.topic_key, str(status)))
# publish
MqttClient.publish(args, args.topic, {'state': {'reported': {args.topic_key: status}}})
if args.topic2 is not None:
MqttClient.publish(args, args.topic2, {'state': {'reported': {args.topic_key: status}}})
sleep(args.wait)