From b8d7dc7c62f854cea79fa7158bd910a15f2f2a11 Mon Sep 17 00:00:00 2001 From: Nat Morris Date: Tue, 15 Nov 2016 01:21:51 +0000 Subject: [PATCH] example topics and start of the script --- README.md | 86 ++++++++++++++++++++++++++++++++++++++++++++++-- aaisp-to-mqtt.py | 33 +++++++++++++++++++ 2 files changed, 117 insertions(+), 2 deletions(-) create mode 100755 aaisp-to-mqtt.py diff --git a/README.md b/README.md index 533a95c..3eae5ea 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,91 @@ It uses version 2 of AAISPs [CHAOS](https://support.aa.net.uk/CHAOS) API. Useful for integrating and displaying AAISP line properties in home automation applications, such as [Home Assistant](https://home-assistant.io/) or [openHAB](http://www.openhab.org/). -## Config ## +## Usage ## -TODO +Create a config file, for example in /etc/aaisp-mqtt.conf, minimal viable with no MQTT authentication: + +``` +[aaisp] +username = aa@1 +password = LongAccountPassword + +[mqtt] +broker = 127.0.0.1 +port = 1883 +topic_prefix = aaisp +``` + +You can also optionally specify MQTT username and password: + +``` +[aaisp] +username = aa@1 +password = LongAccountPassword + +[mqtt] +broker = 127.0.0.1 +port = 1883 +username = aaisp-service +password = AnotherLongPassword +topic_prefix = aaisp +``` + +Run the service: + +``` +$ aaisp-to-mqtt.py /etc/aaisp-mqtt.conf +``` + +## Topics ## + +Single account: + +``` +aaisp/$accounts gb12@a +aaisp/$lines 32891 +aaisp/$version 0.1 +aaisp/account/gb12@a/quota/remaining 3333889 +aaisp/account/gb12@a/quota/monthly 10000000 +aaisp/account/gb12@a/syncrate/down 7800000 +aaisp/account/gb12@a/syncrate/up 1900000 +aaisp/line/32891/quota/remaining 3333889 +aaisp/line/32891/quota/monthly 10000000 +aaisp/line/32891/syncrate/down 7800000 +aaisp/line/32891/syncrate/up 1900000 +``` + +For multiple accounts: + +``` +aaisp/$accounts el6@a.1,el6@a.2,gb12@a +aaisp/$lines 37835,37964,32891 +aaisp/$version 0.1 +aaisp/account/gb12@a/quota/remaining 3333889 +aaisp/account/gb12@a/quota/monthly 10000000 +aaisp/account/gb12@a/syncrate/down 7800000 +aaisp/account/gb12@a/syncrate/up 1900000 +aaisp/account/el6@a.1/quota/remaining 3333889 +aaisp/account/el6@a.1/quota/monthly 10000000 +aaisp/account/el6@a.1/syncrate/down 7400000 +aaisp/account/el6@a.1/syncrate/up 1700000 +aaisp/account/el6@a.2/quota/remaining 3333889 +aaisp/account/el6@a.2/quota/monthly 10000000 +aaisp/account/el6@a.2/syncrate/down 7300000 +aaisp/account/el6@a.2/syncrate/up 1600000 +aaisp/line/32891/quota/remaining 3333889 +aaisp/line/32891/quota/monthly 10000000 +aaisp/line/32891/syncrate/down 7800000 +aaisp/line/32891/syncrate/up 1900000 +aaisp/line/37835/quota/remaining 3333889 +aaisp/line/37835/quota/monthly 10000000 +aaisp/line/37835/syncrate/down 7300000 +aaisp/line/37835/syncrate/up 1600000 +aaisp/line/37964/quota/remaining 3333889 +aaisp/line/37964/quota/monthly 10000000 +aaisp/line/37964/syncrate/down 7400000 +aaisp/line/37964/syncrate/up 1700000 +``` ## Setup ## diff --git a/aaisp-to-mqtt.py b/aaisp-to-mqtt.py new file mode 100755 index 0000000..4c6fb84 --- /dev/null +++ b/aaisp-to-mqtt.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import os +import sys +import logging +import json +import urllib +import configparser + +LOG = logging.getLogger(__name__) +VERSION = 0.1 + +def main(): + logging.basicConfig(level=logging.INFO, format='%(levelname)8s [%(asctime)s] %(message)s') + + if len(sys.argv) != 2: + LOG.fatal("Config file not supplied") + + cfgfile = sys.argv[1] + + config = configparser.ConfigParser() + config.read(cfgfile) + + for section in ["aaisp", "mqtt"]: + if section not in config.sections(): + LOG.fatal("%s section not found in config file %s", section, cfgfile) + + + + sys.exit(0) + +if __name__ == "__main__": + main()