Merge pull request #331 from quartiq/rj/mqtt-topics

rj/mqtt topics
This commit is contained in:
Ryan Summers 2021-04-09 11:04:01 +02:00 committed by GitHub
commit 24215c72a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -22,4 +22,6 @@ python3 -m pip install -r requirements.txt
ping -c 5 -w 20 stabilizer-hitl ping -c 5 -w 20 stabilizer-hitl
# Test the MQTT interface. # Test the MQTT interface.
python3 miniconf.py dt/sinara/stabilizer afe/0 '"G2"' python3 miniconf.py dt/sinara/stabilizer afe/0='"G2"'
python3 miniconf.py dt/sinara/stabilizer afe/0='"G1"' iir_ch/0/0=\
'{"y_min": -32767, "y_max": 32767, "y_offset": 0, "ba": [1.0, 0, 0, 0, 0]}'

View File

@ -83,19 +83,19 @@ class Miniconf:
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Miniconf command line interface.', description='Miniconf command line interface.',
epilog='''Example: formatter_class=argparse.RawDescriptionHelpFormatter,
%(prog)s -v -b mqtt dt/sinara/stabilizer afe/0 '"G10"' epilog='''Examples:
''') %(prog)s dt/sinara/stabilizer afe/0='"G2"' iir_ch/0/0=\
'{"y_min": -32767, "y_max": 32767, "y_offset": 0, "ba": [1.0, 0, 0, 0, 0]}'
''')
parser.add_argument('-v', '--verbose', action='count', default=0, parser.add_argument('-v', '--verbose', action='count', default=0,
help='Increase logging verbosity') help='Increase logging verbosity')
parser.add_argument('--broker', '-b', default='mqtt', type=str, parser.add_argument('--broker', '-b', default='mqtt', type=str,
help='The MQTT broker address') help='The MQTT broker address')
parser.add_argument('prefix', type=str, parser.add_argument('prefix', type=str,
help='The MQTT topic prefix of the target') help='The MQTT topic prefix of the target')
parser.add_argument('path', type=str, parser.add_argument('settings', metavar="KEY=VALUE", nargs='+',
help='The setting path to configure') help='JSON encoded values for settings path keys.')
parser.add_argument('value', type=str,
help='The value of setting in JSON format')
args = parser.parse_args() args = parser.parse_args()
@ -107,8 +107,10 @@ def main():
async def configure_settings(): async def configure_settings():
interface = await Miniconf.create(args.prefix, args.broker) interface = await Miniconf.create(args.prefix, args.broker)
response = await interface.command(args.path, json.loads(args.value)) for kv in args.settings:
print(f"Response: {response}") path, value = kv.split("=", 1)
response = await interface.command(path, json.loads(value))
print(response)
loop.run_until_complete(configure_settings()) loop.run_until_complete(configure_settings())