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()
示例#3
0
    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")
示例#5
0
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/+')
示例#7
0
文件: MQTT.py 项目: dewoller/pi-kobo
 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)
示例#9
0
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'])
示例#11
0
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")
示例#12
0
文件: base.py 项目: Yottabits/DotStar
        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))
示例#13
0
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")
示例#14
0
def on_connect(client, userdata, flags, rc):
    client.subscribe("somakeit/space/open")
示例#15
0
    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')
示例#17
0
 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')
示例#18
0
 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+"/#")
示例#21
0
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
示例#22
0
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)
示例#24
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
示例#25
0
def on_connect(client, userdata, flags, rc) :
    print "connected with result code", rc
    client.subscribe("Vision/Frame")
示例#26
0
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)
示例#27
0
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)
示例#29
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()
示例#30
0
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)
示例#31
0
def OnConnect(client, userdata, flags, rc):
    print('connected (%s)' % client._client_id)
    client.subscribe(topic='home/#', qos=2)
示例#32
0
def on_connect(client, userdata, flags, rc):
    print("Connected with result code: %s" % rc)
    client.subscribe("liveroom")
示例#33
0
def on_connect(client, userdata, flags, rc):
    print("connected (%s)" % client._client_id)
    client.subscribe(topic="#", qos=2)
示例#34
0
 def on_connect(self, client, userdata, flags, rc):
     client.subscribe('/+/' + DAMqtt.D2P_TOPIC)
示例#35
0

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()
示例#36
0
def on_connect(client, userdata, flags, rc, properties=None):
    log.info("on_connect rc %d", rc)
    client.subscribe("/heizung/burner/can/raw/recv/")
示例#37
0
def on_connect(client, userdata, flags, rc):
    client.subscribe("/datapoint")
    client.subscribe("/timepoint")
示例#38
0
		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:
示例#39
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')
示例#41
0
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)
示例#42
0
def on_connect(client, userdata, flags, rc):    
    print('Conectado (%s)' % client._client_id)
    client.subscribe(topic='Sambil/#', qos = 0) 
示例#43
0
def on_connect(client, userdata, flags, respons_code):
    print("Connected")
    client.subscribe(SUB_TOPIC)  #サブスクライブする
示例#44
0
"""

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']),
示例#45
0
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("#")
示例#47
0
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()
示例#49
0
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)
示例#51
0
def on_connect(client, userdata, flags, rc):
    client.subscribe("somakeit/space/power/usage")
示例#52
0
def on_connect(client, userdata, flags, rc, properties=None):
    log.info("on_connect rc %d", rc)
    client.subscribe(topic_prefix + "set_cnf/#")
示例#53
0
def on_connect(client, userdata, flags, rc):
    print('connected (%s)' % client._client_id)
    client.subscribe(topic='#', qos=0)
示例#54
0
 def on_connect(client, data, rc):
     client.subscribe(TOPIC_SUB)