First Implementation
This commit is contained in:
48
tic2mqtt
Executable file
48
tic2mqtt
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
import tic
|
||||
import tic_mqtt
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(prog="tic2mqtt",
|
||||
description="MQTT client for Linky Electricity Meters installed by Enedis in France.")
|
||||
#parser.add_argument('input', nargs='?', type=argparse.FileType('rb', bufsize=0), default='-',
|
||||
# help="input file or device to read TIC messages (stdin by default)")
|
||||
parser.add_argument('input', nargs='?', default='/dev/stdin',
|
||||
help="input file or device to read TIC messages (stdin by default)")
|
||||
parser.add_argument('-m', '--mode', choices=['auto', 'historique', 'standard'], default='auto',
|
||||
help='select TIC mode')
|
||||
parser.add_argument('-l', '--log', choices=['debug', 'info', 'warning', 'error'], default='error',
|
||||
help='set the log level')
|
||||
parser.add_argument('-b', '--broker',
|
||||
help='MQTT broker hostname')
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.basicConfig(level=getattr(logging, args.log.upper()))
|
||||
|
||||
my_tic = tic.Tic(args.input)
|
||||
if args.mode == "auto":
|
||||
my_tic.detect_mode()
|
||||
else:
|
||||
my_tic.set_mode(args.mode)
|
||||
|
||||
mqtt = tic_mqtt.TicPublisher(args.broker)
|
||||
my_tic.set_callback_ads(mqtt.set_ads)
|
||||
my_tic.set_callback_msg(mqtt.send_msg)
|
||||
|
||||
my_tic.run()
|
||||
|
||||
if mqtt:
|
||||
mqtt.close()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Reference in New Issue
Block a user