def registerOfflineSubscriber(): """Just a durable client to trigger queuing""" client = paho.mqtt.client.Client("sub-qos1-offline", clean_session=False) client.connect("localhost", port=port) client.subscribe("test/publish/queueing/#", 1) client.loop() client.disconnect()
def run(self): client = paho.mqtt.client.Client("broker-monitor") client.connect("localhost", port=port) client.message_callback_add("$SYS/broker/store/messages/count", self.store_count) client.message_callback_add("$SYS/broker/store/messages/bytes", self.store_bytes) client.message_callback_add("$SYS/broker/publish/messages/dropped", self.publish_dropped) client.subscribe("$SYS/broker/store/messages/#") client.subscribe("$SYS/broker/publish/messages/dropped") while True: expect_drops = cq.get() self.cq.task_done() if expect_drops == "quit": break first = time.time() while self.stored < 0 or self.stored_bytes < 0 or (expect_drops and self.dropped < 0): client.loop(timeout=0.5) if time.time() - 10 > first: print("ABORT TIMEOUT") break if expect_drops: self.rq.put((self.stored, self.stored_bytes, self.dropped)) else: self.rq.put((self.stored, self.stored_bytes, 0)) self.stored = -1 self.stored_bytes = -1 self.dropped = -1 client.disconnect()
def on_connect(self, client, userdata, flags, rc): """subscribe to all messages related to this LED installation""" start_path = self.conf.MQTT.Path.show_start stop_path = self.conf.MQTT.Path.show_stop client.subscribe(start_path) client.subscribe(stop_path) logger.info("subscription on Broker {host} for {start_path} and {stop_path}".format( host=self.conf.MQTT.Broker.host, start_path=start_path, stop_path=stop_path))
def on_connect(self, client, userdata, flags, rc): """ Callback for when the client receives a CONNACK response from the server. """ self.logger.info("MQTT client connected with result code %d", rc) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe("router/stats")
def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) time.sleep(2) client.publish("user/bob/location", "home", retain=True, qos=1) client.publish("user/bob/location", "work", retain=True, qos=1) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe("user/bob/location")
def on_connect(self, client, userdata, flags, rc): ''' Callback for when the client receives a CONNACK response from the server. ''' self.logger.info('MQTT client connected with result code %d', rc) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe('demo/devices/+')
def on_connect(self, client, userdata, flags, rc): # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. if (rc==0): client.subscribe( BASE_TOPIC_NEW ) client.subscribe( BASE_TOPIC ) else: logger.error("no connection to MQTT server possible") logger.error("Connected with result code "+str(rc))
def _on_connect(self, client, userdata, dict, rc): print("Connected with result code " + str(rc)) client.publish(self.lwt_topic, 'true', retain=True) client.subscribe(self.realm+"#") for dev in self.devices: client.publish(self.realm+dev.mac_addr_str+'/on/$settable', 'true', retain=True) #client.publish(self.realm+dev.mac_addr_str+'/on/$name', dev['display_name'], retain=True) client.publish(self.realm+dev.mac_addr_str+'/on/$datatype', 'boolean', retain=True) self.publish_state_change(dev)
def mqtt_on_connect(mqtt, userdata, rc): global myDevice, msg_cnt print("Connected with result code "+str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. # topics = [ ("$SYS/#", 0),] msg_cnt += 1 topics = myDevice.mqtt_topics # print topics mqtt.subscribe(topics) myDevice.lcd_msg_q.put("MQTT Connected")
def _on_connect(self, client, userdata, dict, rc): print("Connected with result code " + str(rc)) client.publish(self.lwt_topic, 'true', retain=True) client.publish(self.realm+'$fw/name', 'pulseaudio-mqtt', retain=True) client.publish(self.realm+'$name', 'Lautstärkeregler', retain=True) client.subscribe(self.realm+"#") for dev_path, dev in self.devices.items(): print(dev_path) client.publish(self.realm+dev['name']+'/volume/$settable', 'true', retain=True) client.publish(self.realm+dev['name']+'/volume/$name', dev['display_name'], retain=True) client.publish(self.realm+dev['name']+'/volume/$datatype', 'float', retain=True) client.publish(self.realm+dev['name']+'/volume/$format', '0:1.5', retain=True) self.publish_volume(dev_path, dev['volume'])
def on_connect(client, userdata, flags, rc): client.message_callback_add('haklab/hodnik/button', influx_toggle_doorstatus) client.message_callback_add('haklab/wifi/landevices', influx_update_lan_devices) client.message_callback_add('haklab/+/temp', influx_update_temperatures) client.message_callback_add('haklab/+/bootup', bootup) client.subscribe('haklab/hodnik/button') client.subscribe('haklab/wifi/landevices') client.subscribe('haklab/+/temp') client.subscribe('haklab/+/bootup') print('connected') sn = sdnotify.SystemdNotifier() sn.notify("READY=1")
def subscribe(self, client, userdata, flags, rc) -> None: """\ Function to be executed as ``on_connect`` hook of the Paho MQTT client. It subscribes to the MQTT paths for brightness changes and parameter changes for the show. .. todo:: - include link to the paho mqtt lib - explain currently unknown parameters :param client: the calling client object :param userdata: no idea what this does. This is a necessary argument but is not handled in any way in the function. :param flags: no idea what this does. This is a necessary argument but is not handled in any way in the function. :param rc: no idea what this does. This is a necessary argument but is not handled in any way in the function. """ set_brightness_path = self.global_conf.MQTT.Path.global_brightness_set parameter_path = self.global_conf.MQTT.Path.show_parameter_set.format(show_name=self.lightshow.name) client.subscribe(set_brightness_path) self.logger.debug("show subscribed to {}".format(set_brightness_path)) client.subscribe(parameter_path) self.logger.debug("show subscribed to {}".format(parameter_path))
def on_connect(mqtt_client, userdata, flags, rc): print("Connected with result code " + str(rc)) # Subscribing in on_connect() - if we lose the connection and # reconnect then subscriptions will be renewed. mqtt_client.subscribe("mydaemon/mydaemon")
def on_connect(client, userdata, flags, rc): client.subscribe("somakeit/space/open")
parser.add_argument( 'topic', type=str, help= 'Topic mask to unpublish retained messages from. For example: "/devices/my-device/#"' ) args = parser.parse_args() client = paho.mqtt.client.Client(client_id=None, clean_session=True, protocol=paho.mqtt.client.MQTTv31) if args.username: client.username_pw_set(args.username, args.password) client.connect(args.host, args.port) client.on_message = on_mqtt_message client.subscribe(args.topic) influx_client = InfluxDBClient('localhost', 8086, database='mqtt_data') db_writer = DBWriterThread(influx_client, daemon=True) db_writer.start() while 1: rc = client.loop() if rc != 0: break
def on_connect(client, userdata, flags, rc): # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe('gateway-data')
def on_connect(client, userdata, flags, rc): logging.info('%s: connected with result %s', self.__class__.__name__, str(rc)) client.subscribe('planteur/ambient') client.subscribe('planteur/plant') client.subscribe('planteur/watering')
def on_connect(self, client, userdata, flags, rc): logging.info('ESP connected (%s)' % client._client_id) client.subscribe(topic='esp/kukumi')
def on_connect(mosq, obj, rc): mqtt.subscribe(MQTT_Topic_Tegangan, 0)
def on_connect(client, userdata, flags, rc): print("Connected with result code " + str(rc)) client.subscribe(mqttprefix+"/#")
def mqtt_client(host, port, keep_alive): client = paho.mqtt.client.Client() client.subscribe("devnet/2") client.on_message = on_message client.connect(host, port, keep_alive) return client
def on_connect(client, userdata, flags, rc): path = "mqtt/controller" print("Connected with result code: %s" % rc) client.subscribe(path, qos=1) print(f"Client TCP port: {client._bind_port}") print(f"Subscribed to {path}")
def on_connect(client, userdata, flags, rc): #print('connected (%s)' % client._client_id) client.subscribe(topic='miraisra/injusa/datos', qos=0)
def new(host, port, keep_alive): client = paho.mqtt.client() client.subscribe("devnet/2") client.connect(host, port, keep_alive) client.on_message = on_message
def on_connect(client, userdata, flags, rc) : print "connected with result code", rc client.subscribe("Vision/Frame")
def on_connect(client, *args): print(args) print("Subscribing to rpi/{}/operation".format(SysUtil.get_machineid())) client.subscribe("rpi/{}/operation".format(SysUtil.get_machineid()), qos=1)
def on_connect(client, userdata, flags, rc): print('connected (%s)' % client._client_id) client.subscribe("TEST", 2)
def on_connect(mqtt, rc, a): mqtt.subscribe("cmnd/" + prefix + "/#", 0)
#!/usr/bin/env python import paho.mqtt.client as client import yaml TOPIC = 'sensor' def on_message(client, userdata, msg): print(str(msg.payload)) if __name__ == '__main__': f = open('./agent.yaml', 'r') conf = yaml.load(f) mqtt = conf['mqtt'] topic = mqtt['topic'] client = client.Client() client.connect(host=mqtt['host'], port=mqtt['port'], keepalive=60) client.subscribe(topic) client.on_message = on_message client.loop_forever()
def onConnect(client, userData, flags, rc): mqtt.subscribe('hermes/intent/#') mqtt.subscribe(HERMES_ON_HOTWORD) mqtt.subscribe(HERMES_START_LISTENING) mqtt.subscribe(HERMES_SAY) mqtt.subscribe(HERMES_CAPTURED) mqtt.subscribe(HERMES_HOTWORD_TOGGLE_ON) mqttPublish.single('hermes/feedback/sound/toggleOn', payload=json.dumps({'siteId': 'default'}), hostname='127.0.0.1', port=1883)
def OnConnect(client, userdata, flags, rc): print('connected (%s)' % client._client_id) client.subscribe(topic='home/#', qos=2)
def on_connect(client, userdata, flags, rc): print("Connected with result code: %s" % rc) client.subscribe("liveroom")
def on_connect(client, userdata, flags, rc): print("connected (%s)" % client._client_id) client.subscribe(topic="#", qos=2)
def on_connect(self, client, userdata, flags, rc): client.subscribe('/+/' + DAMqtt.D2P_TOPIC)
def on_message(client, obj, msg): data = json.loads(msg.payload) token = get_token(cfg['tokenurl'], data['username'], data['password']) data['wsfunction'] = 'local_mem_post_event' data['wstoken'] = token del data['username'] del data['password'] # Limit precision for PHP compatibility data['datetime'] = data['datetime'][:23] + 'Z' post(cfg['posturl'], data) def signal_term_handler(signal, frame): print 'terminating...' sys.exit(0) signal.signal(signal.SIGTERM, signal_term_handler) mqtt = mqtt.Client(protocol=mqtt.MQTTv31) with open("agent.yml", 'r') as ymlfile: cfg = yaml.load(ymlfile) mqtt.connect(cfg['server']) mqtt.on_connect = on_connect mqtt.on_message = on_message mqtt.subscribe("mooc/") mqtt.loop_forever()
def on_connect(client, userdata, flags, rc, properties=None): log.info("on_connect rc %d", rc) client.subscribe("/heizung/burner/can/raw/recv/")
def on_connect(client, userdata, flags, rc): client.subscribe("/datapoint") client.subscribe("/timepoint")
if old_topic == msg.topic: pin_storage[pin] = str(msg.payload) log(u"Write topic %s to vw/%s, val %s" % (old_topic, pin, str(msg.payload))) conn.sendall(hw("vw", pin, str(msg.payload))) # Main code log('Connecting to MQTT broker %s:%d' % (MQTT_SERVER, MQTT_PORT)) try: mqtt = mqtt.Client(MQTT_CLIENT) mqtt.connect(MQTT_SERVER, MQTT_PORT, 60) mqtt.on_message = on_mqtt_message except: log("Can't connect") sys.exit(1) mqtt.subscribe("%s/#" % TOPIC) log('Connecting to %s:%d' % (SERVER, PORT)) try: conn = socket.create_connection((SERVER, PORT), 3) except: log("Can't connect") sys.exit(1) if NODELAY != 0: conn.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) if SNDBUF != 0: sndbuf = conn.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF) log('Default SNDBUF %s changed to %s' % (sndbuf, SNDBUF)) conn.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, SNDBUF) if RCVBUF != 0:
def on_connect(client, userdata, flags, rc): print("Connected with result code " + str(rc)) client.subscribe(subname)
def on_connect(client, userdata, flags, rc): if DEBUG: print('DEBUG',"i'm in\n") sys.stdout.flush() client.disconnect_flag = False client.subscribe(topic='gates/command')
def on_connect(client, userdata, flags, rc): global nombre print('Conexion a MQTT server establecida (%s)' % client._client_id) client.subscribe(topic='broadlink/#', qos=2) client.publish("broadlink/recordrf",nombre)
def on_connect(client, userdata, flags, rc): print('Conectado (%s)' % client._client_id) client.subscribe(topic='Sambil/#', qos = 0)
def on_connect(client, userdata, flags, respons_code): print("Connected") client.subscribe(SUB_TOPIC) #サブスクライブする
""" import json, restkit, logging import paho.mqtt.client logging.basicConfig(level=logging.INFO, format="%(asctime)-15s %(message)s") log = logging.getLogger() config = json.load(open('priv.json')) updateServer = restkit.Resource("http://bang:9033/update") client = paho.mqtt.client.Client("map-receiver") client.connect("localhost") log.info('connected to %s', client._host) # need more auth here, to be able to read client.subscribe("/mqttitude/#", 0) def on_message(mosq, obj, msg): payload = json.loads(msg.payload) log.info("got message %r %r", msg.topic, payload) try: userFromTopic = config['mqttTopic'][msg.topic] except KeyError: log.warn("ignoring unknown topic") return if 'lon' not in payload: log.info("ignoring") return record = { "timestamp" : int(payload['tst']), "user" : userFromTopic, "longitude" : float(payload['lon']),
def on_connect_local(client, userdata, flags, rc): client.subscribe(LOCAL_MQTT_TOPIC)
def on_connect(client, userdata, rc): print("Connected with result code "+str(rc)) client.subscribe("#")
def mqtt_connect(client, userdata, flags, respons_code): print('mqtt connected.') # Entry Mqtt Subscribe. client.subscribe(MQTT_TOPIC_SUB) print('subscribe topic : ' + MQTT_TOPIC_SUB)
def on_connect(client, userdata, flags, rc): print("i'm in\n") client.subscribe(topic="garage/command", qos = 2) sys.stdout.flush()
def on_connect(client, userdata, flags, rc): print('Connected') mqtt.subscribe('hermes/intent/#')
def on_connect(client, userdata, flags, rc): print("Escuchando %s" % topic) client.subscribe(topic)
def on_connect(client, userdata, flags, rc): client.subscribe("somakeit/space/power/usage")
def on_connect(client, userdata, flags, rc, properties=None): log.info("on_connect rc %d", rc) client.subscribe(topic_prefix + "set_cnf/#")
def on_connect(client, userdata, flags, rc): print('connected (%s)' % client._client_id) client.subscribe(topic='#', qos=0)
def on_connect(client, data, rc): client.subscribe(TOPIC_SUB)