Skip to content

Instantly share code, notes, and snippets.

@stylpen
stylpen / gist:8364ef6fe71af24e216f
Created October 7, 2014 19:01
example usage of mqtt wrapper for homA (sums up smart meter and inverter sensor data)
#! /usr/bin/python
import mqtt, time
MQTT_HOST = "192.168.11.54"
WRs = {"dummy" : 0}
SMs = {"dummy" : 0}
def on_message(mosquitto, message):
device = message.topic.split("/")[4]
if device[0] == "3": # this means it in data from an inverter
@stylpen
stylpen / mqtt.py
Created October 7, 2014 18:48
python MQTT wrapper
import thread, mosquitto, random, time
# mosquitto reference and download can be found here: http://mosquitto.org/documentation/python/
class mqtt():
def __init__(self, broker = "127.0.0.1", port = 1883, clientID = None):
self.__broker = broker
self.__port = port
self._client = None
self.__subscriptionsList = []
self.__pendingSubscriptionsList = []