本文整理汇总了Python中sensor.Sensor.start方法的典型用法代码示例。如果您正苦于以下问题:Python Sensor.start方法的具体用法?Python Sensor.start怎么用?Python Sensor.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor.Sensor
的用法示例。
在下文中一共展示了Sensor.start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pin
# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import start [as 别名]
parser.add_argument("-o", "--topic2", help="Additional MQTT topic")
parser.add_argument("-t", "--topic", help="MQTT topic", required=True)
# specific
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:
示例2: len
# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import start [as 别名]
from sys import argv
from sensor import Sensor
if len(argv) < 3 :
print "Brakujacy parametr podczas uruchomienia!"
print "%s [port sensora] [adres i port monitora]" % (argv[0])
exit()
if __name__ == "__main__":
s = Sensor(argv[1], argv[2])
s.start()