From a046bf66400e320e5ab29ea0147d52ebad105363 Mon Sep 17 00:00:00 2001 From: Asaril Date: Thu, 12 Mar 2020 09:57:07 +0100 Subject: [PATCH] Add clustering --- cluster.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cluster.py diff --git a/cluster.py b/cluster.py new file mode 100644 index 0000000..f47c15a --- /dev/null +++ b/cluster.py @@ -0,0 +1,25 @@ +import paho.mqtt.subscribe as mqtt +import json + +BROKER = ('homeproxy', 1883) +TOPIC_RAW = 'scalefix/raw/weight' +TOPIC_USERS = 'scalefix/users' + + +_users={} + +def handle_weight(client, userdata, message): + pass + +def handle_user(client, userdata, message): + pass + + +TOPIC_LAST = TOPIC_USERS+'/last' +def dispatch(client, userdata, message): + if message.topic == TOPIC_RAW: + handle_weight(client, userdata, message) + elif message.topic.startswith(TOPIC_LAST): + handle_user(client, userdata, message) + +mq.callback(dispatch, [TOPIC_RAW, TOPIC_LAST+'/+'], hostname=BROKER[0], port=BROKER[1])